This is an automated email from the ASF dual-hosted git repository.
colegreer pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
The following commit(s) were added to refs/heads/master by this push:
new 81b5628d77 Update Graph Binary version implementation from 1 to 4
(#3370)
81b5628d77 is described below
commit 81b5628d7713c2c55f5d112642988deee3c4e024
Author: Cole Greer <[email protected]>
AuthorDate: Mon Mar 30 11:27:07 2026 -0700
Update Graph Binary version implementation from 1 to 4 (#3370)
---
.../structure/io/binary/GraphBinaryWriter.java | 2 +-
gremlin-go/driver/connection_test.go | 4 +--
gremlin-go/driver/graphBinaryDeserializer_test.go | 2 +-
gremlin-go/driver/interceptor_test.go | 12 ++++----
gremlin-go/driver/serializer.go | 3 +-
gremlin-go/driver/serializer_test.go | 4 +--
.../io/binary/internals/GraphBinaryReader.js | 2 +-
.../io/binary/internals/GraphBinaryWriter.js | 4 +--
.../unit/graphbinary/GraphBinaryReader-test.js | 34 +++++++++++-----------
.../unit/graphbinary/GraphBinaryWriter-test.js | 16 +++++-----
.../python/gremlin_python/driver/serializer.py | 2 +-
.../gremlin/driver/SerializationBenchmark.java | 4 +--
12 files changed, 44 insertions(+), 45 deletions(-)
diff --git
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/binary/GraphBinaryWriter.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/binary/GraphBinaryWriter.java
index dc2ed926c0..5719015388 100644
---
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/binary/GraphBinaryWriter.java
+++
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/binary/GraphBinaryWriter.java
@@ -47,7 +47,7 @@ public class GraphBinaryWriter {
private final static byte VALUE_FLAG_NONE = 0;
private final static byte VALUE_FLAG_ORDERED = 2;
private final static byte VALUE_FLAG_BULK = 2;
- public final static byte VERSION_BYTE = (byte)0x81;
+ public final static byte VERSION_BYTE = (byte)0x84;
public final static byte BULKED_BYTE = (byte)0x01;
private final static byte[] unspecifiedNullBytes = new byte[] {
DataType.UNSPECIFIED_NULL.getCodeByte(), 0x01};
private final static byte[] customTypeCodeBytes = new byte[] {
DataType.CUSTOM.getCodeByte() };
diff --git a/gremlin-go/driver/connection_test.go
b/gremlin-go/driver/connection_test.go
index 7d95192211..4a730b96f2 100644
--- a/gremlin-go/driver/connection_test.go
+++ b/gremlin-go/driver/connection_test.go
@@ -1315,6 +1315,6 @@ func TestConnectionWithMockServer_BasicAuth(t *testing.T)
{
// Body should still be valid serialized bytes
assert.NotEmpty(t, capturedBody, "serialized body should be non-empty
with BasicAuth")
- assert.Equal(t, byte(0x81), capturedBody[0],
- "body should start with GraphBinary version byte 0x81")
+ assert.Equal(t, byte(0x84), capturedBody[0],
+ "body should start with GraphBinary version byte 0x84")
}
diff --git a/gremlin-go/driver/graphBinaryDeserializer_test.go
b/gremlin-go/driver/graphBinaryDeserializer_test.go
index f6490b425d..2e9517ed15 100644
--- a/gremlin-go/driver/graphBinaryDeserializer_test.go
+++ b/gremlin-go/driver/graphBinaryDeserializer_test.go
@@ -286,7 +286,7 @@ func TestGraphBinaryDeserializerWithEndOfStreamMarker(t
*testing.T) {
// - EndOfStream marker
// - Status: code(4) + message(nullable) + exception(nullable)
data := []byte{
- 0x81, 0x00, // Header: version byte + no bulking
+ 0x84, 0x00, // Header: version byte + no bulking
0x01, 0x00, 0x00, 0x00, 0x00, 0x2A, // int32 = 42
0xfd, 0x00, 0x00, // Marker type + flag + value=0
(EndOfStream)
0x00, 0x00, 0x00, 0xC8, // Status code = 200
diff --git a/gremlin-go/driver/interceptor_test.go
b/gremlin-go/driver/interceptor_test.go
index 44c0c61988..40a947ac9d 100644
--- a/gremlin-go/driver/interceptor_test.go
+++ b/gremlin-go/driver/interceptor_test.go
@@ -111,8 +111,8 @@ func TestSigV4AuthWithSerializeInterceptor(t *testing.T) {
// Body should be valid serialized bytes
assert.NotEmpty(t, capturedBody, "body should be non-empty serialized
bytes")
- assert.Equal(t, byte(0x81), capturedBody[0],
- "body should start with GraphBinary version byte 0x81")
+ assert.Equal(t, byte(0x84), capturedBody[0],
+ "body should start with GraphBinary version byte 0x84")
}
// TestSigV4Auth_AutoSerializesInChain verifies that SigV4Auth works as the
only
@@ -149,8 +149,8 @@ func TestSigV4Auth_AutoSerializesInChain(t *testing.T) {
"SigV4Auth should set Authorization header")
assert.Contains(t, capturedHeaders.Get("Authorization"),
"AWS4-HMAC-SHA256")
assert.NotEmpty(t, capturedBody, "body should be non-empty serialized
bytes")
- assert.Equal(t, byte(0x81), capturedBody[0],
- "body should start with GraphBinary version byte 0x81")
+ assert.Equal(t, byte(0x84), capturedBody[0],
+ "body should start with GraphBinary version byte 0x84")
}
// TestMultipleInterceptors_SerializeThenAuth verifies that a custom
interceptor can
@@ -198,8 +198,8 @@ func TestMultipleInterceptors_SerializeThenAuth(t
*testing.T) {
// Body should be valid serialized bytes (from SerializeRequest)
assert.NotEmpty(t, capturedBody, "body should be non-empty serialized
bytes")
- assert.Equal(t, byte(0x81), capturedBody[0],
- "body should start with GraphBinary version byte 0x81")
+ assert.Equal(t, byte(0x84), capturedBody[0],
+ "body should start with GraphBinary version byte 0x84")
}
// TestInterceptor_IoReaderBody verifies that an interceptor can set Body to
an io.Reader
diff --git a/gremlin-go/driver/serializer.go b/gremlin-go/driver/serializer.go
index 49030251cc..a6c4c9d79a 100644
--- a/gremlin-go/driver/serializer.go
+++ b/gremlin-go/driver/serializer.go
@@ -64,8 +64,7 @@ func newGraphBinarySerializer(handler *logHandler)
*GraphBinarySerializer {
}
}
-// TODO change for graph binary 4.0 version is finalized
-const versionByte byte = 0x81
+const versionByte byte = 0x84
// SerializeMessage serializes a request message into GraphBinary format.
//
diff --git a/gremlin-go/driver/serializer_test.go
b/gremlin-go/driver/serializer_test.go
index fd8d660c8e..92225f25fb 100644
--- a/gremlin-go/driver/serializer_test.go
+++ b/gremlin-go/driver/serializer_test.go
@@ -27,8 +27,8 @@ import (
"golang.org/x/text/language"
)
-const mapDataOrder1 = "[129 0 0 0 2 3 0 0 0 0 8 108 97 110 103 117 97 103 101
3 0 0 0 0 12 103 114 101 109 108 105 110 45 108 97 110 103 3 0 0 0 0 1 103 3 0
0 0 0 1 103 0 0 0 13 103 46 86 40 41 46 99 111 117 110 116 40 41]"
-const mapDataOrder2 = "[129 0 0 0 2 3 0 0 0 0 1 103 3 0 0 0 0 1 103 3 0 0 0 0
8 108 97 110 103 117 97 103 101 3 0 0 0 0 12 103 114 101 109 108 105 110 45 108
97 110 103 0 0 0 13 103 46 86 40 41 46 99 111 117 110 116 40 41]"
+const mapDataOrder1 = "[132 0 0 0 2 3 0 0 0 0 8 108 97 110 103 117 97 103 101
3 0 0 0 0 12 103 114 101 109 108 105 110 45 108 97 110 103 3 0 0 0 0 1 103 3 0
0 0 0 1 103 0 0 0 13 103 46 86 40 41 46 99 111 117 110 116 40 41]"
+const mapDataOrder2 = "[132 0 0 0 2 3 0 0 0 0 1 103 3 0 0 0 0 1 103 3 0 0 0 0
8 108 97 110 103 117 97 103 101 3 0 0 0 0 12 103 114 101 109 108 105 110 45 108
97 110 103 0 0 0 13 103 46 86 40 41 46 99 111 117 110 116 40 41]"
func TestSerializer(t *testing.T) {
t.Run("test serialized request message", func(t *testing.T) {
diff --git
a/gremlin-js/gremlin-javascript/lib/structure/io/binary/internals/GraphBinaryReader.js
b/gremlin-js/gremlin-javascript/lib/structure/io/binary/internals/GraphBinaryReader.js
index d75bf13635..e1aa316970 100644
---
a/gremlin-js/gremlin-javascript/lib/structure/io/binary/internals/GraphBinaryReader.js
+++
b/gremlin-js/gremlin-javascript/lib/structure/io/binary/internals/GraphBinaryReader.js
@@ -51,7 +51,7 @@ export default class GraphBinaryReader {
// {version} is a Byte representing the protocol version
const version = cursor[0];
- if (version !== 0x81) {
+ if (version !== 0x84) {
throw new Error(`Unsupported version '${version}'.`);
}
cursor = cursor.slice(1); // skip version
diff --git
a/gremlin-js/gremlin-javascript/lib/structure/io/binary/internals/GraphBinaryWriter.js
b/gremlin-js/gremlin-javascript/lib/structure/io/binary/internals/GraphBinaryWriter.js
index f0ca979a72..5a9cae0db8 100644
---
a/gremlin-js/gremlin-javascript/lib/structure/io/binary/internals/GraphBinaryWriter.js
+++
b/gremlin-js/gremlin-javascript/lib/structure/io/binary/internals/GraphBinaryWriter.js
@@ -73,7 +73,7 @@ export default class GraphBinaryWriter {
const gremlin = requestMessage.getGremlin();
const bufs = [
- Buffer.from([0x81]),
+ Buffer.from([0x84]),
this.ioc.mapSerializer.serialize(fields, false),
this.ioc.stringSerializer.serialize(gremlin, false),
];
@@ -82,7 +82,7 @@ export default class GraphBinaryWriter {
// Legacy path: plain object with { gremlin, fields }
const bufs = [
- Buffer.from([0x81]),
+ Buffer.from([0x84]),
this.ioc.mapSerializer.serialize(requestMessage.fields || new Map(),
false),
this.ioc.stringSerializer.serialize(requestMessage.gremlin, false),
];
diff --git
a/gremlin-js/gremlin-javascript/test/unit/graphbinary/GraphBinaryReader-test.js
b/gremlin-js/gremlin-javascript/test/unit/graphbinary/GraphBinaryReader-test.js
index d4484c81c7..a686188fb6 100644
---
a/gremlin-js/gremlin-javascript/test/unit/graphbinary/GraphBinaryReader-test.js
+++
b/gremlin-js/gremlin-javascript/test/unit/graphbinary/GraphBinaryReader-test.js
@@ -20,7 +20,7 @@
/*
* GraphBinaryReader v4 response format tests.
* Tests the reader's ability to parse v4 response format:
- * {version:0x81}{bulked:Byte}{result_data stream}{marker:0xFD 0x00
0x00}{status_code:Int bare}{status_message:nullable}{exception:nullable}
+ * {version:0x84}{bulked:Byte}{result_data stream}{marker:0xFD 0x00
0x00}{status_code:Int bare}{status_message:nullable}{exception:nullable}
*/
import { assert } from 'chai';
@@ -55,9 +55,9 @@ describe('GraphBinaryReader', () => {
assert.throws(() => reader.readResponse(buffer), /Unsupported version
'0'/);
});
- it('rejects version 0x84', () => {
- const buffer = Buffer.from([0x84]);
- assert.throws(() => reader.readResponse(buffer), /Unsupported version
'132'/);
+ it('rejects version 0x81', () => {
+ const buffer = Buffer.from([0x81]);
+ assert.throws(() => reader.readResponse(buffer), /Unsupported version
'129'/);
});
it('rejects version 0xFF', () => {
@@ -69,7 +69,7 @@ describe('GraphBinaryReader', () => {
describe('non-bulked responses', () => {
it('single value', () => {
const buffer = Buffer.from([
- 0x81, // version
+ 0x84, // version
0x00, // bulked=false
0x01, 0x00, 0x00, 0x00, 0x00, 0x43, // fq Int: type_code=0x01,
value_flag=0x00, value=67
0xFD, 0x00, 0x00, // marker
@@ -86,7 +86,7 @@ describe('GraphBinaryReader', () => {
it('multiple values', () => {
const buffer = Buffer.from([
- 0x81, // version
+ 0x84, // version
0x00, // bulked=false
0x01, 0x00, 0x00, 0x00, 0x00, 0x43, // fq Int: 67
0x03, 0x00, 0x00, 0x00, 0x00, 0x05, 0x68, 0x65, 0x6C, 0x6C, 0x6F, //
fq String: "hello"
@@ -104,7 +104,7 @@ describe('GraphBinaryReader', () => {
it('empty result', () => {
const buffer = Buffer.from([
- 0x81, // version
+ 0x84, // version
0x00, // bulked=false
0xFD, 0x00, 0x00, // marker (no data)
0x00, 0x00, 0x00, 0xCC, // status_code=204
@@ -122,7 +122,7 @@ describe('GraphBinaryReader', () => {
describe('bulked responses', () => {
it('single item with bulk count', () => {
const buffer = Buffer.from([
- 0x81, // version
+ 0x84, // version
0x01, // bulked=true
0x01, 0x00, 0x00, 0x00, 0x00, 0x43, // fq Int: 67
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, // fq Long
bulk=3
@@ -140,7 +140,7 @@ describe('GraphBinaryReader', () => {
it('multiple items with bulk counts', () => {
const buffer = Buffer.from([
- 0x81, // version
+ 0x84, // version
0x01, // bulked=true
0x01, 0x00, 0x00, 0x00, 0x00, 0x43, // fq Int: 67
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, // fq Long
bulk=2
@@ -162,7 +162,7 @@ describe('GraphBinaryReader', () => {
describe('status codes', () => {
it('status 403', () => {
const buffer = Buffer.from([
- 0x81, 0x00, // version, bulked=false
+ 0x84, 0x00, // version, bulked=false
0xFD, 0x00, 0x00, // marker
0x00, 0x00, 0x01, 0x93, // status_code=403
0x01, 0x01 // null message, null exception
@@ -173,7 +173,7 @@ describe('GraphBinaryReader', () => {
it('status 500', () => {
const buffer = Buffer.from([
- 0x81, 0x00, // version, bulked=false
+ 0x84, 0x00, // version, bulked=false
0xFD, 0x00, 0x00, // marker
0x00, 0x00, 0x01, 0xF4, // status_code=500
0x01, 0x01 // null message, null exception
@@ -186,7 +186,7 @@ describe('GraphBinaryReader', () => {
describe('nullable status_message', () => {
it('present message', () => {
const buffer = Buffer.from([
- 0x81, 0x00, // version, bulked=false
+ 0x84, 0x00, // version, bulked=false
0xFD, 0x00, 0x00, // marker
0x00, 0x00, 0x00, 0xC8, // status_code=200
0x00, // message present flag
@@ -199,7 +199,7 @@ describe('GraphBinaryReader', () => {
it('null message', () => {
const buffer = Buffer.from([
- 0x81, 0x00, // version, bulked=false
+ 0x84, 0x00, // version, bulked=false
0xFD, 0x00, 0x00, // marker
0x00, 0x00, 0x00, 0xC8, // status_code=200
0x01, // message null flag
@@ -213,7 +213,7 @@ describe('GraphBinaryReader', () => {
describe('nullable exception', () => {
it('present exception', () => {
const buffer = Buffer.from([
- 0x81, 0x00, // version, bulked=false
+ 0x84, 0x00, // version, bulked=false
0xFD, 0x00, 0x00, // marker
0x00, 0x00, 0x01, 0xF4, // status_code=500
0x01, // message null
@@ -226,7 +226,7 @@ describe('GraphBinaryReader', () => {
it('null exception', () => {
const buffer = Buffer.from([
- 0x81, 0x00, // version, bulked=false
+ 0x84, 0x00, // version, bulked=false
0xFD, 0x00, 0x00, // marker
0x00, 0x00, 0x00, 0xC8, // status_code=200
0x01, // message null
@@ -240,7 +240,7 @@ describe('GraphBinaryReader', () => {
describe('error response', () => {
it('no result data with error status', () => {
const buffer = Buffer.from([
- 0x81, 0x00, // version, bulked=false
+ 0x84, 0x00, // version, bulked=false
0xFD, 0x00, 0x00, // marker (no data)
0x00, 0x00, 0x01, 0xF4, // status_code=500
0x00, // message present
@@ -259,7 +259,7 @@ describe('GraphBinaryReader', () => {
describe('complex result values', () => {
it('vertex in result data', () => {
const buffer = Buffer.from([
- 0x81, 0x00, // version, bulked=false
+ 0x84, 0x00, // version, bulked=false
0x11, 0x00, // fq Vertex: type_code=0x11, value_flag=0x00
0x01, 0x00, 0x00, 0x00, 0x00, 0x01, // id: fq Int=1
0x00, 0x00, 0x00, 0x01, // label: bare List length=1
diff --git
a/gremlin-js/gremlin-javascript/test/unit/graphbinary/GraphBinaryWriter-test.js
b/gremlin-js/gremlin-javascript/test/unit/graphbinary/GraphBinaryWriter-test.js
index d59937ce42..4c2a07b11e 100644
---
a/gremlin-js/gremlin-javascript/test/unit/graphbinary/GraphBinaryWriter-test.js
+++
b/gremlin-js/gremlin-javascript/test/unit/graphbinary/GraphBinaryWriter-test.js
@@ -20,7 +20,7 @@
/*
* GraphBinaryWriter v4 request format tests.
* Tests the writer's ability to generate v4 request format:
- * {version:0x81}{fields:Map bare}{gremlin:String bare}
+ * {version:0x84}{fields:Map bare}{gremlin:String bare}
*/
import { assert } from 'chai';
@@ -32,9 +32,9 @@ describe('GraphBinaryWriter', () => {
const writer = new GraphBinaryWriter(ioc);
describe('version byte', () => {
- it('first byte is 0x81', () => {
+ it('first byte is 0x84', () => {
const result = writer.writeRequest({ gremlin: 'g.V()', fields: new Map()
});
- assert.equal(result[0], 0x81);
+ assert.equal(result[0], 0x84);
});
});
@@ -42,7 +42,7 @@ describe('GraphBinaryWriter', () => {
it('empty map + bare string', () => {
const result = writer.writeRequest({ gremlin: 'g.V()', fields: new Map()
});
const expected = Buffer.from([
- 0x81, // version
+ 0x84, // version
0x00, 0x00, 0x00, 0x00, // empty map bare (length=0)
0x00, 0x00, 0x00, 0x05, // string length=5
0x67, 0x2E, 0x56, 0x28, 0x29 // "g.V()"
@@ -57,7 +57,7 @@ describe('GraphBinaryWriter', () => {
fields.set('evaluationTimeout', 1000);
const result = writer.writeRequest({ gremlin: 'g.V()', fields });
const expected = Buffer.from([
- 0x81, // version
+ 0x84, // version
0x00, 0x00, 0x00, 0x01, // map length=1
0x03, 0x00, // key type_code=STRING, value_flag=0x00
0x00, 0x00, 0x00, 0x11, // key string length=17
@@ -75,7 +75,7 @@ describe('GraphBinaryWriter', () => {
it('undefined fields defaults to empty map', () => {
const result = writer.writeRequest({ gremlin: 'g.V()', fields: undefined
});
const expected = Buffer.from([
- 0x81, // version
+ 0x84, // version
0x00, 0x00, 0x00, 0x00, // empty map bare (length=0)
0x00, 0x00, 0x00, 0x05, // string length=5
0x67, 0x2E, 0x56, 0x28, 0x29 // "g.V()"
@@ -86,7 +86,7 @@ describe('GraphBinaryWriter', () => {
it('null fields defaults to empty map', () => {
const result = writer.writeRequest({ gremlin: 'g.V()', fields: null });
const expected = Buffer.from([
- 0x81, // version
+ 0x84, // version
0x00, 0x00, 0x00, 0x00, // empty map bare (length=0)
0x00, 0x00, 0x00, 0x05, // string length=5
0x67, 0x2E, 0x56, 0x28, 0x29 // "g.V()"
@@ -112,7 +112,7 @@ describe('GraphBinaryWriter', () => {
it('empty string has length 0', () => {
const result = writer.writeRequest({ gremlin: '', fields: new Map() });
const expected = Buffer.from([
- 0x81, // version
+ 0x84, // version
0x00, 0x00, 0x00, 0x00, // empty map bare (length=0)
0x00, 0x00, 0x00, 0x00 // empty string bare (length=0)
]);
diff --git a/gremlin-python/src/main/python/gremlin_python/driver/serializer.py
b/gremlin-python/src/main/python/gremlin_python/driver/serializer.py
index 800b0500b1..3f18e8cf06 100644
--- a/gremlin-python/src/main/python/gremlin_python/driver/serializer.py
+++ b/gremlin-python/src/main/python/gremlin_python/driver/serializer.py
@@ -137,7 +137,7 @@ class GraphBinarySerializersV4(object):
def finalize_message(self, message):
ba = bytearray()
- ba.extend(graphbinaryV4.uint8_pack(0x81))
+ ba.extend(graphbinaryV4.uint8_pack(0x84))
fields = message["fields"]
ba.extend(self.int_pack(len(fields)))
for k, v in fields.items():
diff --git
a/gremlin-tools/gremlin-benchmark/src/main/java/org/apache/tinkerpop/gremlin/driver/SerializationBenchmark.java
b/gremlin-tools/gremlin-benchmark/src/main/java/org/apache/tinkerpop/gremlin/driver/SerializationBenchmark.java
index a155ddbd05..875feb334d 100644
---
a/gremlin-tools/gremlin-benchmark/src/main/java/org/apache/tinkerpop/gremlin/driver/SerializationBenchmark.java
+++
b/gremlin-tools/gremlin-benchmark/src/main/java/org/apache/tinkerpop/gremlin/driver/SerializationBenchmark.java
@@ -58,7 +58,7 @@ public class SerializationBenchmark extends
AbstractBenchmarkBase {
private static final ByteBuf RequestMessageBinaryBuffer1 =
Unpooled.wrappedBuffer(new byte[]{
// flag
- (byte)0x81,
+ (byte)0x84,
// uuid
(byte) 0xd3, (byte) 0xfd, 0x35, 0x40, 0x67, 0x18, 0x46, (byte)
0x87,(byte) 0x95, 0x6b, (byte) 0xc8, 0x61,
(byte) 0x8a, 0x26, (byte) 0xe3, 0x35,
@@ -72,7 +72,7 @@ public class SerializationBenchmark extends
AbstractBenchmarkBase {
private static final ByteBuf RequestMessageBinaryBuffer2 =
Unpooled.wrappedBuffer(new byte[]{
// flag
- (byte)0x81,
+ (byte)0x84,
// uuid
(byte) 0xd3, (byte) 0xfd, 0x35, 0x40, 0x67, 0x18, 0x46, (byte)
0x87,(byte) 0x95, 0x6b, (byte) 0xc8, 0x61,
(byte) 0x8a, 0x26, (byte) 0xe3, 0x35,