gremlin 3.5.3 → 3.5.4
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/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 +2 -2
- package/doc/GraphTraversalSource.html +2 -2
- 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 +2 -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 +66 -2
- package/doc/index.html +2 -2
- 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 +2 -2
- package/doc/process_transaction.js.html +2 -2
- package/doc/process_translator.js.html +2 -2
- package/doc/process_traversal-strategy.js.html +3 -3
- package/doc/process_traversal.js.html +2 -2
- package/doc/structure_graph.js.html +2 -2
- package/doc/structure_io_binary_internals_DataType.js.html +148 -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/traversal-strategy.js +1 -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 +97 -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 +148 -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 +14 -7
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
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 ByteSerializer {
|
|
26
|
+
constructor(ioc) {
|
|
27
|
+
this.ioc = ioc;
|
|
28
|
+
this.ioc.serializers[ioc.DataType.BYTE] = this;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
serialize(item, fullyQualifiedFormat = true) {
|
|
32
|
+
if (item === undefined || item === null) {
|
|
33
|
+
if (fullyQualifiedFormat) {
|
|
34
|
+
return Buffer.from([this.ioc.DataType.BYTE, 0x01]);
|
|
35
|
+
}
|
|
36
|
+
return Buffer.from([0x00]);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const bufs = [];
|
|
40
|
+
if (fullyQualifiedFormat) {
|
|
41
|
+
bufs.push(Buffer.from([this.ioc.DataType.BYTE, 0x00]));
|
|
42
|
+
}
|
|
43
|
+
const v = Buffer.alloc(1);
|
|
44
|
+
v.writeUInt8(item); // if item is not within uint8 limits writeUInt8 will error
|
|
45
|
+
bufs.push(v);
|
|
46
|
+
|
|
47
|
+
return Buffer.concat(bufs);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
deserialize(buffer, fullyQualifiedFormat = true) {
|
|
51
|
+
let len = 0;
|
|
52
|
+
let cursor = buffer;
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
|
|
56
|
+
throw new Error('buffer is missing');
|
|
57
|
+
}
|
|
58
|
+
if (buffer.length < 1) {
|
|
59
|
+
throw new Error('buffer is empty');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (fullyQualifiedFormat) {
|
|
63
|
+
const type_code = cursor.readUInt8();
|
|
64
|
+
len++;
|
|
65
|
+
if (type_code !== this.ioc.DataType.BYTE) {
|
|
66
|
+
throw new Error('unexpected {type_code}');
|
|
67
|
+
}
|
|
68
|
+
cursor = cursor.slice(1);
|
|
69
|
+
|
|
70
|
+
if (cursor.length < 1) {
|
|
71
|
+
throw new Error('{value_flag} is missing');
|
|
72
|
+
}
|
|
73
|
+
const value_flag = cursor.readUInt8();
|
|
74
|
+
len++;
|
|
75
|
+
if (value_flag === 1) {
|
|
76
|
+
return { v: null, len };
|
|
77
|
+
}
|
|
78
|
+
if (value_flag !== 0) {
|
|
79
|
+
throw new Error('unexpected {value_flag}');
|
|
80
|
+
}
|
|
81
|
+
cursor = cursor.slice(1);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (cursor.length < 1) {
|
|
85
|
+
throw new Error('unexpected {value} length');
|
|
86
|
+
}
|
|
87
|
+
len += 1;
|
|
88
|
+
|
|
89
|
+
const v = cursor.readUInt8();
|
|
90
|
+
return { v, len };
|
|
91
|
+
} catch (err) {
|
|
92
|
+
throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
@@ -0,0 +1,249 @@
|
|
|
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
|
+
const Bytecode = require('../../../../process/bytecode');
|
|
26
|
+
const t = require('../../../../process/traversal');
|
|
27
|
+
|
|
28
|
+
module.exports = class BytecodeSerializer {
|
|
29
|
+
constructor(ioc) {
|
|
30
|
+
this.ioc = ioc;
|
|
31
|
+
this.ioc.serializers[ioc.DataType.BYTECODE] = this;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
canBeUsedFor(value) {
|
|
35
|
+
return value instanceof Bytecode || value instanceof t.Traversal;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
serialize(item, fullyQualifiedFormat = true) {
|
|
39
|
+
if (item === undefined || item === null) {
|
|
40
|
+
if (fullyQualifiedFormat) {
|
|
41
|
+
return Buffer.from([this.ioc.DataType.BYTECODE, 0x01]);
|
|
42
|
+
}
|
|
43
|
+
const steps_length = [0x00, 0x00, 0x00, 0x00]; // 0
|
|
44
|
+
const sources_length = [0x00, 0x00, 0x00, 0x00]; // 0
|
|
45
|
+
return Buffer.from([...steps_length, ...sources_length]);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (item instanceof t.Traversal) {
|
|
49
|
+
item = item.getBytecode();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const bufs = [];
|
|
53
|
+
if (fullyQualifiedFormat) {
|
|
54
|
+
bufs.push(Buffer.from([this.ioc.DataType.BYTECODE, 0x00]));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// {steps_length}{step_0}...{step_n}
|
|
58
|
+
bufs.push(this.ioc.intSerializer.serialize(item.stepInstructions.length, false)); // TODO: what if steps_length > INT32_MAX
|
|
59
|
+
for (let i = 0; i < item.stepInstructions.length; i++) {
|
|
60
|
+
// {step_i} is composed of {name}{values_length}{value_0}...{value_n}
|
|
61
|
+
const step = item.stepInstructions[i];
|
|
62
|
+
const name = step[0];
|
|
63
|
+
const values_length = step.length - 1;
|
|
64
|
+
bufs.push(this.ioc.stringSerializer.serialize(name, false));
|
|
65
|
+
bufs.push(this.ioc.intSerializer.serialize(values_length, false));
|
|
66
|
+
for (let j = 0; j < values_length; j++) {
|
|
67
|
+
bufs.push(this.ioc.anySerializer.serialize(step[1 + j], true));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// {sources_length}{source_0}...{source_n}
|
|
72
|
+
bufs.push(this.ioc.intSerializer.serialize(item.sourceInstructions.length, false)); // TODO: what if sources_length > INT32_MAX
|
|
73
|
+
for (let i = 0; i < item.sourceInstructions.length; i++) {
|
|
74
|
+
// {source_i} is composed of {name}{values_length}{value_0}...{value_n}
|
|
75
|
+
const source = item.sourceInstructions[i];
|
|
76
|
+
const name = source[0];
|
|
77
|
+
const values_length = source.length - 1;
|
|
78
|
+
bufs.push(this.ioc.stringSerializer.serialize(name, false));
|
|
79
|
+
bufs.push(this.ioc.intSerializer.serialize(values_length, false));
|
|
80
|
+
for (let j = 0; j < values_length; j++) {
|
|
81
|
+
bufs.push(this.ioc.anySerializer.serialize(source[1 + j], true));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return Buffer.concat(bufs);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
deserialize(buffer, fullyQualifiedFormat = true) {
|
|
89
|
+
let len = 0;
|
|
90
|
+
let cursor = buffer;
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
|
|
94
|
+
throw new Error('buffer is missing');
|
|
95
|
+
}
|
|
96
|
+
if (buffer.length < 1) {
|
|
97
|
+
throw new Error('buffer is empty');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (fullyQualifiedFormat) {
|
|
101
|
+
const type_code = cursor.readUInt8();
|
|
102
|
+
len++;
|
|
103
|
+
if (type_code !== this.ioc.DataType.BYTECODE) {
|
|
104
|
+
throw new Error('unexpected {type_code}');
|
|
105
|
+
}
|
|
106
|
+
cursor = cursor.slice(1);
|
|
107
|
+
|
|
108
|
+
if (cursor.length < 1) {
|
|
109
|
+
throw new Error('{value_flag} is missing');
|
|
110
|
+
}
|
|
111
|
+
const value_flag = cursor.readUInt8();
|
|
112
|
+
len++;
|
|
113
|
+
if (value_flag === 1) {
|
|
114
|
+
return { v: null, len };
|
|
115
|
+
}
|
|
116
|
+
if (value_flag !== 0) {
|
|
117
|
+
throw new Error('unexpected {value_flag}');
|
|
118
|
+
}
|
|
119
|
+
cursor = cursor.slice(1);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const v = new Bytecode();
|
|
123
|
+
|
|
124
|
+
// steps
|
|
125
|
+
|
|
126
|
+
let steps_length, steps_length_len;
|
|
127
|
+
try {
|
|
128
|
+
({ v: steps_length, len: steps_length_len } = this.ioc.intSerializer.deserialize(cursor, false));
|
|
129
|
+
len += steps_length_len;
|
|
130
|
+
} catch (err) {
|
|
131
|
+
err.message = '{steps_length}: ' + err.message;
|
|
132
|
+
throw err;
|
|
133
|
+
}
|
|
134
|
+
if (steps_length < 0) {
|
|
135
|
+
throw new Error('{steps_length} is less than zero');
|
|
136
|
+
}
|
|
137
|
+
cursor = cursor.slice(steps_length_len);
|
|
138
|
+
|
|
139
|
+
// {step_i} is composed of {name}{values_length}{value_0}...{value_n}
|
|
140
|
+
for (let i = 0; i < steps_length; i++) {
|
|
141
|
+
// {name} is a String
|
|
142
|
+
let name, name_len;
|
|
143
|
+
try {
|
|
144
|
+
({ v: name, len: name_len } = this.ioc.stringSerializer.deserialize(cursor, false));
|
|
145
|
+
len += name_len;
|
|
146
|
+
} catch (err) {
|
|
147
|
+
err.message = `{step_${i}} {name}: ` + err.message;
|
|
148
|
+
throw err;
|
|
149
|
+
}
|
|
150
|
+
cursor = cursor.slice(name_len);
|
|
151
|
+
|
|
152
|
+
// {values_length} is an Int describing the amount values
|
|
153
|
+
let values_length, values_length_len;
|
|
154
|
+
try {
|
|
155
|
+
({ v: values_length, len: values_length_len } = this.ioc.intSerializer.deserialize(cursor, false));
|
|
156
|
+
len += values_length_len;
|
|
157
|
+
} catch (err) {
|
|
158
|
+
err.message = `{step_${i}} {values_length}: ` + err.message;
|
|
159
|
+
throw err;
|
|
160
|
+
}
|
|
161
|
+
if (values_length < 0) {
|
|
162
|
+
throw new Error(`{step_${i}} {values_length} is less than zero`);
|
|
163
|
+
}
|
|
164
|
+
cursor = cursor.slice(values_length_len);
|
|
165
|
+
|
|
166
|
+
// {value_i} is a fully qualified typed value composed of {type_code}{type_info}{value_flag}{value} describing the step argument
|
|
167
|
+
const values = [];
|
|
168
|
+
let value, value_len;
|
|
169
|
+
for (let j = 0; j < values_length; j++) {
|
|
170
|
+
try {
|
|
171
|
+
({ v: value, len: value_len } = this.ioc.anySerializer.deserialize(cursor));
|
|
172
|
+
len += value_len;
|
|
173
|
+
values.push(value);
|
|
174
|
+
} catch (err) {
|
|
175
|
+
err.message = `{step_${i}} {value_${j}}: ` + err.message;
|
|
176
|
+
throw err;
|
|
177
|
+
}
|
|
178
|
+
cursor = cursor.slice(value_len);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
v.addStep(name, values);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// sources
|
|
185
|
+
|
|
186
|
+
let sources_length, sources_length_len;
|
|
187
|
+
try {
|
|
188
|
+
({ v: sources_length, len: sources_length_len } = this.ioc.intSerializer.deserialize(cursor, false));
|
|
189
|
+
len += sources_length_len;
|
|
190
|
+
} catch (err) {
|
|
191
|
+
err.message = '{sources_length}: ' + err.message;
|
|
192
|
+
throw err;
|
|
193
|
+
}
|
|
194
|
+
if (sources_length < 0) {
|
|
195
|
+
throw new Error('{sources_length} is less than zero');
|
|
196
|
+
}
|
|
197
|
+
cursor = cursor.slice(sources_length_len);
|
|
198
|
+
|
|
199
|
+
// {source_i} is composed of {name}{values_length}{value_0}...{value_n}
|
|
200
|
+
for (let i = 0; i < sources_length; i++) {
|
|
201
|
+
// {name} is a String
|
|
202
|
+
let name, name_len;
|
|
203
|
+
try {
|
|
204
|
+
({ v: name, len: name_len } = this.ioc.stringSerializer.deserialize(cursor, false));
|
|
205
|
+
len += name_len;
|
|
206
|
+
} catch (err) {
|
|
207
|
+
err.message = `{source_${i}} {name}: ` + err.message;
|
|
208
|
+
throw err;
|
|
209
|
+
}
|
|
210
|
+
cursor = cursor.slice(name_len);
|
|
211
|
+
|
|
212
|
+
// {values_length} is an Int describing the amount values
|
|
213
|
+
let values_length, values_length_len;
|
|
214
|
+
try {
|
|
215
|
+
({ v: values_length, len: values_length_len } = this.ioc.intSerializer.deserialize(cursor, false));
|
|
216
|
+
len += values_length_len;
|
|
217
|
+
} catch (err) {
|
|
218
|
+
err.message = `{source_${i}} {values_length}: ` + err.message;
|
|
219
|
+
throw err;
|
|
220
|
+
}
|
|
221
|
+
if (values_length < 0) {
|
|
222
|
+
throw new Error(`{source_${i}} {values_length} is less than zero`);
|
|
223
|
+
}
|
|
224
|
+
cursor = cursor.slice(values_length_len);
|
|
225
|
+
|
|
226
|
+
// {value_i} is a fully qualified typed value composed of {type_code}{type_info}{value_flag}{value}
|
|
227
|
+
const values = [];
|
|
228
|
+
let value, value_len;
|
|
229
|
+
for (let j = 0; j < values_length; j++) {
|
|
230
|
+
try {
|
|
231
|
+
({ v: value, len: value_len } = this.ioc.anySerializer.deserialize(cursor));
|
|
232
|
+
len += value_len;
|
|
233
|
+
values.push(value);
|
|
234
|
+
} catch (err) {
|
|
235
|
+
err.message = `{source_${i}} {value_${j}}: ` + err.message;
|
|
236
|
+
throw err;
|
|
237
|
+
}
|
|
238
|
+
cursor = cursor.slice(value_len);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
v.addSource(name, values);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return { v, len };
|
|
245
|
+
} catch (err) {
|
|
246
|
+
throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
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
|
+
/**
|
|
26
|
+
* Represents a GraphBinary data type.
|
|
27
|
+
*
|
|
28
|
+
* See org.apache.tinkerpop.gremlin.structure.io.binary.DataType Java class.
|
|
29
|
+
*/
|
|
30
|
+
const DataType = {
|
|
31
|
+
INT: 0x01,
|
|
32
|
+
LONG: 0x02,
|
|
33
|
+
STRING: 0x03,
|
|
34
|
+
DATE: 0x04,
|
|
35
|
+
TIMESTAMP: 0x05,
|
|
36
|
+
CLASS: 0x06,
|
|
37
|
+
DOUBLE: 0x07,
|
|
38
|
+
FLOAT: 0x08,
|
|
39
|
+
LIST: 0x09,
|
|
40
|
+
MAP: 0x0a,
|
|
41
|
+
SET: 0x0b,
|
|
42
|
+
UUID: 0x0c,
|
|
43
|
+
EDGE: 0x0d,
|
|
44
|
+
PATH: 0x0e,
|
|
45
|
+
PROPERTY: 0x0f,
|
|
46
|
+
GRAPH: 0x10,
|
|
47
|
+
VERTEX: 0x11,
|
|
48
|
+
VERTEXPROPERTY: 0x12,
|
|
49
|
+
BARRIER: 0x13,
|
|
50
|
+
BINDING: 0x14,
|
|
51
|
+
BYTECODE: 0x15,
|
|
52
|
+
CARDINALITY: 0x16,
|
|
53
|
+
COLUMN: 0x17,
|
|
54
|
+
DIRECTION: 0x18,
|
|
55
|
+
OPERATOR: 0x19,
|
|
56
|
+
ORDER: 0x1a,
|
|
57
|
+
PICK: 0x1b,
|
|
58
|
+
POP: 0x1c,
|
|
59
|
+
LAMBDA: 0x1d,
|
|
60
|
+
P: 0x1e,
|
|
61
|
+
SCOPE: 0x1f,
|
|
62
|
+
T: 0x20,
|
|
63
|
+
TRAVERSER: 0x21,
|
|
64
|
+
BIGDECIMAL: 0x22,
|
|
65
|
+
BIGINTEGER: 0x23,
|
|
66
|
+
BYTE: 0x24,
|
|
67
|
+
BYTEBUFFER: 0x25,
|
|
68
|
+
SHORT: 0x26,
|
|
69
|
+
BOOLEAN: 0x27,
|
|
70
|
+
TEXTP: 0x28,
|
|
71
|
+
TRAVERSALSTRATEGY: 0x29,
|
|
72
|
+
BULKSET: 0x2a,
|
|
73
|
+
TREE: 0x2b,
|
|
74
|
+
METRICS: 0x2c,
|
|
75
|
+
TRAVERSALMETRICS: 0x2d,
|
|
76
|
+
|
|
77
|
+
CHAR: 0x80,
|
|
78
|
+
DURATION: 0x81,
|
|
79
|
+
INETADDRESS: 0x82,
|
|
80
|
+
INSTANT: 0x83,
|
|
81
|
+
LOCALDATE: 0x84,
|
|
82
|
+
LOCALDATETIME: 0x85,
|
|
83
|
+
LOCALTIME: 0x86,
|
|
84
|
+
MONTHDAY: 0x87,
|
|
85
|
+
OFFSETDATETIME: 0x88,
|
|
86
|
+
OFFSETTIME: 0x89,
|
|
87
|
+
PERIOD: 0x8a,
|
|
88
|
+
YEAR: 0x8b,
|
|
89
|
+
YEARMONTH: 0x8c,
|
|
90
|
+
ZONEDATETIME: 0x8d,
|
|
91
|
+
ZONEOFFSET: 0x8e,
|
|
92
|
+
|
|
93
|
+
CUSTOM: 0,
|
|
94
|
+
UNSPECIFIED_NULL: 0xfe,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
module.exports = DataType;
|