[ 
https://issues.apache.org/jira/browse/GEODE-4080?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16295354#comment-16295354
 ] 

ASF GitHub Bot commented on GEODE-4080:
---------------------------------------

upthewaterspout commented on a change in pull request #1171: GEODE-4080: 
Protobuf JSON objects are in a proto string
URL: https://github.com/apache/geode/pull/1171#discussion_r157550131
 
 

 ##########
 File path: 
geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/ProtobufSerializationService.java
 ##########
 @@ -14,42 +14,124 @@
  */
 package org.apache.geode.internal.protocol.protobuf.v1;
 
+import com.google.protobuf.ByteString;
+
 import org.apache.geode.annotations.Experimental;
+import 
org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufPrimitiveTypes;
+import 
org.apache.geode.internal.protocol.protobuf.v1.utilities.exception.UnknownProtobufPrimitiveType;
 import org.apache.geode.internal.protocol.serialization.SerializationService;
-import org.apache.geode.internal.protocol.serialization.SerializationType;
-import org.apache.geode.internal.protocol.serialization.TypeCodec;
-import 
org.apache.geode.internal.protocol.serialization.exception.UnsupportedEncodingTypeException;
-import 
org.apache.geode.internal.protocol.serialization.registry.SerializationCodecRegistry;
-import 
org.apache.geode.internal.protocol.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.internal.protocol.serialization.codec.JsonPdxConverter;
+import 
org.apache.geode.internal.protocol.serialization.exception.EncodingException;
+import org.apache.geode.pdx.JSONFormatterException;
+import org.apache.geode.pdx.PdxInstance;
 
 @Experimental
-public class ProtobufSerializationService implements 
SerializationService<BasicTypes.EncodingType> {
-  private SerializationCodecRegistry serializationCodecRegistry = new 
SerializationCodecRegistry();
+public class ProtobufSerializationService implements 
SerializationService<BasicTypes.EncodedValue> {
+  private final JsonPdxConverter jsonPdxConverter = new JsonPdxConverter();
 
   public ProtobufSerializationService() {}
 
+  /**
+   * @param value the value to be encoded
+   *
+   * @return EncodedValue message with the serialized value
+   * @throws EncodingException
+   */
   @Override
-  public byte[] encode(BasicTypes.EncodingType encodingTypeValue, Object value)
-      throws UnsupportedEncodingTypeException, 
CodecNotRegisteredForTypeException {
-    TypeCodec codecForType = getTypeCodecForProtobufType(encodingTypeValue);
-    return codecForType.encode(value);
+  public BasicTypes.EncodedValue encode(Object value) throws EncodingException 
{
+    BasicTypes.EncodedValue.Builder builder = 
BasicTypes.EncodedValue.newBuilder();
+    try {
+      ProtobufPrimitiveTypes protobufPrimitiveTypes =
+          ProtobufPrimitiveTypes.valueOf(value.getClass());
+      switch (protobufPrimitiveTypes) {
+        case INT: {
+          builder.setIntResult((Integer) value);
+          break;
+        }
+        case LONG: {
+          builder.setLongResult((Long) value);
+          break;
+        }
+        case SHORT: {
+          builder.setShortResult((Short) value);
+          break;
+        }
+        case BYTE: {
+          builder.setByteResult((Byte) value);
+          break;
+        }
+        case DOUBLE: {
+          builder.setDoubleResult((Double) value);
+          break;
+        }
+        case FLOAT: {
+          builder.setFloatResult((Float) value);
+          break;
+        }
+        case BINARY: {
+          builder.setBinaryResult(ByteString.copyFrom((byte[]) value));
+          break;
+        }
+        case BOOLEAN: {
+          builder.setBooleanResult((Boolean) value);
+          break;
+        }
+        case STRING: {
+          builder.setStringResult((String) value);
+          break;
+        }
+      }
+    } catch (UnknownProtobufPrimitiveType unknownProtobufPrimitiveType) {
+      if (value instanceof PdxInstance) {
 
 Review comment:
   We shouldn't be throwing and catching exceptions for something which is a 
normal event - in this case handling a PDX value.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Improve JSON encoding for new protocol
> --------------------------------------
>
>                 Key: GEODE-4080
>                 URL: https://issues.apache.org/jira/browse/GEODE-4080
>             Project: Geode
>          Issue Type: Improvement
>          Components: client/server
>            Reporter: Galen O'Sullivan
>
> One of the encoding types in the new protobuf protocol is called 
> {{CustomEncodedValue}}. However, users aren't really free to encode their own 
> types. Also, packing JSON into a byte array is going to be harder for users 
> than just sending ti as a string. Let's make the JSON type a string and put 
> the custom value type in later when we actually have support for custom 
> encoding.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to