gremlin 3.5.3 → 3.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +3 -2
- package/README.md +2 -2
- package/doc/AnonymousTraversalSource.html +2 -2
- package/doc/Authenticator.html +2 -2
- package/doc/Bytecode.html +2 -2
- package/doc/Client.html +2 -2
- package/doc/Connection.html +10 -10
- package/doc/DriverRemoteConnection.html +2 -2
- package/doc/EdgeLabelVerificationStrategy.html +2 -2
- package/doc/Graph.html +2 -2
- package/doc/GraphSON2Reader.html +2 -2
- package/doc/GraphSON2Writer.html +2 -2
- package/doc/GraphSON3Reader.html +2 -2
- package/doc/GraphSON3Writer.html +2 -2
- package/doc/GraphTraversal.html +1006 -171
- package/doc/GraphTraversalSource.html +517 -16
- package/doc/HaltedTraverserStrategy.html +2 -2
- package/doc/MatchAlgorithmStrategy.html +2 -2
- package/doc/P.html +2 -2
- package/doc/PartitionStrategy.html +2 -2
- package/doc/Path.html +2 -2
- package/doc/PlainTextSaslAuthenticator.html +2 -2
- package/doc/ProductiveByStrategy.html +2 -2
- package/doc/RemoteConnection.html +2 -2
- package/doc/RemoteStrategy.html +2 -2
- package/doc/RemoteTraversal.html +2 -2
- package/doc/ReservedKeysVerificationStrategy.html +2 -2
- package/doc/ResponseError.html +2 -2
- package/doc/ResultSet.html +2 -2
- package/doc/SaslAuthenticator.html +2 -2
- package/doc/SaslMechanismBase.html +2 -2
- package/doc/SaslMechanismPlain.html +2 -2
- package/doc/SeedStrategy.html +2 -2
- package/doc/SubgraphStrategy.html +2 -2
- package/doc/TextP.html +292 -2
- package/doc/Transaction.html +2 -2
- package/doc/Translator.html +2 -2
- package/doc/TraversalStrategies.html +2 -2
- package/doc/TraversalStrategy.html +2 -2
- package/doc/TypeSerializer.html +2 -2
- package/doc/driver_auth_authenticator.js.html +2 -2
- package/doc/driver_auth_mechanisms_sasl-mechanism-base.js.html +2 -2
- package/doc/driver_auth_mechanisms_sasl-mechanism-plain.js.html +2 -2
- package/doc/driver_auth_plain-text-sasl-authenticator.js.html +2 -2
- package/doc/driver_auth_sasl-authenticator.js.html +2 -2
- package/doc/driver_client.js.html +2 -2
- package/doc/driver_connection.js.html +32 -9
- package/doc/driver_driver-remote-connection.js.html +2 -2
- package/doc/driver_remote-connection.js.html +2 -2
- package/doc/driver_response-error.js.html +2 -2
- package/doc/driver_result-set.js.html +2 -2
- package/doc/global.html +67 -3
- package/doc/index.html +4 -4
- package/doc/module.exports.html +301 -0
- package/doc/process_anonymous-traversal.js.html +2 -2
- package/doc/process_bytecode.js.html +2 -2
- package/doc/process_graph-traversal.js.html +108 -13
- package/doc/process_transaction.js.html +2 -2
- package/doc/process_translator.js.html +2 -2
- package/doc/process_traversal-strategy.js.html +16 -3
- package/doc/process_traversal.js.html +14 -3
- package/doc/structure_graph.js.html +2 -2
- package/doc/structure_io_binary_internals_DataType.js.html +149 -0
- package/doc/structure_io_binary_internals_GraphBinaryReader.js.html +131 -0
- package/doc/structure_io_binary_internals_GraphBinaryWriter.js.html +134 -0
- package/doc/structure_io_graph-serializer.js.html +2 -2
- package/doc/structure_io_type-serializers.js.html +2 -2
- package/lib/driver/connection.js +30 -7
- package/lib/process/graph-traversal.js +106 -11
- package/lib/process/traversal-strategy.js +14 -1
- package/lib/process/traversal.js +12 -1
- package/lib/structure/io/binary/GraphBinary.js +109 -0
- package/lib/structure/io/binary/internals/AnySerializer.js +95 -0
- package/lib/structure/io/binary/internals/ArraySerializer.js +135 -0
- package/lib/structure/io/binary/internals/BigIntegerSerializer.js +151 -0
- package/lib/structure/io/binary/internals/BooleanSerializer.js +103 -0
- package/lib/structure/io/binary/internals/BulkSetSerializer.js +124 -0
- package/lib/structure/io/binary/internals/ByteBufferSerializer.js +124 -0
- package/lib/structure/io/binary/internals/ByteSerializer.js +95 -0
- package/lib/structure/io/binary/internals/BytecodeSerializer.js +249 -0
- package/lib/structure/io/binary/internals/DataType.js +98 -0
- package/lib/structure/io/binary/internals/DateSerializer.js +103 -0
- package/lib/structure/io/binary/internals/DoubleSerializer.js +99 -0
- package/lib/structure/io/binary/internals/EdgeSerializer.js +215 -0
- package/lib/structure/io/binary/internals/EnumSerializer.js +149 -0
- package/lib/structure/io/binary/internals/FloatSerializer.js +99 -0
- package/lib/structure/io/binary/internals/GraphBinaryReader.js +80 -0
- package/lib/structure/io/binary/internals/GraphBinaryWriter.js +83 -0
- package/lib/structure/io/binary/internals/IntSerializer.js +112 -0
- package/lib/structure/io/binary/internals/LambdaSerializer.js +70 -0
- package/lib/structure/io/binary/internals/LongSerializer.js +107 -0
- package/lib/structure/io/binary/internals/LongSerializerNg.js +102 -0
- package/lib/structure/io/binary/internals/MapSerializer.js +153 -0
- package/lib/structure/io/binary/internals/NumberSerializationStrategy.js +68 -0
- package/lib/structure/io/binary/internals/PSerializer.js +151 -0
- package/lib/structure/io/binary/internals/PathSerializer.js +123 -0
- package/lib/structure/io/binary/internals/PropertySerializer.js +141 -0
- package/lib/structure/io/binary/internals/ShortSerializer.js +99 -0
- package/lib/structure/io/binary/internals/StringSerializer.js +114 -0
- package/lib/structure/io/binary/internals/TextPSerializer.js +145 -0
- package/lib/structure/io/binary/internals/TraversalStrategySerializer.js +72 -0
- package/lib/structure/io/binary/internals/TraverserSerializer.js +123 -0
- package/lib/structure/io/binary/internals/UnspecifiedNullSerializer.js +75 -0
- package/lib/structure/io/binary/internals/UuidSerializer.js +119 -0
- package/lib/structure/io/binary/internals/VertexPropertySerializer.js +172 -0
- package/lib/structure/io/binary/internals/VertexSerializer.js +135 -0
- package/lib/structure/io/binary/internals/utils.js +59 -0
- package/package.json +12 -4
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @author Igor Ostapenko
|
|
22
|
+
*/
|
|
23
|
+
'use strict';
|
|
24
|
+
|
|
25
|
+
module.exports = class ArraySerializer {
|
|
26
|
+
constructor(ioc, ID) {
|
|
27
|
+
this.ioc = ioc;
|
|
28
|
+
this.ID = ID;
|
|
29
|
+
this.ioc.serializers[ID] = this;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
canBeUsedFor(value) {
|
|
33
|
+
return Array.isArray(value);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
serialize(item, fullyQualifiedFormat = true) {
|
|
37
|
+
if (item === undefined || item === null) {
|
|
38
|
+
if (fullyQualifiedFormat) {
|
|
39
|
+
return Buffer.from([this.ID, 0x01]);
|
|
40
|
+
}
|
|
41
|
+
return Buffer.from([0x00, 0x00, 0x00, 0x00]); // {length} = 0
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const bufs = [];
|
|
45
|
+
if (fullyQualifiedFormat) {
|
|
46
|
+
bufs.push(Buffer.from([this.ID, 0x00]));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// {length}
|
|
50
|
+
let length = item.length;
|
|
51
|
+
if (length < 0) {
|
|
52
|
+
length = 0; // TODO: test it
|
|
53
|
+
}
|
|
54
|
+
if (length > this.ioc.intSerializer.INT32_MAX) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
`Array length=${length} is greater than supported max_length=${this.ioc.intSerializer.INT32_MAX}.`,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
bufs.push(this.ioc.intSerializer.serialize(length, false));
|
|
60
|
+
|
|
61
|
+
// {item_0}...{item_n}
|
|
62
|
+
for (let i = 0; i < length; i++) {
|
|
63
|
+
bufs.push(this.ioc.anySerializer.serialize(item[i]));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return Buffer.concat(bufs);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
deserialize(buffer, fullyQualifiedFormat = true) {
|
|
70
|
+
let len = 0;
|
|
71
|
+
let cursor = buffer;
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
|
|
75
|
+
throw new Error('buffer is missing');
|
|
76
|
+
}
|
|
77
|
+
if (buffer.length < 1) {
|
|
78
|
+
throw new Error('buffer is empty');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (fullyQualifiedFormat) {
|
|
82
|
+
const type_code = cursor.readUInt8();
|
|
83
|
+
len++;
|
|
84
|
+
if (type_code !== this.ID) {
|
|
85
|
+
throw new Error('unexpected {type_code}');
|
|
86
|
+
}
|
|
87
|
+
cursor = cursor.slice(1);
|
|
88
|
+
|
|
89
|
+
if (cursor.length < 1) {
|
|
90
|
+
throw new Error('{value_flag} is missing');
|
|
91
|
+
}
|
|
92
|
+
const value_flag = cursor.readUInt8();
|
|
93
|
+
len++;
|
|
94
|
+
if (value_flag === 1) {
|
|
95
|
+
return { v: null, len };
|
|
96
|
+
}
|
|
97
|
+
if (value_flag !== 0) {
|
|
98
|
+
throw new Error('unexpected {value_flag}');
|
|
99
|
+
}
|
|
100
|
+
cursor = cursor.slice(1);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
let length, length_len;
|
|
104
|
+
try {
|
|
105
|
+
({ v: length, len: length_len } = this.ioc.intSerializer.deserialize(cursor, false));
|
|
106
|
+
len += length_len;
|
|
107
|
+
} catch (err) {
|
|
108
|
+
err.message = '{length}: ' + err.message;
|
|
109
|
+
throw err;
|
|
110
|
+
}
|
|
111
|
+
if (length < 0) {
|
|
112
|
+
throw new Error('{length} is less than zero');
|
|
113
|
+
}
|
|
114
|
+
cursor = cursor.slice(length_len);
|
|
115
|
+
|
|
116
|
+
const v = [];
|
|
117
|
+
for (let i = 0; i < length; i++) {
|
|
118
|
+
let value, value_len;
|
|
119
|
+
try {
|
|
120
|
+
({ v: value, len: value_len } = this.ioc.anySerializer.deserialize(cursor));
|
|
121
|
+
len += value_len;
|
|
122
|
+
} catch (err) {
|
|
123
|
+
err.message = `{item_${i}}: ` + err.message;
|
|
124
|
+
throw err;
|
|
125
|
+
}
|
|
126
|
+
cursor = cursor.slice(value_len);
|
|
127
|
+
v.push(value);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return { v, len };
|
|
131
|
+
} catch (err) {
|
|
132
|
+
throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @author Igor Ostapenko
|
|
22
|
+
*/
|
|
23
|
+
'use strict';
|
|
24
|
+
|
|
25
|
+
// TODO: it has room for performance improvements
|
|
26
|
+
module.exports = class BigIntegerSerializer {
|
|
27
|
+
constructor(ioc) {
|
|
28
|
+
this.ioc = ioc;
|
|
29
|
+
this.ioc.serializers[ioc.DataType.BIGINTEGER] = this;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
canBeUsedFor(value) {
|
|
33
|
+
// it's not expected to be used directly, see NumberSerializationStrategy
|
|
34
|
+
return typeof value === 'bigint';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
serialize(item, fullyQualifiedFormat = true) {
|
|
38
|
+
if (item === undefined || item === null) {
|
|
39
|
+
if (fullyQualifiedFormat) {
|
|
40
|
+
return Buffer.from([this.ioc.DataType.BIGINTEGER, 0x01]);
|
|
41
|
+
}
|
|
42
|
+
return Buffer.from([0x00, 0x00, 0x00, 0x01, 0x00]);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const bufs = [];
|
|
46
|
+
if (fullyQualifiedFormat) {
|
|
47
|
+
bufs.push(Buffer.from([this.ioc.DataType.BIGINTEGER, 0x00]));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let v;
|
|
51
|
+
|
|
52
|
+
// positive number
|
|
53
|
+
if (item >= 0) {
|
|
54
|
+
let hex_str = item.toString(16);
|
|
55
|
+
if (hex_str.length % 2 !== 0) {
|
|
56
|
+
hex_str = '0' + hex_str; // Buffer.from() expects exactly two hex digits per byte
|
|
57
|
+
}
|
|
58
|
+
if (Number.parseInt(hex_str[0], 16) > 7) {
|
|
59
|
+
hex_str = '00' + hex_str; // to keep sign bit unset for positive number
|
|
60
|
+
}
|
|
61
|
+
v = Buffer.from(hex_str, 'hex');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// negative number
|
|
65
|
+
else {
|
|
66
|
+
let hex_str = (-item).toString(16);
|
|
67
|
+
|
|
68
|
+
const bytes = (hex_str.length + (hex_str.length % 2)) / 2; // number's size in bytes
|
|
69
|
+
let N = BigInt(bytes) * BigInt(8); // number's size in bits
|
|
70
|
+
const INTN_MIN = -(BigInt(2) ** (N - BigInt(1))); // minimum negative number we can keep within N bits
|
|
71
|
+
if (item < INTN_MIN) {
|
|
72
|
+
N += BigInt(8); // to provide room for smaller negative number
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const twos_complement = BigInt(2) ** N + item;
|
|
76
|
+
hex_str = twos_complement.toString(16);
|
|
77
|
+
if (hex_str.length % 2 !== 0) {
|
|
78
|
+
hex_str = '0' + hex_str; // Buffer.from() expects exactly two hex digits per byte
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
v = Buffer.from(hex_str, 'hex');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
bufs.push(this.ioc.intSerializer.serialize(v.length, false));
|
|
85
|
+
bufs.push(v);
|
|
86
|
+
|
|
87
|
+
return Buffer.concat(bufs);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
deserialize(buffer, fullyQualifiedFormat = true) {
|
|
91
|
+
let len = 0;
|
|
92
|
+
let cursor = buffer;
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
|
|
96
|
+
throw new Error('buffer is missing');
|
|
97
|
+
}
|
|
98
|
+
if (buffer.length < 1) {
|
|
99
|
+
throw new Error('buffer is empty');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (fullyQualifiedFormat) {
|
|
103
|
+
const type_code = cursor.readUInt8();
|
|
104
|
+
len++;
|
|
105
|
+
if (type_code !== this.ioc.DataType.BIGINTEGER) {
|
|
106
|
+
throw new Error('unexpected {type_code}');
|
|
107
|
+
}
|
|
108
|
+
cursor = cursor.slice(1);
|
|
109
|
+
|
|
110
|
+
if (cursor.length < 1) {
|
|
111
|
+
throw new Error('{value_flag} is missing');
|
|
112
|
+
}
|
|
113
|
+
const value_flag = cursor.readUInt8();
|
|
114
|
+
len++;
|
|
115
|
+
if (value_flag === 1) {
|
|
116
|
+
return { v: null, len };
|
|
117
|
+
}
|
|
118
|
+
if (value_flag !== 0) {
|
|
119
|
+
throw new Error('unexpected {value_flag}');
|
|
120
|
+
}
|
|
121
|
+
cursor = cursor.slice(1);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// {length}
|
|
125
|
+
let length, length_len;
|
|
126
|
+
try {
|
|
127
|
+
({ v: length, len: length_len } = this.ioc.intSerializer.deserialize(cursor, false));
|
|
128
|
+
len += length_len;
|
|
129
|
+
} catch (err) {
|
|
130
|
+
err.message = '{length}: ' + err.message;
|
|
131
|
+
throw err;
|
|
132
|
+
}
|
|
133
|
+
if (length < 1) {
|
|
134
|
+
throw new Error(`{length}=${length} is less than one`);
|
|
135
|
+
}
|
|
136
|
+
cursor = cursor.slice(length_len);
|
|
137
|
+
|
|
138
|
+
len += length;
|
|
139
|
+
cursor = cursor.slice(0, length);
|
|
140
|
+
let v = BigInt(`0x${cursor.toString('hex')}`);
|
|
141
|
+
const is_sign_bit_set = (cursor[0] & 0x80) === 0x80;
|
|
142
|
+
if (is_sign_bit_set) {
|
|
143
|
+
v = BigInt.asIntN(length * 8, v); // now we get expected negative number
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return { v, len };
|
|
147
|
+
} catch (err) {
|
|
148
|
+
throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @author Igor Ostapenko
|
|
22
|
+
*/
|
|
23
|
+
'use strict';
|
|
24
|
+
|
|
25
|
+
module.exports = class BooleanSerializer {
|
|
26
|
+
constructor(ioc) {
|
|
27
|
+
this.ioc = ioc;
|
|
28
|
+
this.ioc.serializers[ioc.DataType.BOOLEAN] = this;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
canBeUsedFor(value) {
|
|
32
|
+
return typeof value === 'boolean';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
serialize(item, fullyQualifiedFormat = true) {
|
|
36
|
+
if (item === undefined || item === null) {
|
|
37
|
+
if (fullyQualifiedFormat) {
|
|
38
|
+
return Buffer.from([this.ioc.DataType.BOOLEAN, 0x01]);
|
|
39
|
+
}
|
|
40
|
+
return Buffer.from([0x00]);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const bufs = [];
|
|
44
|
+
if (fullyQualifiedFormat) {
|
|
45
|
+
bufs.push(Buffer.from([this.ioc.DataType.BOOLEAN, 0x00]));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
bufs.push(Buffer.from([item ? 0x01 : 0x00]));
|
|
49
|
+
|
|
50
|
+
return Buffer.concat(bufs);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
deserialize(buffer, fullyQualifiedFormat = true) {
|
|
54
|
+
let len = 0;
|
|
55
|
+
let cursor = buffer;
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
|
|
59
|
+
throw new Error('buffer is missing');
|
|
60
|
+
}
|
|
61
|
+
if (buffer.length < 1) {
|
|
62
|
+
throw new Error('buffer is empty');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (fullyQualifiedFormat) {
|
|
66
|
+
const type_code = cursor.readUInt8();
|
|
67
|
+
len++;
|
|
68
|
+
if (type_code !== this.ioc.DataType.BOOLEAN) {
|
|
69
|
+
throw new Error('unexpected {type_code}');
|
|
70
|
+
}
|
|
71
|
+
cursor = cursor.slice(1);
|
|
72
|
+
|
|
73
|
+
if (cursor.length < 1) {
|
|
74
|
+
throw new Error('{value_flag} is missing');
|
|
75
|
+
}
|
|
76
|
+
const value_flag = cursor.readUInt8();
|
|
77
|
+
len++;
|
|
78
|
+
if (value_flag === 1) {
|
|
79
|
+
return { v: null, len };
|
|
80
|
+
}
|
|
81
|
+
if (value_flag !== 0) {
|
|
82
|
+
throw new Error('unexpected {value_flag}');
|
|
83
|
+
}
|
|
84
|
+
cursor = cursor.slice(1);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (cursor.length < 1) {
|
|
88
|
+
throw new Error('unexpected {value} length');
|
|
89
|
+
}
|
|
90
|
+
len += 1;
|
|
91
|
+
|
|
92
|
+
let v = cursor.readUInt8();
|
|
93
|
+
if (v !== 0x00 && v !== 0x01) {
|
|
94
|
+
throw new Error(`unexpected boolean byte=${v}`);
|
|
95
|
+
}
|
|
96
|
+
v = v === 0x01;
|
|
97
|
+
|
|
98
|
+
return { v, len };
|
|
99
|
+
} catch (err) {
|
|
100
|
+
throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @author Igor Ostapenko
|
|
22
|
+
*/
|
|
23
|
+
'use strict';
|
|
24
|
+
|
|
25
|
+
module.exports = class BulkSetSerializer {
|
|
26
|
+
constructor(ioc) {
|
|
27
|
+
this.ioc = ioc;
|
|
28
|
+
this.ioc.serializers[ioc.DataType.BULKSET] = this;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
deserialize(buffer, fullyQualifiedFormat = true) {
|
|
32
|
+
let len = 0;
|
|
33
|
+
let cursor = buffer;
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
|
|
37
|
+
throw new Error('buffer is missing');
|
|
38
|
+
}
|
|
39
|
+
if (buffer.length < 1) {
|
|
40
|
+
throw new Error('buffer is empty');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (fullyQualifiedFormat) {
|
|
44
|
+
const type_code = cursor.readUInt8();
|
|
45
|
+
len++;
|
|
46
|
+
if (type_code !== this.ioc.DataType.BULKSET) {
|
|
47
|
+
throw new Error('unexpected {type_code}');
|
|
48
|
+
}
|
|
49
|
+
cursor = cursor.slice(1);
|
|
50
|
+
|
|
51
|
+
if (cursor.length < 1) {
|
|
52
|
+
throw new Error('{value_flag} is missing');
|
|
53
|
+
}
|
|
54
|
+
const value_flag = cursor.readUInt8();
|
|
55
|
+
len++;
|
|
56
|
+
if (value_flag === 1) {
|
|
57
|
+
return { v: null, len };
|
|
58
|
+
}
|
|
59
|
+
if (value_flag !== 0) {
|
|
60
|
+
throw new Error('unexpected {value_flag}');
|
|
61
|
+
}
|
|
62
|
+
cursor = cursor.slice(1);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// {length}
|
|
66
|
+
let length, length_len;
|
|
67
|
+
try {
|
|
68
|
+
({ v: length, len: length_len } = this.ioc.intSerializer.deserialize(cursor, false));
|
|
69
|
+
len += length_len;
|
|
70
|
+
} catch (err) {
|
|
71
|
+
err.message = '{length}: ' + err.message;
|
|
72
|
+
throw err;
|
|
73
|
+
}
|
|
74
|
+
if (length < 0) {
|
|
75
|
+
throw new Error('{length} is less than zero');
|
|
76
|
+
}
|
|
77
|
+
cursor = cursor.slice(length_len);
|
|
78
|
+
|
|
79
|
+
// Official GraphBinary 1.0 spec:
|
|
80
|
+
// If the implementing language does not have a BulkSet object to deserialize into,
|
|
81
|
+
// this format can be coerced to a List and still be considered compliant with Gremlin.
|
|
82
|
+
// Simply "expand the bulk" by adding the item to the List the number of times specified by the bulk.
|
|
83
|
+
|
|
84
|
+
// {item_0}...{item_n}
|
|
85
|
+
let v = new Array();
|
|
86
|
+
for (let i = 0; i < length; i++) {
|
|
87
|
+
let value, value_len;
|
|
88
|
+
try {
|
|
89
|
+
({ v: value, len: value_len } = this.ioc.anySerializer.deserialize(cursor));
|
|
90
|
+
len += value_len;
|
|
91
|
+
} catch (err) {
|
|
92
|
+
err.message = `{item_${i}} value: ` + err.message;
|
|
93
|
+
throw err;
|
|
94
|
+
}
|
|
95
|
+
cursor = cursor.slice(value_len);
|
|
96
|
+
|
|
97
|
+
let bulk, bulk_len;
|
|
98
|
+
try {
|
|
99
|
+
({ v: bulk, len: bulk_len } = this.ioc.longSerializer.deserialize(cursor, false));
|
|
100
|
+
len += bulk_len;
|
|
101
|
+
} catch (err) {
|
|
102
|
+
err.message = `{item_${i}} bulk: ` + err.message;
|
|
103
|
+
throw err;
|
|
104
|
+
}
|
|
105
|
+
if (bulk < 0) {
|
|
106
|
+
throw new Error(`{item_${i}}: bulk is less than zero`);
|
|
107
|
+
}
|
|
108
|
+
if (bulk > 4294967295) {
|
|
109
|
+
// arrayLength of Array() constructor is expected to be an integer between 0 and 2^32 - 1
|
|
110
|
+
throw new Error(`{item_${i}}: bulk is greater than 2^32-1`);
|
|
111
|
+
}
|
|
112
|
+
cursor = cursor.slice(bulk_len);
|
|
113
|
+
|
|
114
|
+
bulk = Number(bulk); // coersion to Number is required for BigInt if LongSerializerNg is used
|
|
115
|
+
const item = new Array(bulk).fill(value);
|
|
116
|
+
v = v.concat(item);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return { v, len };
|
|
120
|
+
} catch (err) {
|
|
121
|
+
throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @author Igor Ostapenko
|
|
22
|
+
*/
|
|
23
|
+
'use strict';
|
|
24
|
+
|
|
25
|
+
module.exports = class ByteBufferSerializer {
|
|
26
|
+
constructor(ioc) {
|
|
27
|
+
this.ioc = ioc;
|
|
28
|
+
this.ioc.serializers[ioc.DataType.BYTEBUFFER] = this;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
canBeUsedFor(value) {
|
|
32
|
+
return value instanceof Buffer;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
serialize(item, fullyQualifiedFormat = true) {
|
|
36
|
+
if (item === undefined || item === null) {
|
|
37
|
+
if (fullyQualifiedFormat) {
|
|
38
|
+
return Buffer.from([this.ioc.DataType.BYTEBUFFER, 0x01]);
|
|
39
|
+
}
|
|
40
|
+
return Buffer.from([0x00, 0x00, 0x00, 0x00]); // {length} = 0
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const bufs = [];
|
|
44
|
+
if (fullyQualifiedFormat) {
|
|
45
|
+
bufs.push(Buffer.from([this.ioc.DataType.BYTEBUFFER, 0x00]));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// {length}
|
|
49
|
+
let length = item.length;
|
|
50
|
+
if (length < 0) {
|
|
51
|
+
length = 0; // TODO: test it
|
|
52
|
+
}
|
|
53
|
+
if (length > this.ioc.intSerializer.INT32_MAX) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
`Buffer length=${length} is greater than supported max_length=${this.ioc.intSerializer.INT32_MAX}.`,
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
bufs.push(this.ioc.intSerializer.serialize(length, false));
|
|
59
|
+
|
|
60
|
+
// {value} sequence of bytes
|
|
61
|
+
bufs.push(item);
|
|
62
|
+
|
|
63
|
+
return Buffer.concat(bufs);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
deserialize(buffer, fullyQualifiedFormat = true) {
|
|
67
|
+
let len = 0;
|
|
68
|
+
let cursor = buffer;
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
|
|
72
|
+
throw new Error('buffer is missing');
|
|
73
|
+
}
|
|
74
|
+
if (buffer.length < 1) {
|
|
75
|
+
throw new Error('buffer is empty');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (fullyQualifiedFormat) {
|
|
79
|
+
const type_code = cursor.readUInt8();
|
|
80
|
+
len++;
|
|
81
|
+
if (type_code !== this.ioc.DataType.BYTEBUFFER) {
|
|
82
|
+
throw new Error('unexpected {type_code}');
|
|
83
|
+
}
|
|
84
|
+
cursor = cursor.slice(1);
|
|
85
|
+
|
|
86
|
+
if (cursor.length < 1) {
|
|
87
|
+
throw new Error('{value_flag} is missing');
|
|
88
|
+
}
|
|
89
|
+
const value_flag = cursor.readUInt8();
|
|
90
|
+
len++;
|
|
91
|
+
if (value_flag === 1) {
|
|
92
|
+
return { v: null, len };
|
|
93
|
+
}
|
|
94
|
+
if (value_flag !== 0) {
|
|
95
|
+
throw new Error('unexpected {value_flag}');
|
|
96
|
+
}
|
|
97
|
+
cursor = cursor.slice(1);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
let length, length_len;
|
|
101
|
+
try {
|
|
102
|
+
({ v: length, len: length_len } = this.ioc.intSerializer.deserialize(cursor, false));
|
|
103
|
+
len += length_len;
|
|
104
|
+
} catch (err) {
|
|
105
|
+
err.message = '{length}: ' + err.message;
|
|
106
|
+
throw err;
|
|
107
|
+
}
|
|
108
|
+
if (length < 0) {
|
|
109
|
+
throw new Error('{length} is less than zero');
|
|
110
|
+
}
|
|
111
|
+
cursor = cursor.slice(length_len);
|
|
112
|
+
|
|
113
|
+
if (length !== cursor.length) {
|
|
114
|
+
throw new Error(`{value}: unexpected actual {value} length=${cursor.length} when {length}=${length}`);
|
|
115
|
+
}
|
|
116
|
+
const v = cursor.slice(0, length);
|
|
117
|
+
len += length;
|
|
118
|
+
|
|
119
|
+
return { v, len };
|
|
120
|
+
} catch (err) {
|
|
121
|
+
throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
};
|