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.
Files changed (113) hide show
  1. package/.eslintrc.js +3 -2
  2. package/NOTICE +1 -1
  3. package/doc/AnonymousTraversalSource.html +2 -2
  4. package/doc/Authenticator.html +2 -2
  5. package/doc/Bytecode.html +2 -2
  6. package/doc/Client.html +174 -9
  7. package/doc/Connection.html +43 -10
  8. package/doc/DriverRemoteConnection.html +144 -12
  9. package/doc/EdgeLabelVerificationStrategy.html +2 -2
  10. package/doc/Graph.html +2 -2
  11. package/doc/GraphSON2Reader.html +2 -2
  12. package/doc/GraphSON2Writer.html +2 -2
  13. package/doc/GraphSON3Reader.html +2 -2
  14. package/doc/GraphSON3Writer.html +2 -2
  15. package/doc/GraphTraversal.html +112 -112
  16. package/doc/GraphTraversalSource.html +19 -19
  17. package/doc/HaltedTraverserStrategy.html +2 -2
  18. package/doc/MatchAlgorithmStrategy.html +2 -2
  19. package/doc/P.html +2 -2
  20. package/doc/PartitionStrategy.html +2 -2
  21. package/doc/Path.html +2 -2
  22. package/doc/PlainTextSaslAuthenticator.html +2 -2
  23. package/doc/ProductiveByStrategy.html +2 -2
  24. package/doc/RemoteConnection.html +2 -2
  25. package/doc/RemoteStrategy.html +2 -2
  26. package/doc/RemoteTraversal.html +2 -2
  27. package/doc/ReservedKeysVerificationStrategy.html +2 -2
  28. package/doc/ResponseError.html +2 -2
  29. package/doc/ResultSet.html +2 -2
  30. package/doc/SaslAuthenticator.html +2 -2
  31. package/doc/SaslMechanismBase.html +2 -2
  32. package/doc/SaslMechanismPlain.html +2 -2
  33. package/doc/SeedStrategy.html +2 -2
  34. package/doc/SubgraphStrategy.html +2 -2
  35. package/doc/TextP.html +2 -2
  36. package/doc/Transaction.html +2 -2
  37. package/doc/Translator.html +2 -2
  38. package/doc/TraversalStrategies.html +2 -2
  39. package/doc/TraversalStrategy.html +2 -2
  40. package/doc/TypeSerializer.html +2 -2
  41. package/doc/driver_auth_authenticator.js.html +2 -2
  42. package/doc/driver_auth_mechanisms_sasl-mechanism-base.js.html +2 -2
  43. package/doc/driver_auth_mechanisms_sasl-mechanism-plain.js.html +2 -2
  44. package/doc/driver_auth_plain-text-sasl-authenticator.js.html +2 -2
  45. package/doc/driver_auth_sasl-authenticator.js.html +2 -2
  46. package/doc/driver_client.js.html +7 -2
  47. package/doc/driver_connection.js.html +49 -13
  48. package/doc/driver_driver-remote-connection.js.html +6 -2
  49. package/doc/driver_remote-connection.js.html +2 -2
  50. package/doc/driver_response-error.js.html +2 -2
  51. package/doc/driver_result-set.js.html +2 -2
  52. package/doc/global.html +68 -4
  53. package/doc/index.html +2 -2
  54. package/doc/module.exports.html +301 -0
  55. package/doc/process_anonymous-traversal.js.html +2 -2
  56. package/doc/process_bytecode.js.html +2 -2
  57. package/doc/process_graph-traversal.js.html +25 -13
  58. package/doc/process_transaction.js.html +2 -2
  59. package/doc/process_translator.js.html +2 -2
  60. package/doc/process_traversal-strategy.js.html +3 -3
  61. package/doc/process_traversal.js.html +4 -4
  62. package/doc/structure_graph.js.html +2 -2
  63. package/doc/structure_io_binary_internals_DataType.js.html +149 -0
  64. package/doc/structure_io_binary_internals_GraphBinaryReader.js.html +131 -0
  65. package/doc/structure_io_binary_internals_GraphBinaryWriter.js.html +134 -0
  66. package/doc/structure_io_graph-serializer.js.html +2 -2
  67. package/doc/structure_io_type-serializers.js.html +2 -2
  68. package/docker-compose.yml +62 -0
  69. package/index.js +1 -0
  70. package/lib/driver/client.js +5 -0
  71. package/lib/driver/connection.js +47 -11
  72. package/lib/driver/driver-remote-connection.js +4 -0
  73. package/lib/process/graph-traversal.js +23 -11
  74. package/lib/process/traversal-strategy.js +1 -1
  75. package/lib/process/traversal.js +2 -2
  76. package/lib/structure/io/binary/GraphBinary.js +109 -0
  77. package/lib/structure/io/binary/internals/AnySerializer.js +95 -0
  78. package/lib/structure/io/binary/internals/ArraySerializer.js +135 -0
  79. package/lib/structure/io/binary/internals/BigIntegerSerializer.js +151 -0
  80. package/lib/structure/io/binary/internals/BooleanSerializer.js +103 -0
  81. package/lib/structure/io/binary/internals/BulkSetSerializer.js +124 -0
  82. package/lib/structure/io/binary/internals/ByteBufferSerializer.js +124 -0
  83. package/lib/structure/io/binary/internals/ByteSerializer.js +95 -0
  84. package/lib/structure/io/binary/internals/BytecodeSerializer.js +249 -0
  85. package/lib/structure/io/binary/internals/DataType.js +98 -0
  86. package/lib/structure/io/binary/internals/DateSerializer.js +103 -0
  87. package/lib/structure/io/binary/internals/DoubleSerializer.js +99 -0
  88. package/lib/structure/io/binary/internals/EdgeSerializer.js +215 -0
  89. package/lib/structure/io/binary/internals/EnumSerializer.js +149 -0
  90. package/lib/structure/io/binary/internals/FloatSerializer.js +99 -0
  91. package/lib/structure/io/binary/internals/GraphBinaryReader.js +80 -0
  92. package/lib/structure/io/binary/internals/GraphBinaryWriter.js +83 -0
  93. package/lib/structure/io/binary/internals/IntSerializer.js +112 -0
  94. package/lib/structure/io/binary/internals/LambdaSerializer.js +70 -0
  95. package/lib/structure/io/binary/internals/LongSerializer.js +107 -0
  96. package/lib/structure/io/binary/internals/LongSerializerNg.js +102 -0
  97. package/lib/structure/io/binary/internals/MapSerializer.js +153 -0
  98. package/lib/structure/io/binary/internals/NumberSerializationStrategy.js +68 -0
  99. package/lib/structure/io/binary/internals/PSerializer.js +151 -0
  100. package/lib/structure/io/binary/internals/PathSerializer.js +123 -0
  101. package/lib/structure/io/binary/internals/PropertySerializer.js +141 -0
  102. package/lib/structure/io/binary/internals/ShortSerializer.js +99 -0
  103. package/lib/structure/io/binary/internals/StringSerializer.js +114 -0
  104. package/lib/structure/io/binary/internals/TextPSerializer.js +145 -0
  105. package/lib/structure/io/binary/internals/TraversalStrategySerializer.js +72 -0
  106. package/lib/structure/io/binary/internals/TraverserSerializer.js +123 -0
  107. package/lib/structure/io/binary/internals/UnspecifiedNullSerializer.js +75 -0
  108. package/lib/structure/io/binary/internals/UuidSerializer.js +119 -0
  109. package/lib/structure/io/binary/internals/VertexPropertySerializer.js +172 -0
  110. package/lib/structure/io/binary/internals/VertexSerializer.js +135 -0
  111. package/lib/structure/io/binary/internals/utils.js +59 -0
  112. package/lib/utils.js +29 -0
  113. package/package.json +22 -12
