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.
Files changed (105) hide show
  1. package/.eslintrc.js +3 -2
  2. package/doc/AnonymousTraversalSource.html +2 -2
  3. package/doc/Authenticator.html +2 -2
  4. package/doc/Bytecode.html +2 -2
  5. package/doc/Client.html +2 -2
  6. package/doc/Connection.html +10 -10
  7. package/doc/DriverRemoteConnection.html +2 -2
  8. package/doc/EdgeLabelVerificationStrategy.html +2 -2
  9. package/doc/Graph.html +2 -2
  10. package/doc/GraphSON2Reader.html +2 -2
  11. package/doc/GraphSON2Writer.html +2 -2
  12. package/doc/GraphSON3Reader.html +2 -2
  13. package/doc/GraphSON3Writer.html +2 -2
  14. package/doc/GraphTraversal.html +2 -2
  15. package/doc/GraphTraversalSource.html +2 -2
  16. package/doc/HaltedTraverserStrategy.html +2 -2
  17. package/doc/MatchAlgorithmStrategy.html +2 -2
  18. package/doc/P.html +2 -2
  19. package/doc/PartitionStrategy.html +2 -2
  20. package/doc/Path.html +2 -2
  21. package/doc/PlainTextSaslAuthenticator.html +2 -2
  22. package/doc/ProductiveByStrategy.html +2 -2
  23. package/doc/RemoteConnection.html +2 -2
  24. package/doc/RemoteStrategy.html +2 -2
  25. package/doc/RemoteTraversal.html +2 -2
  26. package/doc/ReservedKeysVerificationStrategy.html +2 -2
  27. package/doc/ResponseError.html +2 -2
  28. package/doc/ResultSet.html +2 -2
  29. package/doc/SaslAuthenticator.html +2 -2
  30. package/doc/SaslMechanismBase.html +2 -2
  31. package/doc/SaslMechanismPlain.html +2 -2
  32. package/doc/SeedStrategy.html +2 -2
  33. package/doc/SubgraphStrategy.html +2 -2
  34. package/doc/TextP.html +2 -2
  35. package/doc/Transaction.html +2 -2
  36. package/doc/Translator.html +2 -2
  37. package/doc/TraversalStrategies.html +2 -2
  38. package/doc/TraversalStrategy.html +2 -2
  39. package/doc/TypeSerializer.html +2 -2
  40. package/doc/driver_auth_authenticator.js.html +2 -2
  41. package/doc/driver_auth_mechanisms_sasl-mechanism-base.js.html +2 -2
  42. package/doc/driver_auth_mechanisms_sasl-mechanism-plain.js.html +2 -2
  43. package/doc/driver_auth_plain-text-sasl-authenticator.js.html +2 -2
  44. package/doc/driver_auth_sasl-authenticator.js.html +2 -2
  45. package/doc/driver_client.js.html +2 -2
  46. package/doc/driver_connection.js.html +32 -9
  47. package/doc/driver_driver-remote-connection.js.html +2 -2
  48. package/doc/driver_remote-connection.js.html +2 -2
  49. package/doc/driver_response-error.js.html +2 -2
  50. package/doc/driver_result-set.js.html +2 -2
  51. package/doc/global.html +66 -2
  52. package/doc/index.html +2 -2
  53. package/doc/module.exports.html +301 -0
  54. package/doc/process_anonymous-traversal.js.html +2 -2
  55. package/doc/process_bytecode.js.html +2 -2
  56. package/doc/process_graph-traversal.js.html +2 -2
  57. package/doc/process_transaction.js.html +2 -2
  58. package/doc/process_translator.js.html +2 -2
  59. package/doc/process_traversal-strategy.js.html +3 -3
  60. package/doc/process_traversal.js.html +2 -2
  61. package/doc/structure_graph.js.html +2 -2
  62. package/doc/structure_io_binary_internals_DataType.js.html +148 -0
  63. package/doc/structure_io_binary_internals_GraphBinaryReader.js.html +131 -0
  64. package/doc/structure_io_binary_internals_GraphBinaryWriter.js.html +134 -0
  65. package/doc/structure_io_graph-serializer.js.html +2 -2
  66. package/doc/structure_io_type-serializers.js.html +2 -2
  67. package/lib/driver/connection.js +30 -7
  68. package/lib/process/traversal-strategy.js +1 -1
  69. package/lib/structure/io/binary/GraphBinary.js +109 -0
  70. package/lib/structure/io/binary/internals/AnySerializer.js +95 -0
  71. package/lib/structure/io/binary/internals/ArraySerializer.js +135 -0
  72. package/lib/structure/io/binary/internals/BigIntegerSerializer.js +151 -0
  73. package/lib/structure/io/binary/internals/BooleanSerializer.js +103 -0
  74. package/lib/structure/io/binary/internals/BulkSetSerializer.js +124 -0
  75. package/lib/structure/io/binary/internals/ByteBufferSerializer.js +124 -0
  76. package/lib/structure/io/binary/internals/ByteSerializer.js +95 -0
  77. package/lib/structure/io/binary/internals/BytecodeSerializer.js +249 -0
  78. package/lib/structure/io/binary/internals/DataType.js +97 -0
  79. package/lib/structure/io/binary/internals/DateSerializer.js +103 -0
  80. package/lib/structure/io/binary/internals/DoubleSerializer.js +99 -0
  81. package/lib/structure/io/binary/internals/EdgeSerializer.js +215 -0
  82. package/lib/structure/io/binary/internals/EnumSerializer.js +148 -0
  83. package/lib/structure/io/binary/internals/FloatSerializer.js +99 -0
  84. package/lib/structure/io/binary/internals/GraphBinaryReader.js +80 -0
  85. package/lib/structure/io/binary/internals/GraphBinaryWriter.js +83 -0
  86. package/lib/structure/io/binary/internals/IntSerializer.js +112 -0
  87. package/lib/structure/io/binary/internals/LambdaSerializer.js +70 -0
  88. package/lib/structure/io/binary/internals/LongSerializer.js +107 -0
  89. package/lib/structure/io/binary/internals/LongSerializerNg.js +102 -0
  90. package/lib/structure/io/binary/internals/MapSerializer.js +153 -0
  91. package/lib/structure/io/binary/internals/NumberSerializationStrategy.js +68 -0
  92. package/lib/structure/io/binary/internals/PSerializer.js +151 -0
  93. package/lib/structure/io/binary/internals/PathSerializer.js +123 -0
  94. package/lib/structure/io/binary/internals/PropertySerializer.js +141 -0
  95. package/lib/structure/io/binary/internals/ShortSerializer.js +99 -0
  96. package/lib/structure/io/binary/internals/StringSerializer.js +114 -0
  97. package/lib/structure/io/binary/internals/TextPSerializer.js +145 -0
  98. package/lib/structure/io/binary/internals/TraversalStrategySerializer.js +72 -0
  99. package/lib/structure/io/binary/internals/TraverserSerializer.js +123 -0
  100. package/lib/structure/io/binary/internals/UnspecifiedNullSerializer.js +75 -0
  101. package/lib/structure/io/binary/internals/UuidSerializer.js +119 -0
  102. package/lib/structure/io/binary/internals/VertexPropertySerializer.js +172 -0
  103. package/lib/structure/io/binary/internals/VertexSerializer.js +135 -0
  104. package/lib/structure/io/binary/internals/utils.js +59 -0
  105. package/package.json +14 -7
