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,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,98 @@
|
|
|
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
|
+
MERGE: 0x2e,
|
|
77
|
+
|
|
78
|
+
CHAR: 0x80,
|
|
79
|
+
DURATION: 0x81,
|
|
80
|
+
INETADDRESS: 0x82,
|
|
81
|
+
INSTANT: 0x83,
|
|
82
|
+
LOCALDATE: 0x84,
|
|
83
|
+
LOCALDATETIME: 0x85,
|
|
84
|
+
LOCALTIME: 0x86,
|
|
85
|
+
MONTHDAY: 0x87,
|
|
86
|
+
OFFSETDATETIME: 0x88,
|
|
87
|
+
OFFSETTIME: 0x89,
|
|
88
|
+
PERIOD: 0x8a,
|
|
89
|
+
YEAR: 0x8b,
|
|
90
|
+
YEARMONTH: 0x8c,
|
|
91
|
+
ZONEDATETIME: 0x8d,
|
|
92
|
+
ZONEOFFSET: 0x8e,
|
|
93
|
+
|
|
94
|
+
CUSTOM: 0,
|
|
95
|
+
UNSPECIFIED_NULL: 0xfe,
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
module.exports = DataType;
|
|
@@ -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
|
+
};
|