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

ASF GitHub Bot commented on TINKERPOP-3237:
-------------------------------------------

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


##########
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:
   That makes sense. Thanks for the quick response! 





> Add Custom Type Writer/Serializer API for gremlin-go
> ----------------------------------------------------
>
>                 Key: TINKERPOP-3237
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-3237
>             Project: TinkerPop
>          Issue Type: Improvement
>          Components: go
>    Affects Versions: 3.8.0
>            Reporter: Haiyu Wang
>            Priority: Major
>             Fix For: 3.8.1
>
>
> ## Problem
>  
> Currently, gremlin-go supports deserializing custom types via 
> `RegisterCustomTypeReader()`, but lacks the corresponding functionality to 
> serialize custom types when sending requests to the server. This creates an 
> asymmetry where users can read custom types from server responses but cannot 
> write them in requests.
> **The Java driver already has complete custom type support** through 
> `CustomTypeSerializer` in `GraphBinaryWriter.java` and 
> `GraphBinaryReader.java`. This gap prevents gremlin-go users from working 
> with custom types in graph databases like JanusGraph, which use custom types 
> such as `RelationIdentifier`, `Geoshape`, etc.
> ## Current State
> - **Java driver**: ✅ Custom Type Reader + ✅ Custom Type Writer
> - **gremlin-go**: ✅ Custom Type Reader + ❌ Custom Type Writer (incomplete)
> ## Proposed Solution
> Add a `RegisterCustomTypeWriter()` API that mirrors the existing 
> `CustomTypeReader` pattern and implements the same GraphBinary custom type 
> format used by the Java driver.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to