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

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

DR1N0 opened a new pull request, #3335:
URL: https://github.com/apache/tinkerpop/pull/3335

   ## Summary
   This PR adds support for serializing custom types in gremlin-go, bringing it 
to **feature parity with the Java driver** and completing the custom type 
support that currently only includes deserialization. This implements the 
official GraphBinary specification for custom types, enabling full round-trip 
support for custom graph database types.
   
   ## Motivation
   While gremlin-go supports deserializing custom types via 
`RegisterCustomTypeReader()`, it lacks the corresponding serialization 
capability. This creates an asymmetry where users can read custom types from 
server responses but cannot write them in requests. The **Java driver already 
has full custom type support** (both `CustomTypeSerializer` reader and writer), 
and this PR brings gremlin-go to the same level.
   
   ## Changes
   
   ### New API Functions
   - `RegisterCustomTypeWriter(valueType reflect.Type, typeName string, writer 
CustomTypeWriter)` - Registers a custom serializer for a specific type
   - `UnregisterCustomTypeWriter(valueType reflect.Type)` - Unregisters a 
custom serializer
   
   ### New Types
   - `CustomTypeWriter` - Function type for user-provided serialization 
functions
   - `CustomTypeInfo` - Struct holding type metadata (name and writer function)
   
   ### Implementation Details
   - Added `customTypeWriter()` function to handle GraphBinary custom type 
format (type_code=0x00, type_name, value)
   - Modified `getType()` to detect registered custom types before checking 
built-in types
   - Modified `write()` to properly handle custom type format, matching the 
Java implementation in `GraphBinaryWriter.java`:
     ```java
     if (serializer instanceof CustomTypeSerializer) {
         buffer.writeBytes(customTypeCodeBytes);  // 0x00
         writeValue(customTypeSerializer.getTypeName(), buffer, false);
         customTypeSerializer.write(value, buffer, this);
     }
     ```
   
   ### GraphBinary Format Compliance
   The implementation follows the exact format used by Java's 
`GraphBinaryWriter`:
   - **Type code**: `0x00` (DataType.CUSTOM)
   - **Type name**: UTF-8 string with length prefix
   - **Value**: Custom-serialized data
   
   This ensures **cross-driver compatibility** - custom types serialized by 
gremlin-go can be deserialized by Java drivers and vice versa.
   
   ### Updated Files
   - `gremlin-go/driver/serializer.go` - Added type definitions and 
registration functions
   - `gremlin-go/driver/graphBinary.go` - Added custom type writer 
implementation and modified type detection
   - `gremlin-go/driver/serializer_test.go` - Added test cases following 
existing patterns
   - `CHANGELOG.asciidoc` - Added changelog entry
   
   ## Test Coverage
   Tests follow the same pattern as existing custom type reader tests:
   - **Success case** in `TestSerializer`: "test serialized request message w/ 
custom type"
   - **Failure case** in `TestSerializerFailures`: "test unregistered custom 
type writer failure"
   
   All tests pass:
   ```
   === RUN   TestSerializer/test_serialized_request_message_w/_custom_type
   -

> 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