gremlin 3.6.0 → 3.6.2
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/NOTICE +1 -1
- package/doc/AnonymousTraversalSource.html +2 -2
- package/doc/Authenticator.html +2 -2
- package/doc/Bytecode.html +2 -2
- package/doc/Client.html +174 -9
- package/doc/Connection.html +43 -10
- package/doc/DriverRemoteConnection.html +144 -12
- 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 +112 -112
- package/doc/GraphTraversalSource.html +19 -19
- 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 +7 -2
- package/doc/driver_connection.js.html +49 -13
- package/doc/driver_driver-remote-connection.js.html +6 -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 +68 -4
- 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 +25 -13
- 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 +4 -4
- 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/docker-compose.yml +62 -0
- package/index.js +1 -0
- package/lib/driver/client.js +5 -0
- package/lib/driver/connection.js +47 -11
- package/lib/driver/driver-remote-connection.js +4 -0
- package/lib/process/graph-traversal.js +23 -11
- package/lib/process/traversal-strategy.js +1 -1
- package/lib/process/traversal.js +2 -2
- 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/lib/utils.js +29 -0
- package/package.json +22 -12
|
@@ -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
|
+
const t = require('../../../../process/traversal');
|
|
26
|
+
|
|
27
|
+
module.exports = class PSerializer {
|
|
28
|
+
constructor(ioc) {
|
|
29
|
+
this.ioc = ioc;
|
|
30
|
+
this.ioc.serializers[ioc.DataType.P] = this;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
canBeUsedFor(value) {
|
|
34
|
+
return value instanceof t.P;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
serialize(item, fullyQualifiedFormat = true) {
|
|
38
|
+
if (item === undefined || item === null) {
|
|
39
|
+
if (fullyQualifiedFormat) {
|
|
40
|
+
return Buffer.from([this.ioc.DataType.P, 0x01]);
|
|
41
|
+
}
|
|
42
|
+
const name = [0x00, 0x00, 0x00, 0x00]; // ''
|
|
43
|
+
const values_length = [0x00, 0x00, 0x00, 0x00]; // 0
|
|
44
|
+
return Buffer.from([...name, ...values_length]);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const bufs = [];
|
|
48
|
+
if (fullyQualifiedFormat) {
|
|
49
|
+
bufs.push(Buffer.from([this.ioc.DataType.P, 0x00]));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// {name}
|
|
53
|
+
bufs.push(this.ioc.stringSerializer.serialize(item.operator, false));
|
|
54
|
+
|
|
55
|
+
// {values_length}{value_0}...{value_n}
|
|
56
|
+
//
|
|
57
|
+
// This is a tricky part due to the nature of t.P.
|
|
58
|
+
// GraphBinary states that {name} is followed by list only,
|
|
59
|
+
// but t.P may be constructed such way that its item.value can be
|
|
60
|
+
// a usual string or something, that's why we should care here
|
|
61
|
+
// to get it wrapped into a list.
|
|
62
|
+
//
|
|
63
|
+
// It tries to resemble the same if-else structure as
|
|
64
|
+
// GraphSON.PSerializer.serialize() does.
|
|
65
|
+
let list;
|
|
66
|
+
if (item.other === undefined || item.other === null) {
|
|
67
|
+
if (Array.isArray(item.value)) {
|
|
68
|
+
list = item.value;
|
|
69
|
+
} else {
|
|
70
|
+
list = [item.value];
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
list = [item.value, item.other];
|
|
74
|
+
}
|
|
75
|
+
bufs.push(this.ioc.listSerializer.serialize(list, false));
|
|
76
|
+
|
|
77
|
+
return Buffer.concat(bufs);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
deserialize(buffer, fullyQualifiedFormat = true) {
|
|
81
|
+
let len = 0;
|
|
82
|
+
let cursor = buffer;
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
|
|
86
|
+
throw new Error('buffer is missing');
|
|
87
|
+
}
|
|
88
|
+
if (buffer.length < 1) {
|
|
89
|
+
throw new Error('buffer is empty');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (fullyQualifiedFormat) {
|
|
93
|
+
const type_code = cursor.readUInt8();
|
|
94
|
+
len++;
|
|
95
|
+
if (type_code !== this.ioc.DataType.P) {
|
|
96
|
+
throw new Error('unexpected {type_code}');
|
|
97
|
+
}
|
|
98
|
+
cursor = cursor.slice(1);
|
|
99
|
+
|
|
100
|
+
if (cursor.length < 1) {
|
|
101
|
+
throw new Error('{value_flag} is missing');
|
|
102
|
+
}
|
|
103
|
+
const value_flag = cursor.readUInt8();
|
|
104
|
+
len++;
|
|
105
|
+
if (value_flag === 1) {
|
|
106
|
+
return { v: null, len };
|
|
107
|
+
}
|
|
108
|
+
if (value_flag !== 0) {
|
|
109
|
+
throw new Error('unexpected {value_flag}');
|
|
110
|
+
}
|
|
111
|
+
cursor = cursor.slice(1);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
let name, name_len;
|
|
115
|
+
try {
|
|
116
|
+
({ v: name, len: name_len } = this.ioc.stringSerializer.deserialize(cursor, false));
|
|
117
|
+
len += name_len;
|
|
118
|
+
} catch (err) {
|
|
119
|
+
err.message = '{name}: ' + err.message;
|
|
120
|
+
throw err;
|
|
121
|
+
}
|
|
122
|
+
cursor = cursor.slice(name_len);
|
|
123
|
+
|
|
124
|
+
let values, values_len;
|
|
125
|
+
try {
|
|
126
|
+
({ v: values, len: values_len } = this.ioc.listSerializer.deserialize(cursor, false));
|
|
127
|
+
len += values_len;
|
|
128
|
+
} catch (err) {
|
|
129
|
+
err.message = '{values}: ' + err.message;
|
|
130
|
+
throw err;
|
|
131
|
+
}
|
|
132
|
+
cursor = cursor.slice(values_len);
|
|
133
|
+
|
|
134
|
+
if (values.length < 1) {
|
|
135
|
+
return { v: new t.P(''), len };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
let v;
|
|
139
|
+
const P_static = t.P[name];
|
|
140
|
+
if (typeof P_static === 'function') {
|
|
141
|
+
v = P_static(...values); // it's better to follow existing logic which may depend on an operator name
|
|
142
|
+
} else {
|
|
143
|
+
v = new t.P(name, ...values);
|
|
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,123 @@
|
|
|
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 PathSerializer {
|
|
28
|
+
constructor(ioc) {
|
|
29
|
+
this.ioc = ioc;
|
|
30
|
+
this.ioc.serializers[ioc.DataType.PATH] = this;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
canBeUsedFor(value) {
|
|
34
|
+
return value instanceof g.Path;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
serialize(item, fullyQualifiedFormat = true) {
|
|
38
|
+
if (item === undefined || item === null) {
|
|
39
|
+
if (fullyQualifiedFormat) {
|
|
40
|
+
return Buffer.from([this.ioc.DataType.PATH, 0x01]);
|
|
41
|
+
}
|
|
42
|
+
return Buffer.concat([
|
|
43
|
+
this.ioc.listSerializer.serialize([]), // {labels}=[]
|
|
44
|
+
this.ioc.listSerializer.serialize([]), // {objects}=[]
|
|
45
|
+
]);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const bufs = [];
|
|
49
|
+
if (fullyQualifiedFormat) {
|
|
50
|
+
bufs.push(Buffer.from([this.ioc.DataType.PATH, 0x00]));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// {labels} is a List in which each item is a Set of String
|
|
54
|
+
bufs.push(this.ioc.listSerializer.serialize(item.labels));
|
|
55
|
+
|
|
56
|
+
// {objects} is a List of fully qualified typed values
|
|
57
|
+
bufs.push(this.ioc.listSerializer.serialize(item.objects));
|
|
58
|
+
|
|
59
|
+
return Buffer.concat(bufs);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
deserialize(buffer, fullyQualifiedFormat = true) {
|
|
63
|
+
let len = 0;
|
|
64
|
+
let cursor = buffer;
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
|
|
68
|
+
throw new Error('buffer is missing');
|
|
69
|
+
}
|
|
70
|
+
if (buffer.length < 1) {
|
|
71
|
+
throw new Error('buffer is empty');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (fullyQualifiedFormat) {
|
|
75
|
+
const type_code = cursor.readUInt8();
|
|
76
|
+
len++;
|
|
77
|
+
if (type_code !== this.ioc.DataType.PATH) {
|
|
78
|
+
throw new Error('unexpected {type_code}');
|
|
79
|
+
}
|
|
80
|
+
cursor = cursor.slice(1);
|
|
81
|
+
|
|
82
|
+
if (cursor.length < 1) {
|
|
83
|
+
throw new Error('{value_flag} is missing');
|
|
84
|
+
}
|
|
85
|
+
const value_flag = cursor.readUInt8();
|
|
86
|
+
len++;
|
|
87
|
+
if (value_flag === 1) {
|
|
88
|
+
return { v: null, len };
|
|
89
|
+
}
|
|
90
|
+
if (value_flag !== 0) {
|
|
91
|
+
throw new Error('unexpected {value_flag}');
|
|
92
|
+
}
|
|
93
|
+
cursor = cursor.slice(1);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let labels, labels_len;
|
|
97
|
+
try {
|
|
98
|
+
({ v: labels, len: labels_len } = this.ioc.listSerializer.deserialize(cursor));
|
|
99
|
+
len += labels_len;
|
|
100
|
+
} catch (err) {
|
|
101
|
+
err.message = '{labels}: ' + err.message;
|
|
102
|
+
throw err;
|
|
103
|
+
}
|
|
104
|
+
// TODO: should we check content of labels to make sure it's List< Set<String> > ?
|
|
105
|
+
cursor = cursor.slice(labels_len);
|
|
106
|
+
|
|
107
|
+
let objects, objects_len;
|
|
108
|
+
try {
|
|
109
|
+
({ v: objects, len: objects_len } = this.ioc.listSerializer.deserialize(cursor));
|
|
110
|
+
len += objects_len;
|
|
111
|
+
} catch (err) {
|
|
112
|
+
err.message = '{objects}: ' + err.message;
|
|
113
|
+
throw err;
|
|
114
|
+
}
|
|
115
|
+
cursor = cursor.slice(objects_len);
|
|
116
|
+
|
|
117
|
+
const v = new g.Path(labels, objects);
|
|
118
|
+
return { v, len };
|
|
119
|
+
} catch (err) {
|
|
120
|
+
throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
};
|
|
@@ -0,0 +1,141 @@
|
|
|
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 PropertySerializer {
|
|
28
|
+
constructor(ioc) {
|
|
29
|
+
this.ioc = ioc;
|
|
30
|
+
this.ioc.serializers[ioc.DataType.PROPERTY] = this;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
canBeUsedFor(value) {
|
|
34
|
+
return value instanceof g.Property;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
serialize(item, fullyQualifiedFormat = true) {
|
|
38
|
+
if (item === undefined || item === null) {
|
|
39
|
+
if (fullyQualifiedFormat) {
|
|
40
|
+
return Buffer.from([this.ioc.DataType.PROPERTY, 0x01]);
|
|
41
|
+
}
|
|
42
|
+
return Buffer.concat([
|
|
43
|
+
this.ioc.stringSerializer.serialize('', false), // {key}=''
|
|
44
|
+
this.ioc.unspecifiedNullSerializer.serialize(null), // {value}=null
|
|
45
|
+
this.ioc.unspecifiedNullSerializer.serialize(null), // {parent}=null
|
|
46
|
+
]);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const bufs = [];
|
|
50
|
+
if (fullyQualifiedFormat) {
|
|
51
|
+
bufs.push(Buffer.from([this.ioc.DataType.PROPERTY, 0x00]));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// {key}
|
|
55
|
+
bufs.push(this.ioc.stringSerializer.serialize(item.key, false));
|
|
56
|
+
|
|
57
|
+
// {value}
|
|
58
|
+
bufs.push(this.ioc.anySerializer.serialize(item.value));
|
|
59
|
+
|
|
60
|
+
// {parent}
|
|
61
|
+
bufs.push(this.ioc.unspecifiedNullSerializer.serialize(null));
|
|
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.PROPERTY) {
|
|
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
|
+
// {key} is a String value
|
|
101
|
+
let key, key_len;
|
|
102
|
+
try {
|
|
103
|
+
({ v: key, len: key_len } = this.ioc.stringSerializer.deserialize(cursor, false));
|
|
104
|
+
len += key_len;
|
|
105
|
+
} catch (err) {
|
|
106
|
+
err.message = '{key}: ' + err.message;
|
|
107
|
+
throw err;
|
|
108
|
+
}
|
|
109
|
+
cursor = cursor.slice(key_len);
|
|
110
|
+
|
|
111
|
+
// {value} is a fully qualified typed value composed of {type_code}{type_info}{value_flag}{value}
|
|
112
|
+
let value, value_len;
|
|
113
|
+
try {
|
|
114
|
+
({ v: value, len: value_len } = this.ioc.anySerializer.deserialize(cursor));
|
|
115
|
+
len += value_len;
|
|
116
|
+
} catch (err) {
|
|
117
|
+
err.message = '{value}: ' + err.message;
|
|
118
|
+
throw err;
|
|
119
|
+
}
|
|
120
|
+
cursor = cursor.slice(value_len);
|
|
121
|
+
|
|
122
|
+
// {parent} is a fully qualified typed value composed of {type_code}{type_info}{value_flag}{value} which is either an Edge or VertexProperty.
|
|
123
|
+
// Note that as TinkerPop currently sends "references" only this value will always be null.
|
|
124
|
+
let parent_len;
|
|
125
|
+
try {
|
|
126
|
+
({ len: parent_len } = this.ioc.unspecifiedNullSerializer.deserialize(cursor));
|
|
127
|
+
len += parent_len;
|
|
128
|
+
} catch (err) {
|
|
129
|
+
err.message = '{parent}: ' + err.message;
|
|
130
|
+
throw err;
|
|
131
|
+
}
|
|
132
|
+
// TODO: should we verify that parent is null?
|
|
133
|
+
cursor = cursor.slice(parent_len);
|
|
134
|
+
|
|
135
|
+
const v = new g.Property(key, value);
|
|
136
|
+
return { v, len };
|
|
137
|
+
} catch (err) {
|
|
138
|
+
throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
};
|
|
@@ -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 ShortSerializer {
|
|
26
|
+
constructor(ioc) {
|
|
27
|
+
this.ioc = ioc;
|
|
28
|
+
this.ioc.serializers[ioc.DataType.SHORT] = this;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
canBeUsedFor(value) {
|
|
32
|
+
// it's not expected to be used during serialization
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
serialize(item, fullyQualifiedFormat = true) {
|
|
36
|
+
if (item === undefined || item === null) {
|
|
37
|
+
if (fullyQualifiedFormat) {
|
|
38
|
+
return Buffer.from([this.ioc.DataType.SHORT, 0x01]);
|
|
39
|
+
}
|
|
40
|
+
return Buffer.from([0x00, 0x00]);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const bufs = [];
|
|
44
|
+
if (fullyQualifiedFormat) {
|
|
45
|
+
bufs.push(Buffer.from([this.ioc.DataType.SHORT, 0x00]));
|
|
46
|
+
}
|
|
47
|
+
const v = Buffer.alloc(2);
|
|
48
|
+
v.writeInt16BE(item); // TODO: what if item is not within int16 limits, for now writeInt16BE would error
|
|
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.SHORT) {
|
|
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 < 2) {
|
|
89
|
+
throw new Error('unexpected {value} length');
|
|
90
|
+
}
|
|
91
|
+
len += 2;
|
|
92
|
+
|
|
93
|
+
const v = cursor.readInt16BE();
|
|
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,114 @@
|
|
|
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 StringSerializer {
|
|
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 typeof value === 'string';
|
|
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 this.ioc.intSerializer.serialize(0, false);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const bufs = [];
|
|
45
|
+
if (fullyQualifiedFormat) {
|
|
46
|
+
bufs.push(Buffer.from([this.ID, 0x00]));
|
|
47
|
+
}
|
|
48
|
+
const v = Buffer.from(String(item), 'utf8');
|
|
49
|
+
bufs.push(this.ioc.intSerializer.serialize(v.length, false)); // TODO: what if len > INT32_MAX, for now it's backed by logic of IntSerializer.serialize itself
|
|
50
|
+
bufs.push(v);
|
|
51
|
+
|
|
52
|
+
return Buffer.concat(bufs);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
deserialize(buffer, fullyQualifiedFormat = true, nullable = false) {
|
|
56
|
+
let len = 0;
|
|
57
|
+
let cursor = buffer;
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
|
|
61
|
+
throw new Error('buffer is missing');
|
|
62
|
+
}
|
|
63
|
+
if (buffer.length < 1) {
|
|
64
|
+
throw new Error('buffer is empty');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (fullyQualifiedFormat) {
|
|
68
|
+
const type_code = cursor.readUInt8();
|
|
69
|
+
len++;
|
|
70
|
+
if (type_code !== this.ID) {
|
|
71
|
+
throw new Error('unexpected {type_code}');
|
|
72
|
+
}
|
|
73
|
+
cursor = cursor.slice(1);
|
|
74
|
+
}
|
|
75
|
+
if (fullyQualifiedFormat || nullable) {
|
|
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
|
+
let length, length_len;
|
|
91
|
+
try {
|
|
92
|
+
({ v: length, len: length_len } = this.ioc.intSerializer.deserialize(cursor, false));
|
|
93
|
+
len += length_len;
|
|
94
|
+
} catch (err) {
|
|
95
|
+
err.message = '{length}: ' + err.message;
|
|
96
|
+
throw err;
|
|
97
|
+
}
|
|
98
|
+
if (length < 0) {
|
|
99
|
+
throw new Error('{length} is less than zero');
|
|
100
|
+
}
|
|
101
|
+
cursor = cursor.slice(length_len);
|
|
102
|
+
|
|
103
|
+
if (cursor.length < length) {
|
|
104
|
+
throw new Error('unexpected {text_value} length');
|
|
105
|
+
}
|
|
106
|
+
len += length;
|
|
107
|
+
|
|
108
|
+
const v = cursor.toString('utf8', 0, length);
|
|
109
|
+
return { v, len };
|
|
110
|
+
} catch (err) {
|
|
111
|
+
throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|