@@ -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,149 @@
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: 'Merge', code: DT.MERGE, enum: to_orig_enum(t.merge) },
45
+ { name: 'Operator', code: DT.OPERATOR, enum: to_orig_enum(t.operator) },
46
+ { name: 'Order', code: DT.ORDER, enum: to_orig_enum(t.order) },
47
+ { name: 'Pick', code: DT.PICK, enum: to_orig_enum(t.pick) },
48
+ { name: 'Pop', code: DT.POP, enum: to_orig_enum(t.pop) },
49
+ { name: 'Scope', code: DT.SCOPE, enum: to_orig_enum(t.scope) },
50
+ { name: 'T', code: DT.T, enum: to_orig_enum(t.t) },
51
+ ];
52
+ this.byname = {};
53
+ this.bycode = {};
54
+ for (const type of this.types) {
55
+ this.ioc.serializers[type.code] = this;
56
+ this.byname[type.name] = type;
57
+ this.bycode[type.code] = type;
58
+ }
59
+ }
60
+
61
+ canBeUsedFor(value) {
62
+ if (!(value instanceof t.EnumValue)) {
63
+ return false;
64
+ }
65
+ if (!this.byname[value.typeName]) {
66
+ throw new Error(`EnumSerializer.serialize: typeName=${value.typeName} is not supported.`);
67
+ }
68
+
69
+ return true;
70
+ }
71
+
72
+ serialize(item, fullyQualifiedFormat = true) {
73
+ const type = this.byname[item.typeName];
74
+ if (item.elementName === undefined || item.elementName === null) {
75
+ if (fullyQualifiedFormat) {
76
+ return Buffer.from([type.code, 0x01]);
77
+ }
78
+ return Buffer.from([this.ioc.DataType.STRING, 0x00, 0x00, 0x00, 0x00, 0x00]);
79
+ }
80
+
81
+ const bufs = [];
82
+ if (fullyQualifiedFormat) {
83
+ bufs.push(Buffer.from([type.code, 0x00]));
84
+ }
85
+
86
+ bufs.push(this.ioc.stringSerializer.serialize(item.elementName, true));
87
+
88
+ return Buffer.concat(bufs);
89
+ }
90
+
91
+ deserialize(buffer, fullyQualifiedFormat = true) {
92
+ let len = 0;
93
+ let cursor = buffer;
94
+
95
+ try {
96
+ if (buffer === undefined || buffer === null || !(buffer instanceof Buffer)) {
97
+ throw new Error('buffer is missing');
98
+ }
99
+ if (buffer.length < 1) {
100
+ throw new Error('buffer is empty');
101
+ }
102
+
103
+ let type = undefined;
104
+ if (fullyQualifiedFormat) {
105
+ const type_code = cursor.readUInt8();
106
+ len++;
107
+ type = this.bycode[type_code];
108
+ if (!type) {
109
+ throw new Error(`unexpected {type_code}=${type_code}`);
110
+ }
111
+ cursor = cursor.slice(1);
112
+
113
+ if (cursor.length < 1) {
114
+ throw new Error('{value_flag} is missing');
115
+ }
116
+ const value_flag = cursor.readUInt8();
117
+ len++;
118
+ if (value_flag === 1) {
119
+ return { v: null, len };
120
+ }
121
+ if (value_flag !== 0) {
122
+ throw new Error('unexpected {value_flag}');
123
+ }
124
+ cursor = cursor.slice(1);
125
+ }
126
+
127
+ let elementName, elementName_len;
128
+ try {
129
+ ({ v: elementName, len: elementName_len } = this.ioc.stringSerializer.deserialize(cursor, true));
130
+ len += elementName_len;
131
+ } catch (err) {
132
+ err.message = 'elementName: ' + err.message;
133
+ throw err;
134
+ }
135
+ cursor = cursor.slice(elementName_len);
136
+
137
+ let v;
138
+ if (!type) {
139
+ v = new t.EnumValue(undefined, elementName);
140
+ } else {
141
+ 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
142
+ }
143
+
144
+ return { v, len };
145
+ } catch (err) {
146
+ throw this.ioc.utils.des_error({ serializer: this, args: arguments, cursor, err });
147
+ }
148
+ }
149
+ };
@@ -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
+ };
@@ -0,0 +1,80 @@
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
+ * GraphBinary reader.
27
+ */
28
+ module.exports = class GraphBinaryReader {
29
+ constructor(ioc) {
30
+ this.ioc = ioc;
31
+ }
32
+
33
+ readResponse(buffer) {
34
+ if (buffer === undefined || buffer === null) {
35
+ throw new Error('Buffer is missing.');
36
+ }
37
+ if (!(buffer instanceof Buffer)) {
38
+ throw new Error('Not an instance of Buffer.');
39
+ }
40
+ if (buffer.length < 1) {
41
+ throw new Error('Buffer is empty.');
42
+ }
43
+
44
+ const response = { status: {}, result: {} };
45
+ let cursor = buffer;
46
+ let len;
47
+
48
+ // {version} is a Byte representing the protocol version
49
+ const version = cursor[0];
50
+ if (version !== 0x81) {
51
+ throw new Error(`Unsupported version '${version}'.`);
52
+ }
53
+ cursor = cursor.slice(1); // skip version
54
+
55
+ // {request_id} is a nullable UUID
56
+ ({ v: response.requestId, len } = this.ioc.uuidSerializer.deserialize(cursor, false, true));
57
+ cursor = cursor.slice(len);
58
+
59
+ // {status_code} is an Int
60
+ ({ v: response.status.code, len } = this.ioc.intSerializer.deserialize(cursor, false));
61
+ cursor = cursor.slice(len);
62
+
63
+ // {status_message} is a nullable String
64
+ ({ v: response.status.message, len } = this.ioc.stringSerializer.deserialize(cursor, false, true));
65
+ cursor = cursor.slice(len);
66
+
67
+ // {status_attributes} is a Map
68
+ ({ v: response.status.attributes, len } = this.ioc.mapSerializer.deserialize(cursor, false));
69
+ cursor = cursor.slice(len);
70
+
71
+ // {result_meta} is a Map
72
+ ({ v: response.result.meta, len } = this.ioc.mapSerializer.deserialize(cursor, false));
73
+ cursor = cursor.slice(len);
74
+
75
+ // {result_data} is a fully qualified typed value composed of {type_code}{type_info}{value_flag}{value}
76
+ ({ v: response.result.data } = this.ioc.anySerializer.deserialize(cursor));
77
+
78
+ return response;
79
+ }
80
+ };
@@ -0,0 +1,83 @@
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
+ * GraphBinary writer.
27
+ */
28
+ module.exports = class GraphBinaryWriter {
29
+ constructor(ioc) {
30
+ this.ioc = ioc;
31
+ }
32
+
33
+ writeRequest({ requestId, op, processor, args }) {
34
+ const bufs = [
35
+ // {version} 1 byte
36
+ Buffer.from([0x81]),
37
+ // {request_id} UUID
38
+ this.ioc.uuidSerializer.serialize(requestId, false),
39
+ // {op} String
40
+ this.ioc.stringSerializer.serialize(op, false),
41
+ // {processor} String
42
+ this.ioc.stringSerializer.serialize(processor, false),
43
+ // {args} Map
44
+ this.ioc.mapSerializer.serialize(args, false),
45
+ ];
46
+ return Buffer.concat(bufs);
47
+
48
+ /*// Detailed example for a quick reference:
49
+ // {version}
50
+ 0x81,
51
+ // {request_id} UUID
52
+ 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
53
+ // {op} String
54
+ 0x00,0x00,0x00,0x08, ...Buffer.from('bytecode'),
55
+ // {processor} String
56
+ 0x00,0x00,0x00,0x09, ...Buffer.from('traversal'),
57
+ // {args} Map
58
+ 0x00,0x00,0x00,0x02,
59
+ // 1.
60
+ // args.aliases key String
61
+ 0x03,0x00, 0x00,0x00,0x00,0x07, ...Buffer.from('aliases'),
62
+ // args.aliases value Map
63
+ 0x0A,0x00, 0x00,0x00,0x00,0x01,
64
+ // aliases.g key String
65
+ 0x03,0x00, 0x00,0x00,0x00,0x01, ...Buffer.from('g'),
66
+ // aliases.g value String
67
+ 0x03,0x00, 0x00,0x00,0x00,0x01, ...Buffer.from('g'),
68
+ // 2.
69
+ // args.gremlin key String
70
+ 0x03,0x00, 0x00,0x00,0x00,0x07, ...Buffer.from('gremlin'),
71
+ // args.gremlin value Bytecode
72
+ 0x15,0x00,
73
+ // {steps_length}
74
+ 0x00,0x00,0x00,0x01,
75
+ // step 1 - {name} String
76
+ 0x00,0x00,0x00,0x01, ...Buffer.from('V'),
77
+ // step 1 - {values_length} Int
78
+ 0x00,0x00,0x00,0x00,
79
+ // {sources_length}
80
+ 0x00,0x00,0x00,0x00,
81
+ */
82
+ }
83
+ };