DR1N0 commented on code in PR #3335:
URL: https://github.com/apache/tinkerpop/pull/3335#discussion_r2980437968


##########
gremlin-go/driver/graphBinary.go:
##########
@@ -681,7 +681,52 @@ func bindingWriter(value interface{}, buffer 
*bytes.Buffer, typeSerializer *grap
        return buffer.Bytes(), nil
 }
 
+// customTypeWriter handles serialization of custom types registered via 
RegisterCustomTypeWriter.
+// Format: {type_code}{type_info}{value_flag}{value}
+// where type_code=0x00 (customType), type_info is the custom type name 
length+bytes,
+// value_flag=0x00 (not null), and value is the custom-serialized data.
+func customTypeWriter(value interface{}, buffer *bytes.Buffer, typeSerializer 
*graphBinaryTypeSerializer) ([]byte, error) {
+       // Look up the custom type info
+       valType := reflect.TypeOf(value)
+       customTypeWriterLock.RLock()
+       typeInfo, exists := customSerializers[valType]
+       customTypeWriterLock.RUnlock()
+
+       if !exists || customSerializers == nil {
+               return nil, 
newError(err0407GetSerializerToWriteUnknownTypeError, valType.Name())
+       }
+
+       // Write the custom type name as a String (length prefix + UTF-8 bytes)
+       typeName := typeInfo.TypeName
+       typeNameBytes := []byte(typeName)
+       if err := binary.Write(buffer, binary.BigEndian, 
int32(len(typeNameBytes))); err != nil {
+               return nil, err
+       }
+       if _, err := buffer.Write(typeNameBytes); err != nil {
+               return nil, err
+       }
+

Review Comment:
   Hi! Thanks for the review, and yes indeed the comment and the code don't 
match. (The comment is wrong)
   The Go implementation follows Java's design in GraphBinaryWriter.write():
   ```
       if (serializer instanceof CustomTypeSerializer) {
               // It's a custom type
               CustomTypeSerializer customTypeSerializer = 
(CustomTypeSerializer) serializer;
   
               buffer.writeBytes(customTypeCodeBytes); // 0x00
               writeValue(customTypeSerializer.getTypeName(), buffer, false); 
// type name
               customTypeSerializer.write(value, buffer, this); // custom 
serializer
               return;
           }
   ```
   the writer first writes {type_code}{type_name}, then it delegates to user's 
serializer for the rest, including the value_flag.
   I have updated the misleading comment.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to