@@ -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
+ };
@@ -0,0 +1,145 @@
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 TextPSerializer {
28
+ constructor(ioc) {
29
+ this.ioc = ioc;
30
+ this.ioc.serializers[ioc.DataType.TEXTP] = this;
31
+ }
32
+
33
+ canBeUsedFor(value) {
34
+ return value instanceof t.TextP;
35
+ }
36
+
37
+ serialize(item, fullyQualifiedFormat = true) {
38
+ if (item === undefined || item === null) {
39
+ if (fullyQualifiedFormat) {
40
+ return Buffer.from([this.ioc.DataType.TEXTP, 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.TEXTP, 0x00]));
50
+ }
51
+
52
+ // {name} is a String
53
+ bufs.push(this.ioc.stringSerializer.serialize(item.operator, false));
54
+
55
+ // {values_length}{value_0}...{value_n}
56
+ // It tries to resemble the same if-else structure as
57
+ // GraphSON.TextPSerializer.serialize() does.
58
+ let list;
59
+ if (item.other === undefined || item.other === null) {
60
+ // follows the same idea as for t.P
61
+ if (Array.isArray(item.value)) {
62
+ list = item.value;
63
+ } else {
64
+ list = [item.value];
65
+ }
66
+ } else {
67
+ list = [item.value, item.other];
68
+ }
69
+ bufs.push(this.ioc.listSerializer.serialize(list, false));
70
+
71
+ return Buffer.concat(bufs);
72
+ }
73
+
74
+ deserialize(buffer, fullyQualifiedFormat = true) {
75
+ let len = 0;
76
+ let cursor = buffer;
77
+
78
+ try {
79
+ if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
80
+ throw new Error('buffer is missing');
81
+ }
82
+ if (buffer.length < 1) {
83
+ throw new Error('buffer is empty');
84
+ }
85
+
86
+ if (fullyQualifiedFormat) {
87
+ const type_code = cursor.readUInt8();
88
+ len++;
89
+ if (type_code !== this.ioc.DataType.TEXTP) {
90
+ throw new Error('unexpected {type_code}');
91
+ }
92
+ cursor = cursor.slice(1);
93
+
94
+ if (cursor.length < 1) {
95
+ throw new Error('{value_flag} is missing');
96
+ }
97
+ const value_flag = cursor.readUInt8();
98
+ len++;
99
+ if (value_flag === 1) {
100
+ return { v: null, len };
101
+ }
102
+ if (value_flag !== 0) {
103
+ throw new Error('unexpected {value_flag}');
104
+ }
105
+ cursor = cursor.slice(1);
106
+ }
107
+
108
+ let name, name_len;
109
+ try {
110
+ ({ v: name, len: name_len } = this.ioc.stringSerializer.deserialize(cursor, false));
111
+ len += name_len;
112
+ } catch (err) {
113
+ err.message = '{name}: ' + err.message;
114
+ throw err;
115
+ }
116
+ cursor = cursor.slice(name_len);
117
+
118
+ let values, values_len;
119
+ try {
120
+ ({ v: values, len: values_len } = this.ioc.listSerializer.deserialize(cursor, false));
121
+ len += values_len;
122
+ } catch (err) {
123
+ err.message = '{values}: ' + err.message;
124
+ throw err;
125
+ }
126
+ cursor = cursor.slice(values_len);
127
+
128
+ if (values.length < 1) {
129
+ return { v: new t.TextP(''), len };
130
+ }
131
+
132
+ let v;
133
+ const TextP_static = t.TextP[name];
134
+ if (typeof TextP_static === 'function') {
135
+ v = TextP_static(...values); // it's better to follow existing logic which may depend on an operator name
136
+ } else {
137
+ v = new t.TextP(name, ...values);
138
+ }
139
+
140
+ return { v, len };
141
+ } catch (err) {
142
+ throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
143
+ }
144
+ }
145
+ };
@@ -0,0 +1,72 @@
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 { TraversalStrategySerializer: GraphsonTraversalStrategySerializer } = require('../../type-serializers');
26
+
27
+ module.exports = class TraversalStrategySerializer {
28
+ constructor(ioc) {
29
+ this.ioc = ioc;
30
+ // this.ioc.serializers[ioc.DataType.TRAVERSALSTRATEGY] = this; // TODO: it's not expected to be deserialized
31
+ this.graphsonTraversalStrategySerializer = new GraphsonTraversalStrategySerializer();
32
+ }
33
+
34
+ canBeUsedFor(value) {
35
+ return this.graphsonTraversalStrategySerializer.canBeUsedFor(value);
36
+ }
37
+
38
+ serialize(item, fullyQualifiedFormat = true) {
39
+ if (item === undefined || item === null) {
40
+ if (fullyQualifiedFormat) {
41
+ return Buffer.from([this.ioc.DataType.TRAVERSALSTRATEGY, 0x01]);
42
+ }
43
+ const strategy_class = [0x00, 0x00, 0x00, 0x00]; // ''
44
+ const configuration = [0x00, 0x00, 0x00, 0x00]; // {}
45
+ return Buffer.from([...strategy_class, ...configuration]);
46
+ // TODO: should we delegate these to respective serializers like classSerializer.serialize(undefined, false) ?
47
+ // Consider to make it the same way for all other serializers
48
+ }
49
+
50
+ const bufs = [];
51
+ if (fullyQualifiedFormat) {
52
+ bufs.push(Buffer.from([this.ioc.DataType.TRAVERSALSTRATEGY, 0x00]));
53
+ }
54
+
55
+ // let's repeat the logic of Graphson's TraversalStrategySerializer:
56
+ const strategy_class = item.fqcn;
57
+ const conf = {};
58
+ for (const k in item.configuration) {
59
+ if (item.configuration.hasOwnProperty(k)) {
60
+ conf[k] = item.configuration[k];
61
+ }
62
+ }
63
+
64
+ // {strategy_class}
65
+ bufs.push(this.ioc.classSerializer.serialize(strategy_class, false));
66
+
67
+ // {configuration}
68
+ bufs.push(this.ioc.mapSerializer.serialize(conf, false));
69
+
70
+ return Buffer.concat(bufs);
71
+ }
72
+ };
@@ -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 t = require('../../../../process/traversal');
26
+
27
+ module.exports = class TraverserSerializer {
28
+ constructor(ioc) {
29
+ this.ioc = ioc;
30
+ this.ioc.serializers[ioc.DataType.TRAVERSER] = this;
31
+ }
32
+
33
+ canBeUsedFor(value) {
34
+ return value instanceof t.Traverser;
35
+ }
36
+
37
+ serialize(item, fullyQualifiedFormat = true) {
38
+ if (item === undefined || item === null) {
39
+ if (fullyQualifiedFormat) {
40
+ return Buffer.from([this.ioc.DataType.TRAVERSER, 0x01]);
41
+ }
42
+ const bulk = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]; // 1
43
+ const value = [0xfe, 0x01]; // null
44
+ return Buffer.from([...bulk, ...value]);
45
+ }
46
+
47
+ const bufs = [];
48
+ if (fullyQualifiedFormat) {
49
+ bufs.push(Buffer.from([this.ioc.DataType.TRAVERSER, 0x00]));
50
+ }
51
+
52
+ // {bulk}
53
+ bufs.push(this.ioc.longSerializer.serialize(item.bulk, false));
54
+ // {value}
55
+ bufs.push(this.ioc.anySerializer.serialize(item.object));
56
+
57
+ return Buffer.concat(bufs);
58
+ }
59
+
60
+ deserialize(buffer, fullyQualifiedFormat = true) {
61
+ let len = 0;
62
+ let cursor = buffer;
63
+
64
+ try {
65
+ if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
66
+ throw new Error('buffer is missing');
67
+ }
68
+ if (buffer.length < 1) {
69
+ throw new Error('buffer is empty');
70
+ }
71
+
72
+ if (fullyQualifiedFormat) {
73
+ const type_code = cursor.readUInt8();
74
+ len++;
75
+ if (type_code !== this.ioc.DataType.TRAVERSER) {
76
+ throw new Error('unexpected {type_code}');
77
+ }
78
+ cursor = cursor.slice(1);
79
+
80
+ if (cursor.length < 1) {
81
+ throw new Error('{value_flag} is missing');
82
+ }
83
+ const value_flag = cursor.readUInt8();
84
+ len++;
85
+ if (value_flag === 1) {
86
+ return { v: null, len };
87
+ }
88
+ if (value_flag !== 0) {
89
+ throw new Error('unexpected {value_flag}');
90
+ }
91
+ cursor = cursor.slice(1);
92
+ }
93
+
94
+ let bulk, bulk_len;
95
+ try {
96
+ ({ v: bulk, len: bulk_len } = this.ioc.longSerializer.deserialize(cursor, false));
97
+ len += bulk_len;
98
+ } catch (err) {
99
+ err.message = '{bulk}: ' + err.message;
100
+ throw err;
101
+ }
102
+ if (bulk < 0) {
103
+ throw new Error('{bulk} is less than zero');
104
+ }
105
+ cursor = cursor.slice(bulk_len);
106
+
107
+ let value, value_len;
108
+ try {
109
+ ({ v: value, len: value_len } = this.ioc.anySerializer.deserialize(cursor));
110
+ len += value_len;
111
+ } catch (err) {
112
+ err.message = '{value}: ' + err.message;
113
+ throw err;
114
+ }
115
+ cursor = cursor.slice(value_len);
116
+
117
+ const v = new t.Traverser(value, bulk);
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,75 @@
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 UnspecifiedNullSerializer {
26
+ constructor(ioc) {
27
+ this.ioc = ioc;
28
+ this.ioc.serializers[ioc.DataType.UNSPECIFIED_NULL] = this;
29
+ }
30
+
31
+ canBeUsedFor(value) {
32
+ return value === null || value === undefined;
33
+ }
34
+
35
+ serialize(item) {
36
+ // fullyQualifiedFormat always is true
37
+ return Buffer.from([this.ioc.DataType.UNSPECIFIED_NULL, 0x01]);
38
+ }
39
+
40
+ deserialize(buffer) {
41
+ // fullyQualifiedFormat always is true
42
+ let len = 0;
43
+ let cursor = buffer;
44
+
45
+ try {
46
+ if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
47
+ throw new Error('buffer is missing');
48
+ }
49
+ if (buffer.length < 1) {
50
+ throw new Error('buffer is empty');
51
+ }
52
+
53
+ const type_code = cursor.readUInt8();
54
+ len++;
55
+ if (type_code !== this.ioc.DataType.UNSPECIFIED_NULL) {
56
+ throw new Error('unexpected {type_code}');
57
+ }
58
+ cursor = cursor.slice(1);
59
+
60
+ if (cursor.length < 1) {
61
+ throw new Error('{value_flag} is missing');
62
+ }
63
+ const value_flag = cursor.readUInt8();
64
+ len++;
65
+ if (value_flag !== 1) {
66
+ throw new Error('unexpected {value_flag}');
67
+ }
68
+ cursor = cursor.slice(1);
69
+
70
+ return { v: null, len };
71
+ } catch (err) {
72
+ throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
73
+ }
74
+ }
75
+ };