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,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 DateSerializer {
|
|
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 value instanceof Date;
|
|
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, 0x00, 0x00, 0x00, 0x00]);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const bufs = [];
|
|
45
|
+
if (fullyQualifiedFormat) {
|
|
46
|
+
bufs.push(Buffer.from([this.ID, 0x00]));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const v = Buffer.alloc(8);
|
|
50
|
+
v.writeBigInt64BE(BigInt(item.getTime()));
|
|
51
|
+
bufs.push(v);
|
|
52
|
+
|
|
53
|
+
return Buffer.concat(bufs);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
deserialize(buffer, fullyQualifiedFormat = true) {
|
|
57
|
+
let len = 0;
|
|
58
|
+
let cursor = buffer;
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
|
|
62
|
+
throw new Error('buffer is missing');
|
|
63
|
+
}
|
|
64
|
+
if (buffer.length < 1) {
|
|
65
|
+
throw new Error('buffer is empty');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (fullyQualifiedFormat) {
|
|
69
|
+
const type_code = cursor.readUInt8();
|
|
70
|
+
len++;
|
|
71
|
+
if (type_code !== this.ID) {
|
|
72
|
+
throw new Error('unexpected {type_code}');
|
|
73
|
+
}
|
|
74
|
+
cursor = cursor.slice(1);
|
|
75
|
+
|
|
76
|
+
if (cursor.length < 1) {
|
|
77
|
+
throw new Error('{value_flag} is missing');
|
|
78
|
+
}
|
|
79
|
+
const value_flag = cursor.readUInt8();
|
|
80
|
+
len++;
|
|
81
|
+
if (value_flag === 1) {
|
|
82
|
+
return { v: null, len };
|
|
83
|
+
}
|
|
84
|
+
if (value_flag !== 0) {
|
|
85
|
+
throw new Error('unexpected {value_flag}');
|
|
86
|
+
}
|
|
87
|
+
cursor = cursor.slice(1);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (cursor.length < 8) {
|
|
91
|
+
throw new Error('unexpected {value} length');
|
|
92
|
+
}
|
|
93
|
+
len += 8;
|
|
94
|
+
|
|
95
|
+
const ms = cursor.readBigInt64BE();
|
|
96
|
+
const v = new Date(Number(ms));
|
|
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,99 @@
|
|
|
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 DoubleSerializer {
|
|
26
|
+
constructor(ioc) {
|
|
27
|
+
this.ioc = ioc;
|
|
28
|
+
this.ioc.serializers[ioc.DataType.DOUBLE] = this;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
canBeUsedFor(value) {
|
|
32
|
+
return typeof value === 'number' && !Number.isInteger(value);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
serialize(item, fullyQualifiedFormat = true) {
|
|
36
|
+
if (item === undefined || item === null) {
|
|
37
|
+
if (fullyQualifiedFormat) {
|
|
38
|
+
return Buffer.from([this.ioc.DataType.DOUBLE, 0x01]);
|
|
39
|
+
}
|
|
40
|
+
return Buffer.from([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const bufs = [];
|
|
44
|
+
if (fullyQualifiedFormat) {
|
|
45
|
+
bufs.push(Buffer.from([this.ioc.DataType.DOUBLE, 0x00]));
|
|
46
|
+
}
|
|
47
|
+
const v = Buffer.alloc(8);
|
|
48
|
+
v.writeDoubleBE(item);
|
|
49
|
+
bufs.push(v);
|
|
50
|
+
|
|
51
|
+
return Buffer.concat(bufs);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
deserialize(buffer, fullyQualifiedFormat = true) {
|
|
55
|
+
let len = 0;
|
|
56
|
+
let cursor = buffer;
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
|
|
60
|
+
throw new Error('buffer is missing');
|
|
61
|
+
}
|
|
62
|
+
if (buffer.length < 1) {
|
|
63
|
+
throw new Error('buffer is empty');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (fullyQualifiedFormat) {
|
|
67
|
+
const type_code = cursor.readUInt8();
|
|
68
|
+
len++;
|
|
69
|
+
if (type_code !== this.ioc.DataType.DOUBLE) {
|
|
70
|
+
throw new Error('unexpected {type_code}');
|
|
71
|
+
}
|
|
72
|
+
cursor = cursor.slice(1);
|
|
73
|
+
|
|
74
|
+
if (cursor.length < 1) {
|
|
75
|
+
throw new Error('{value_flag} is missing');
|
|
76
|
+
}
|
|
77
|
+
const value_flag = cursor.readUInt8();
|
|
78
|
+
len++;
|
|
79
|
+
if (value_flag === 1) {
|
|
80
|
+
return { v: null, len };
|
|
81
|
+
}
|
|
82
|
+
if (value_flag !== 0) {
|
|
83
|
+
throw new Error('unexpected {value_flag}');
|
|
84
|
+
}
|
|
85
|
+
cursor = cursor.slice(1);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (cursor.length < 8) {
|
|
89
|
+
throw new Error('unexpected {value} length');
|
|
90
|
+
}
|
|
91
|
+
len += 8;
|
|
92
|
+
|
|
93
|
+
const v = cursor.readDoubleBE();
|
|
94
|
+
return { v, len };
|
|
95
|
+
} catch (err) {
|
|
96
|
+
throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
@@ -0,0 +1,215 @@
|
|
|
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 g = require('../../../graph');
|
|
26
|
+
|
|
27
|
+
module.exports = class EdgeSerializer {
|
|
28
|
+
constructor(ioc) {
|
|
29
|
+
this.ioc = ioc;
|
|
30
|
+
this.ioc.serializers[ioc.DataType.EDGE] = this;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
canBeUsedFor(value) {
|
|
34
|
+
return value instanceof g.Edge;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
serialize(item, fullyQualifiedFormat = true) {
|
|
38
|
+
if (item === undefined || item === null) {
|
|
39
|
+
if (fullyQualifiedFormat) {
|
|
40
|
+
return Buffer.from([this.ioc.DataType.EDGE, 0x01]);
|
|
41
|
+
}
|
|
42
|
+
const id = [0x03, 0x00, 0x00, 0x00, 0x00, 0x00]; // String ''
|
|
43
|
+
const label = [0x00, 0x00, 0x00, 0x00]; // ''
|
|
44
|
+
const inVId = [0x03, 0x00, 0x00, 0x00, 0x00, 0x00]; // String ''
|
|
45
|
+
const inVLabel = [0x00, 0x00, 0x00, 0x00]; // ''
|
|
46
|
+
const outVId = [0x03, 0x00, 0x00, 0x00, 0x00, 0x00]; // String ''
|
|
47
|
+
const outVLabel = [0x00, 0x00, 0x00, 0x00]; // ''
|
|
48
|
+
const parent = [0xfe, 0x01]; // null
|
|
49
|
+
const properties = [0xfe, 0x01]; // null
|
|
50
|
+
return Buffer.from([...id, ...label, ...inVId, ...inVLabel, ...outVId, ...outVLabel, ...parent, ...properties]);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const bufs = [];
|
|
54
|
+
if (fullyQualifiedFormat) {
|
|
55
|
+
bufs.push(Buffer.from([this.ioc.DataType.EDGE, 0x00]));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// {id}
|
|
59
|
+
bufs.push(this.ioc.anySerializer.serialize(item.id));
|
|
60
|
+
|
|
61
|
+
// {label}
|
|
62
|
+
bufs.push(this.ioc.stringSerializer.serialize(item.label, false));
|
|
63
|
+
|
|
64
|
+
// {inVId}
|
|
65
|
+
const inVId = item.inV && item.inV.id;
|
|
66
|
+
bufs.push(this.ioc.anySerializer.serialize(inVId));
|
|
67
|
+
|
|
68
|
+
// {inVLabel}
|
|
69
|
+
const inVLabel = item.inV && item.inV.label;
|
|
70
|
+
bufs.push(this.ioc.stringSerializer.serialize(inVLabel, false));
|
|
71
|
+
|
|
72
|
+
// {outVId}
|
|
73
|
+
const outVId = item.outV && item.outV.id;
|
|
74
|
+
bufs.push(this.ioc.anySerializer.serialize(outVId));
|
|
75
|
+
|
|
76
|
+
// {outVLabel}
|
|
77
|
+
const outVLabel = item.outV && item.outV.label;
|
|
78
|
+
bufs.push(this.ioc.stringSerializer.serialize(outVLabel, false));
|
|
79
|
+
|
|
80
|
+
// {parent}
|
|
81
|
+
bufs.push(this.ioc.unspecifiedNullSerializer.serialize(null));
|
|
82
|
+
|
|
83
|
+
// {properties}
|
|
84
|
+
bufs.push(this.ioc.unspecifiedNullSerializer.serialize(null));
|
|
85
|
+
|
|
86
|
+
return Buffer.concat(bufs);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
deserialize(buffer, fullyQualifiedFormat = true) {
|
|
90
|
+
let len = 0;
|
|
91
|
+
let cursor = buffer;
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
|
|
95
|
+
throw new Error('buffer is missing');
|
|
96
|
+
}
|
|
97
|
+
if (buffer.length < 1) {
|
|
98
|
+
throw new Error('buffer is empty');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (fullyQualifiedFormat) {
|
|
102
|
+
const type_code = cursor.readUInt8();
|
|
103
|
+
len++;
|
|
104
|
+
if (type_code !== this.ioc.DataType.EDGE) {
|
|
105
|
+
throw new Error('unexpected {type_code}');
|
|
106
|
+
}
|
|
107
|
+
cursor = cursor.slice(1);
|
|
108
|
+
|
|
109
|
+
if (cursor.length < 1) {
|
|
110
|
+
throw new Error('{value_flag} is missing');
|
|
111
|
+
}
|
|
112
|
+
const value_flag = cursor.readUInt8();
|
|
113
|
+
len++;
|
|
114
|
+
if (value_flag === 1) {
|
|
115
|
+
return { v: null, len };
|
|
116
|
+
}
|
|
117
|
+
if (value_flag !== 0) {
|
|
118
|
+
throw new Error('unexpected {value_flag}');
|
|
119
|
+
}
|
|
120
|
+
cursor = cursor.slice(1);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
let id, id_len;
|
|
124
|
+
try {
|
|
125
|
+
({ v: id, len: id_len } = this.ioc.anySerializer.deserialize(cursor));
|
|
126
|
+
len += id_len;
|
|
127
|
+
} catch (err) {
|
|
128
|
+
err.message = '{id}: ' + err.message;
|
|
129
|
+
throw err;
|
|
130
|
+
}
|
|
131
|
+
cursor = cursor.slice(id_len);
|
|
132
|
+
|
|
133
|
+
let label, label_len;
|
|
134
|
+
try {
|
|
135
|
+
({ v: label, len: label_len } = this.ioc.stringSerializer.deserialize(cursor, false));
|
|
136
|
+
len += label_len;
|
|
137
|
+
} catch (err) {
|
|
138
|
+
err.message = '{label}: ' + err.message;
|
|
139
|
+
throw err;
|
|
140
|
+
}
|
|
141
|
+
cursor = cursor.slice(label_len);
|
|
142
|
+
|
|
143
|
+
let inVId, inVId_len;
|
|
144
|
+
try {
|
|
145
|
+
({ v: inVId, len: inVId_len } = this.ioc.anySerializer.deserialize(cursor));
|
|
146
|
+
len += inVId_len;
|
|
147
|
+
} catch (err) {
|
|
148
|
+
err.message = '{inVId}: ' + err.message;
|
|
149
|
+
throw err;
|
|
150
|
+
}
|
|
151
|
+
cursor = cursor.slice(inVId_len);
|
|
152
|
+
|
|
153
|
+
let inVLabel, inVLabel_len;
|
|
154
|
+
try {
|
|
155
|
+
({ v: inVLabel, len: inVLabel_len } = this.ioc.stringSerializer.deserialize(cursor, false));
|
|
156
|
+
len += inVLabel_len;
|
|
157
|
+
} catch (err) {
|
|
158
|
+
err.message = '{inVLabel}: ' + err.message;
|
|
159
|
+
throw err;
|
|
160
|
+
}
|
|
161
|
+
cursor = cursor.slice(inVLabel_len);
|
|
162
|
+
|
|
163
|
+
let outVId, outVId_len;
|
|
164
|
+
try {
|
|
165
|
+
({ v: outVId, len: outVId_len } = this.ioc.anySerializer.deserialize(cursor));
|
|
166
|
+
len += outVId_len;
|
|
167
|
+
} catch (err) {
|
|
168
|
+
err.message = '{outVId}: ' + err.message;
|
|
169
|
+
throw err;
|
|
170
|
+
}
|
|
171
|
+
cursor = cursor.slice(outVId_len);
|
|
172
|
+
|
|
173
|
+
let outVLabel, outVLabel_len;
|
|
174
|
+
try {
|
|
175
|
+
({ v: outVLabel, len: outVLabel_len } = this.ioc.stringSerializer.deserialize(cursor, false));
|
|
176
|
+
len += outVLabel_len;
|
|
177
|
+
} catch (err) {
|
|
178
|
+
err.message = '{outVLabel}: ' + err.message;
|
|
179
|
+
throw err;
|
|
180
|
+
}
|
|
181
|
+
cursor = cursor.slice(outVLabel_len);
|
|
182
|
+
|
|
183
|
+
let parent_len;
|
|
184
|
+
try {
|
|
185
|
+
({ len: parent_len } = this.ioc.anySerializer.deserialize(cursor));
|
|
186
|
+
len += parent_len;
|
|
187
|
+
} catch (err) {
|
|
188
|
+
err.message = '{parent}: ' + err.message;
|
|
189
|
+
throw err;
|
|
190
|
+
}
|
|
191
|
+
cursor = cursor.slice(parent_len);
|
|
192
|
+
|
|
193
|
+
let properties, properties_len;
|
|
194
|
+
try {
|
|
195
|
+
({ v: properties, len: properties_len } = this.ioc.anySerializer.deserialize(cursor));
|
|
196
|
+
len += properties_len;
|
|
197
|
+
} catch (err) {
|
|
198
|
+
err.message = '{properties}: ' + err.message;
|
|
199
|
+
throw err;
|
|
200
|
+
}
|
|
201
|
+
cursor = cursor.slice(properties_len);
|
|
202
|
+
|
|
203
|
+
const v = new g.Edge(
|
|
204
|
+
id,
|
|
205
|
+
new g.Vertex(outVId, outVLabel, null),
|
|
206
|
+
label,
|
|
207
|
+
new g.Vertex(inVId, inVLabel, null),
|
|
208
|
+
properties,
|
|
209
|
+
);
|
|
210
|
+
return { v, len };
|
|
211
|
+
} catch (err) {
|
|
212
|
+
throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
};
|
|
@@ -0,0 +1,148 @@
|
|
|
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 t = require('../../../../process/traversal');
|
|
26
|
+
|
|
27
|
+
module.exports = class EnumSerializer {
|
|
28
|
+
constructor(ioc) {
|
|
29
|
+
this.ioc = ioc;
|
|
30
|
+
|
|
31
|
+
const to_orig_enum = (obj) => {
|
|
32
|
+
// process/traversal.js:toEnum() changes original element name (e.g. OUT => out) for end users' convenience
|
|
33
|
+
// but we need original mapping as is w/o additional time spent on case-insensititive comparison
|
|
34
|
+
const r = {};
|
|
35
|
+
Object.values(obj).forEach((e) => (r[e.elementName] = e));
|
|
36
|
+
return r;
|
|
37
|
+
};
|
|
38
|
+
const DT = ioc.DataType;
|
|
39
|
+
this.types = [
|
|
40
|
+
{ name: 'Barrier', code: DT.BARRIER, enum: to_orig_enum(t.barrier) },
|
|
41
|
+
{ name: 'Cardinality', code: DT.CARDINALITY, enum: to_orig_enum(t.cardinality) },
|
|
42
|
+
{ name: 'Column', code: DT.COLUMN, enum: to_orig_enum(t.column) },
|
|
43
|
+
{ name: 'Direction', code: DT.DIRECTION, enum: to_orig_enum(t.direction) },
|
|
44
|
+
{ name: 'Operator', code: DT.OPERATOR, enum: to_orig_enum(t.operator) },
|
|
45
|
+
{ name: 'Order', code: DT.ORDER, enum: to_orig_enum(t.order) },
|
|
46
|
+
{ name: 'Pick', code: DT.PICK, enum: to_orig_enum(t.pick) },
|
|
47
|
+
{ name: 'Pop', code: DT.POP, enum: to_orig_enum(t.pop) },
|
|
48
|
+
{ name: 'Scope', code: DT.SCOPE, enum: to_orig_enum(t.scope) },
|
|
49
|
+
{ name: 'T', code: DT.T, enum: to_orig_enum(t.t) },
|
|
50
|
+
];
|
|
51
|
+
this.byname = {};
|
|
52
|
+
this.bycode = {};
|
|
53
|
+
for (const type of this.types) {
|
|
54
|
+
this.ioc.serializers[type.code] = this;
|
|
55
|
+
this.byname[type.name] = type;
|
|
56
|
+
this.bycode[type.code] = type;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
canBeUsedFor(value) {
|
|
61
|
+
if (!(value instanceof t.EnumValue)) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
if (!this.byname[value.typeName]) {
|
|
65
|
+
throw new Error(`EnumSerializer.serialize: typeName=${value.typeName} is not supported.`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
serialize(item, fullyQualifiedFormat = true) {
|
|
72
|
+
const type = this.byname[item.typeName];
|
|
73
|
+
if (item.elementName === undefined || item.elementName === null) {
|
|
74
|
+
if (fullyQualifiedFormat) {
|
|
75
|
+
return Buffer.from([type.code, 0x01]);
|
|
76
|
+
}
|
|
77
|
+
return Buffer.from([this.ioc.DataType.STRING, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const bufs = [];
|
|
81
|
+
if (fullyQualifiedFormat) {
|
|
82
|
+
bufs.push(Buffer.from([type.code, 0x00]));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
bufs.push(this.ioc.stringSerializer.serialize(item.elementName, true));
|
|
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
|
+
let type = undefined;
|
|
103
|
+
if (fullyQualifiedFormat) {
|
|
104
|
+
const type_code = cursor.readUInt8();
|
|
105
|
+
len++;
|
|
106
|
+
type = this.bycode[type_code];
|
|
107
|
+
if (!type) {
|
|
108
|
+
throw new Error(`unexpected {type_code}=${type_code}`);
|
|
109
|
+
}
|
|
110
|
+
cursor = cursor.slice(1);
|
|
111
|
+
|
|
112
|
+
if (cursor.length < 1) {
|
|
113
|
+
throw new Error('{value_flag} is missing');
|
|
114
|
+
}
|
|
115
|
+
const value_flag = cursor.readUInt8();
|
|
116
|
+
len++;
|
|
117
|
+
if (value_flag === 1) {
|
|
118
|
+
return { v: null, len };
|
|
119
|
+
}
|
|
120
|
+
if (value_flag !== 0) {
|
|
121
|
+
throw new Error('unexpected {value_flag}');
|
|
122
|
+
}
|
|
123
|
+
cursor = cursor.slice(1);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
let elementName, elementName_len;
|
|
127
|
+
try {
|
|
128
|
+
({ v: elementName, len: elementName_len } = this.ioc.stringSerializer.deserialize(cursor, true));
|
|
129
|
+
len += elementName_len;
|
|
130
|
+
} catch (err) {
|
|
131
|
+
err.message = 'elementName: ' + err.message;
|
|
132
|
+
throw err;
|
|
133
|
+
}
|
|
134
|
+
cursor = cursor.slice(elementName_len);
|
|
135
|
+
|
|
136
|
+
let v;
|
|
137
|
+
if (!type) {
|
|
138
|
+
v = new t.EnumValue(undefined, elementName);
|
|
139
|
+
} else {
|
|
140
|
+
v = type.enum[elementName]; // users are expected to work with maps like Map.get(T.id), i.e. it must be exactly the same object
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return { v, len };
|
|
144
|
+
} catch (err) {
|
|
145
|
+
throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
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 FloatSerializer {
|
|
26
|
+
constructor(ioc) {
|
|
27
|
+
this.ioc = ioc;
|
|
28
|
+
this.ioc.serializers[ioc.DataType.FLOAT] = this;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
canBeUsedFor(value) {
|
|
32
|
+
// it's not expected to be used
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
serialize(item, fullyQualifiedFormat = true) {
|
|
36
|
+
if (item === undefined || item === null) {
|
|
37
|
+
if (fullyQualifiedFormat) {
|
|
38
|
+
return Buffer.from([this.ioc.DataType.FLOAT, 0x01]);
|
|
39
|
+
}
|
|
40
|
+
return Buffer.from([0x00, 0x00, 0x00, 0x00]);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const bufs = [];
|
|
44
|
+
if (fullyQualifiedFormat) {
|
|
45
|
+
bufs.push(Buffer.from([this.ioc.DataType.FLOAT, 0x00]));
|
|
46
|
+
}
|
|
47
|
+
const v = Buffer.alloc(4);
|
|
48
|
+
v.writeFloatBE(item);
|
|
49
|
+
bufs.push(v);
|
|
50
|
+
|
|
51
|
+
return Buffer.concat(bufs);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
deserialize(buffer, fullyQualifiedFormat = true) {
|
|
55
|
+
let len = 0;
|
|
56
|
+
let cursor = buffer;
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
|
|
60
|
+
throw new Error('buffer is missing');
|
|
61
|
+
}
|
|
62
|
+
if (buffer.length < 1) {
|
|
63
|
+
throw new Error('buffer is empty');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (fullyQualifiedFormat) {
|
|
67
|
+
const type_code = cursor.readUInt8();
|
|
68
|
+
len++;
|
|
69
|
+
if (type_code !== this.ioc.DataType.FLOAT) {
|
|
70
|
+
throw new Error('unexpected {type_code}');
|
|
71
|
+
}
|
|
72
|
+
cursor = cursor.slice(1);
|
|
73
|
+
|
|
74
|
+
if (cursor.length < 1) {
|
|
75
|
+
throw new Error('{value_flag} is missing');
|
|
76
|
+
}
|
|
77
|
+
const value_flag = cursor.readUInt8();
|
|
78
|
+
len++;
|
|
79
|
+
if (value_flag === 1) {
|
|
80
|
+
return { v: null, len };
|
|
81
|
+
}
|
|
82
|
+
if (value_flag !== 0) {
|
|
83
|
+
throw new Error('unexpected {value_flag}');
|
|
84
|
+
}
|
|
85
|
+
cursor = cursor.slice(1);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (cursor.length < 4) {
|
|
89
|
+
throw new Error('unexpected {value} length');
|
|
90
|
+
}
|
|
91
|
+
len += 4;
|
|
92
|
+
|
|
93
|
+
const v = cursor.readFloatBE();
|
|
94
|
+
return { v, len };
|
|
95
|
+
} catch (err) {
|
|
96
|
+
throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|