TINKERPOP-3237 Add custom type serializer API for gremlin-go#3335
Open
DR1N0 wants to merge 1 commit intoapache:3.8-devfrom
Open
TINKERPOP-3237 Add custom type serializer API for gremlin-go#3335DR1N0 wants to merge 1 commit intoapache:3.8-devfrom
DR1N0 wants to merge 1 commit intoapache:3.8-devfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 3.8-dev #3335 +/- ##
==========================================
Coverage ? 76.46%
Complexity ? 14890
==========================================
Files ? 1159
Lines ? 72135
Branches ? 8057
==========================================
Hits ? 55159
Misses ? 14047
Partials ? 2929 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 (bothCustomTypeSerializerreader 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 typeUnregisterCustomTypeWriter(valueType reflect.Type)- Unregisters a custom serializerNew Types
CustomTypeWriter- Function type for user-provided serialization functionsCustomTypeInfo- Struct holding type metadata (name and writer function)Implementation Details
customTypeWriter()function to handle GraphBinary custom type format (type_code=0x00, type_name, value)getType()to detect registered custom types before checking built-in typeswrite()to properly handle custom type format, matching the Java implementation inGraphBinaryWriter.java:GraphBinary Format Compliance
The implementation follows the exact format used by Java's
GraphBinaryWriter:0x00(DataType.CUSTOM)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 functionsgremlin-go/driver/graphBinary.go- Added custom type writer implementation and modified type detectiongremlin-go/driver/serializer_test.go- Added test cases following existing patternsCHANGELOG.asciidoc- Added changelog entryTest Coverage
Tests follow the same pattern as existing custom type reader tests:
TestSerializer: "test serialized request message w/ custom type"TestSerializerFailures: "test unregistered custom type writer failure"All tests pass:
Use Case
This feature enables users to serialize custom graph database types (e.g., JanusGraph's
RelationIdentifier) when sending requests to the server:Benefits
Backward Compatibility
This change is fully backward compatible - it only adds new functionality without modifying existing APIs or behavior.
References
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/binary/GraphBinaryWriter.java