@platformatic/kafka 0.1.0
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/LICENSE +201 -0
- package/README.md +270 -0
- package/dist/apis/admin/alter-client-quotas.d.ts +33 -0
- package/dist/apis/admin/alter-client-quotas.js +64 -0
- package/dist/apis/admin/alter-configs.d.ts +26 -0
- package/dist/apis/admin/alter-configs.js +57 -0
- package/dist/apis/admin/alter-partition-reassignments.d.ts +30 -0
- package/dist/apis/admin/alter-partition-reassignments.js +68 -0
- package/dist/apis/admin/alter-partition.d.ts +39 -0
- package/dist/apis/admin/alter-partition.js +87 -0
- package/dist/apis/admin/alter-replica-log-dirs.d.ts +26 -0
- package/dist/apis/admin/alter-replica-log-dirs.js +55 -0
- package/dist/apis/admin/alter-user-scram-credentials.d.ts +27 -0
- package/dist/apis/admin/alter-user-scram-credentials.js +60 -0
- package/dist/apis/admin/consumer-group-describe.d.ts +41 -0
- package/dist/apis/admin/consumer-group-describe.js +103 -0
- package/dist/apis/admin/create-acls.d.ts +24 -0
- package/dist/apis/admin/create-acls.js +55 -0
- package/dist/apis/admin/create-delegation-token.d.ts +24 -0
- package/dist/apis/admin/create-delegation-token.js +54 -0
- package/dist/apis/admin/create-partitions.d.ts +24 -0
- package/dist/apis/admin/create-partitions.js +54 -0
- package/dist/apis/admin/create-topics.d.ts +42 -0
- package/dist/apis/admin/create-topics.js +86 -0
- package/dist/apis/admin/delete-acls.d.ts +36 -0
- package/dist/apis/admin/delete-acls.js +82 -0
- package/dist/apis/admin/delete-groups.d.ts +14 -0
- package/dist/apis/admin/delete-groups.js +40 -0
- package/dist/apis/admin/delete-records.d.ts +27 -0
- package/dist/apis/admin/delete-records.js +59 -0
- package/dist/apis/admin/delete-topics.d.ts +21 -0
- package/dist/apis/admin/delete-topics.js +50 -0
- package/dist/apis/admin/describe-acls.d.ts +25 -0
- package/dist/apis/admin/describe-acls.js +66 -0
- package/dist/apis/admin/describe-client-quotas.d.ts +30 -0
- package/dist/apis/admin/describe-client-quotas.js +57 -0
- package/dist/apis/admin/describe-cluster.d.ts +23 -0
- package/dist/apis/admin/describe-cluster.js +50 -0
- package/dist/apis/admin/describe-configs.d.ts +38 -0
- package/dist/apis/admin/describe-configs.js +85 -0
- package/dist/apis/admin/describe-delegation-token.d.ts +31 -0
- package/dist/apis/admin/describe-delegation-token.js +62 -0
- package/dist/apis/admin/describe-groups.d.ts +28 -0
- package/dist/apis/admin/describe-groups.js +67 -0
- package/dist/apis/admin/describe-log-dirs.d.ts +32 -0
- package/dist/apis/admin/describe-log-dirs.js +75 -0
- package/dist/apis/admin/describe-producers.d.ts +33 -0
- package/dist/apis/admin/describe-producers.js +70 -0
- package/dist/apis/admin/describe-quorum.d.ts +50 -0
- package/dist/apis/admin/describe-quorum.js +116 -0
- package/dist/apis/admin/describe-topic-partitions.d.ts +42 -0
- package/dist/apis/admin/describe-topic-partitions.js +94 -0
- package/dist/apis/admin/describe-transactions.d.ts +24 -0
- package/dist/apis/admin/describe-transactions.js +59 -0
- package/dist/apis/admin/describe-user-scram-credentials.d.ts +26 -0
- package/dist/apis/admin/describe-user-scram-credentials.js +62 -0
- package/dist/apis/admin/envelope.d.ts +10 -0
- package/dist/apis/admin/envelope.js +32 -0
- package/dist/apis/admin/expire-delegation-token.d.ts +11 -0
- package/dist/apis/admin/expire-delegation-token.js +29 -0
- package/dist/apis/admin/incremental-alter-configs.d.ts +27 -0
- package/dist/apis/admin/incremental-alter-configs.js +58 -0
- package/dist/apis/admin/index.d.ts +37 -0
- package/dist/apis/admin/index.js +37 -0
- package/dist/apis/admin/list-groups.d.ts +18 -0
- package/dist/apis/admin/list-groups.js +43 -0
- package/dist/apis/admin/list-partition-reassignments.d.ts +27 -0
- package/dist/apis/admin/list-partition-reassignments.js +56 -0
- package/dist/apis/admin/list-transactions.d.ts +18 -0
- package/dist/apis/admin/list-transactions.js +45 -0
- package/dist/apis/admin/offset-delete.d.ts +26 -0
- package/dist/apis/admin/offset-delete.js +59 -0
- package/dist/apis/admin/renew-delegation-token.d.ts +11 -0
- package/dist/apis/admin/renew-delegation-token.js +29 -0
- package/dist/apis/admin/unregister-broker.d.ts +12 -0
- package/dist/apis/admin/unregister-broker.js +28 -0
- package/dist/apis/admin/update-features.d.ts +23 -0
- package/dist/apis/admin/update-features.js +60 -0
- package/dist/apis/consumer/consumer-group-heartbeat.d.ts +27 -0
- package/dist/apis/consumer/consumer-group-heartbeat.js +70 -0
- package/dist/apis/consumer/fetch.d.ts +46 -0
- package/dist/apis/consumer/fetch.js +121 -0
- package/dist/apis/consumer/heartbeat.d.ts +11 -0
- package/dist/apis/consumer/heartbeat.js +34 -0
- package/dist/apis/consumer/index.d.ts +9 -0
- package/dist/apis/consumer/index.js +9 -0
- package/dist/apis/consumer/join-group.d.ts +27 -0
- package/dist/apis/consumer/join-group.js +71 -0
- package/dist/apis/consumer/leave-group.d.ts +22 -0
- package/dist/apis/consumer/leave-group.js +57 -0
- package/dist/apis/consumer/list-offsets.d.ts +30 -0
- package/dist/apis/consumer/list-offsets.js +68 -0
- package/dist/apis/consumer/offset-commit.d.ts +29 -0
- package/dist/apis/consumer/offset-commit.js +68 -0
- package/dist/apis/consumer/offset-fetch.d.ts +37 -0
- package/dist/apis/consumer/offset-fetch.js +81 -0
- package/dist/apis/consumer/sync-group.d.ts +18 -0
- package/dist/apis/consumer/sync-group.js +49 -0
- package/dist/apis/definitions.d.ts +16 -0
- package/dist/apis/definitions.js +12 -0
- package/dist/apis/enumerations.d.ts +114 -0
- package/dist/apis/enumerations.js +78 -0
- package/dist/apis/index.d.ts +8 -0
- package/dist/apis/index.js +10 -0
- package/dist/apis/metadata/api-versions.d.ts +17 -0
- package/dist/apis/metadata/api-versions.js +41 -0
- package/dist/apis/metadata/find-coordinator.d.ts +19 -0
- package/dist/apis/metadata/find-coordinator.js +50 -0
- package/dist/apis/metadata/index.d.ts +3 -0
- package/dist/apis/metadata/index.js +3 -0
- package/dist/apis/metadata/metadata.d.ts +37 -0
- package/dist/apis/metadata/metadata.js +92 -0
- package/dist/apis/producer/add-offsets-to-txn.d.ts +10 -0
- package/dist/apis/producer/add-offsets-to-txn.js +34 -0
- package/dist/apis/producer/add-partitions-to-txn.d.ts +34 -0
- package/dist/apis/producer/add-partitions-to-txn.js +79 -0
- package/dist/apis/producer/end-txn.d.ts +10 -0
- package/dist/apis/producer/end-txn.js +34 -0
- package/dist/apis/producer/index.d.ts +6 -0
- package/dist/apis/producer/index.js +6 -0
- package/dist/apis/producer/init-producer-id.d.ts +21 -0
- package/dist/apis/producer/init-producer-id.js +38 -0
- package/dist/apis/producer/produce.d.ts +29 -0
- package/dist/apis/producer/produce.js +104 -0
- package/dist/apis/producer/txn-offset-commit.d.ts +29 -0
- package/dist/apis/producer/txn-offset-commit.js +77 -0
- package/dist/apis/security/index.d.ts +2 -0
- package/dist/apis/security/index.js +2 -0
- package/dist/apis/security/sasl-authenticate.d.ts +15 -0
- package/dist/apis/security/sasl-authenticate.js +30 -0
- package/dist/apis/security/sasl-handshake.d.ts +10 -0
- package/dist/apis/security/sasl-handshake.js +28 -0
- package/dist/apis/telemetry/get-telemetry-subscriptions.d.ts +18 -0
- package/dist/apis/telemetry/get-telemetry-subscriptions.js +46 -0
- package/dist/apis/telemetry/index.d.ts +3 -0
- package/dist/apis/telemetry/index.js +3 -0
- package/dist/apis/telemetry/list-client-metrics-resources.d.ts +14 -0
- package/dist/apis/telemetry/list-client-metrics-resources.js +32 -0
- package/dist/apis/telemetry/push-telemetry.d.ts +10 -0
- package/dist/apis/telemetry/push-telemetry.js +36 -0
- package/dist/clients/admin/admin.d.ts +18 -0
- package/dist/clients/admin/admin.js +322 -0
- package/dist/clients/admin/index.d.ts +3 -0
- package/dist/clients/admin/index.js +3 -0
- package/dist/clients/admin/options.d.ts +135 -0
- package/dist/clients/admin/options.js +81 -0
- package/dist/clients/admin/types.d.ts +56 -0
- package/dist/clients/admin/types.js +1 -0
- package/dist/clients/base/base.d.ts +48 -0
- package/dist/clients/base/base.js +242 -0
- package/dist/clients/base/index.d.ts +3 -0
- package/dist/clients/base/index.js +3 -0
- package/dist/clients/base/options.d.ts +115 -0
- package/dist/clients/base/options.js +59 -0
- package/dist/clients/base/types.d.ts +38 -0
- package/dist/clients/base/types.js +1 -0
- package/dist/clients/callbacks.d.ts +8 -0
- package/dist/clients/callbacks.js +42 -0
- package/dist/clients/consumer/consumer.d.ts +33 -0
- package/dist/clients/consumer/consumer.js +767 -0
- package/dist/clients/consumer/index.d.ts +5 -0
- package/dist/clients/consumer/index.js +5 -0
- package/dist/clients/consumer/messages-stream.d.ts +56 -0
- package/dist/clients/consumer/messages-stream.js +404 -0
- package/dist/clients/consumer/options.d.ts +521 -0
- package/dist/clients/consumer/options.js +177 -0
- package/dist/clients/consumer/topics-map.d.ts +8 -0
- package/dist/clients/consumer/topics-map.js +48 -0
- package/dist/clients/consumer/types.d.ts +74 -0
- package/dist/clients/consumer/types.js +11 -0
- package/dist/clients/index.d.ts +6 -0
- package/dist/clients/index.js +6 -0
- package/dist/clients/producer/index.d.ts +3 -0
- package/dist/clients/producer/index.js +3 -0
- package/dist/clients/producer/options.d.ts +122 -0
- package/dist/clients/producer/options.js +47 -0
- package/dist/clients/producer/producer.d.ts +13 -0
- package/dist/clients/producer/producer.js +272 -0
- package/dist/clients/producer/types.d.ts +29 -0
- package/dist/clients/producer/types.js +1 -0
- package/dist/clients/serde.d.ts +40 -0
- package/dist/clients/serde.js +49 -0
- package/dist/errors.d.ts +67 -0
- package/dist/errors.js +160 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +10 -0
- package/dist/network/connection-pool.d.ts +11 -0
- package/dist/network/connection-pool.js +101 -0
- package/dist/network/connection.d.ts +49 -0
- package/dist/network/connection.js +319 -0
- package/dist/network/index.d.ts +2 -0
- package/dist/network/index.js +2 -0
- package/dist/protocol/apis.d.ts +2 -0
- package/dist/protocol/apis.js +191 -0
- package/dist/protocol/compression.d.ts +70 -0
- package/dist/protocol/compression.js +114 -0
- package/dist/protocol/crc32c.d.ts +2 -0
- package/dist/protocol/crc32c.js +83 -0
- package/dist/protocol/definitions.d.ts +12 -0
- package/dist/protocol/definitions.js +11 -0
- package/dist/protocol/dynamic-buffer.d.ts +65 -0
- package/dist/protocol/dynamic-buffer.js +557 -0
- package/dist/protocol/errors.d.ts +8 -0
- package/dist/protocol/errors.js +908 -0
- package/dist/protocol/index.d.ts +14 -0
- package/dist/protocol/index.js +14 -0
- package/dist/protocol/murmur2.d.ts +1 -0
- package/dist/protocol/murmur2.js +55 -0
- package/dist/protocol/reader.d.ts +58 -0
- package/dist/protocol/reader.js +296 -0
- package/dist/protocol/records.d.ts +110 -0
- package/dist/protocol/records.js +149 -0
- package/dist/protocol/sasl/plain.d.ts +3 -0
- package/dist/protocol/sasl/plain.js +3 -0
- package/dist/protocol/sasl/scram-sha.d.ts +28 -0
- package/dist/protocol/sasl/scram-sha.js +104 -0
- package/dist/protocol/varint.d.ts +12 -0
- package/dist/protocol/varint.js +36 -0
- package/dist/protocol/writer.d.ts +48 -0
- package/dist/protocol/writer.js +223 -0
- package/dist/utils.d.ts +20 -0
- package/dist/utils.js +127 -0
- package/package.json +75 -0
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
import { UserError } from "../errors.js";
|
|
2
|
+
import { EMPTY_BUFFER, INT16_SIZE, INT32_SIZE, INT64_SIZE, INT8_SIZE } from "./definitions.js";
|
|
3
|
+
import { BITS_8PLUS_MASK, BITS_8PLUS_MASK_64, int64ZigZagDecode, int64ZigZagEncode, intZigZagDecode, intZigZagEncode, LEAST_SIGNIFICANT_7_BITS, LEAST_SIGNIFICANT_7_BITS_64, MOST_SIGNIFICANT_BIT_FLAG, MOST_SIGNIFICANT_BIT_FLAG_64, sizeOfUnsignedVarInt, sizeOfUnsignedVarInt64 } from "./varint.js";
|
|
4
|
+
const instanceIdentifier = Symbol('plt.kafka.dynamicBuffer.instanceIdentifier');
|
|
5
|
+
export class DynamicBuffer {
|
|
6
|
+
buffers;
|
|
7
|
+
length;
|
|
8
|
+
#readBuffer; // This is used from the fixed length readers
|
|
9
|
+
[instanceIdentifier];
|
|
10
|
+
static isDynamicBuffer(target) {
|
|
11
|
+
return target?.[instanceIdentifier] === true;
|
|
12
|
+
}
|
|
13
|
+
constructor(buffers) {
|
|
14
|
+
this.buffers = [];
|
|
15
|
+
this.length = 0;
|
|
16
|
+
this.#readBuffer = Buffer.allocUnsafe(8);
|
|
17
|
+
this[instanceIdentifier] = true;
|
|
18
|
+
if (buffers) {
|
|
19
|
+
if (Buffer.isBuffer(buffers)) {
|
|
20
|
+
this.buffers.push(buffers);
|
|
21
|
+
this.length += buffers.length;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
for (const buffer of buffers) {
|
|
25
|
+
this.buffers.push(buffer);
|
|
26
|
+
this.length += buffer.length;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
get buffer() {
|
|
32
|
+
if (this.buffers.length === 0) {
|
|
33
|
+
return EMPTY_BUFFER;
|
|
34
|
+
}
|
|
35
|
+
if (this.buffers.length === 1) {
|
|
36
|
+
return this.buffers[0];
|
|
37
|
+
}
|
|
38
|
+
return Buffer.concat(this.buffers, this.length);
|
|
39
|
+
}
|
|
40
|
+
append(buffer) {
|
|
41
|
+
this.buffers.push(buffer);
|
|
42
|
+
this.length += buffer.length;
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
prepend(buffer) {
|
|
46
|
+
this.buffers.unshift(buffer);
|
|
47
|
+
this.length += buffer.length;
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
appendFrom(DynamicBuffer) {
|
|
51
|
+
this.buffers.push(...DynamicBuffer.buffers);
|
|
52
|
+
this.length += DynamicBuffer.length;
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
prependFrom(DynamicBuffer) {
|
|
56
|
+
this.buffers.unshift(...DynamicBuffer.buffers);
|
|
57
|
+
this.length += DynamicBuffer.length;
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
subarray(start = 0, end) {
|
|
61
|
+
if (typeof end === 'undefined') {
|
|
62
|
+
end = this.length;
|
|
63
|
+
}
|
|
64
|
+
if (start < 0 || start > this.length || end > this.length) {
|
|
65
|
+
throw new UserError('Out of bounds.');
|
|
66
|
+
}
|
|
67
|
+
if (this.buffers.length === 0) {
|
|
68
|
+
return new DynamicBuffer(EMPTY_BUFFER);
|
|
69
|
+
}
|
|
70
|
+
else if (this.buffers.length === 1) {
|
|
71
|
+
return new DynamicBuffer(this.buffers[0].subarray(start, end));
|
|
72
|
+
}
|
|
73
|
+
let length = end - start;
|
|
74
|
+
let [startBuffer, current] = this.#findInitialBuffer(start);
|
|
75
|
+
start = startBuffer;
|
|
76
|
+
// The slice is in a single buffer
|
|
77
|
+
if (length <= this.buffers[current].length - start) {
|
|
78
|
+
return new DynamicBuffer(this.buffers[current].subarray(start, start + length));
|
|
79
|
+
}
|
|
80
|
+
// Copy all subarrays
|
|
81
|
+
const buffers = [];
|
|
82
|
+
while (length > 0) {
|
|
83
|
+
const currentEnd = Math.min(this.buffers[current].length - start, length);
|
|
84
|
+
buffers.push(this.buffers[current].subarray(start, start + currentEnd));
|
|
85
|
+
length -= currentEnd;
|
|
86
|
+
start = 0;
|
|
87
|
+
current++;
|
|
88
|
+
}
|
|
89
|
+
return new DynamicBuffer(buffers);
|
|
90
|
+
}
|
|
91
|
+
slice(start = 0, end) {
|
|
92
|
+
if (typeof end === 'undefined') {
|
|
93
|
+
end = this.length;
|
|
94
|
+
}
|
|
95
|
+
if (start < 0 || start > this.length || end > this.length) {
|
|
96
|
+
throw new UserError('Out of bounds.');
|
|
97
|
+
}
|
|
98
|
+
if (this.buffers.length === 0) {
|
|
99
|
+
return EMPTY_BUFFER;
|
|
100
|
+
}
|
|
101
|
+
else if (this.buffers.length === 1) {
|
|
102
|
+
return this.buffers[0].slice(start, end);
|
|
103
|
+
}
|
|
104
|
+
let position = 0;
|
|
105
|
+
let length = end - start;
|
|
106
|
+
let [startBuffer, current] = this.#findInitialBuffer(start);
|
|
107
|
+
start = startBuffer;
|
|
108
|
+
// The slice is in a single buffer
|
|
109
|
+
if (length <= this.buffers[current].length - start) {
|
|
110
|
+
return this.buffers[current].slice(start, start + length);
|
|
111
|
+
}
|
|
112
|
+
// Copy all buffers
|
|
113
|
+
const buffer = Buffer.allocUnsafe(length);
|
|
114
|
+
while (length > 0) {
|
|
115
|
+
const currentEnd = Math.min(this.buffers[current].length - start, length);
|
|
116
|
+
this.buffers[current].copy(buffer, position, start, start + currentEnd);
|
|
117
|
+
position += currentEnd;
|
|
118
|
+
length -= currentEnd;
|
|
119
|
+
start = 0;
|
|
120
|
+
current++;
|
|
121
|
+
}
|
|
122
|
+
return buffer;
|
|
123
|
+
}
|
|
124
|
+
clone(deep = false) {
|
|
125
|
+
if (!deep) {
|
|
126
|
+
return new DynamicBuffer(this.buffers);
|
|
127
|
+
}
|
|
128
|
+
const buffers = [];
|
|
129
|
+
for (const buffer of this.buffers) {
|
|
130
|
+
buffers.push(buffer.slice());
|
|
131
|
+
}
|
|
132
|
+
return new DynamicBuffer(buffers);
|
|
133
|
+
}
|
|
134
|
+
consume(offset) {
|
|
135
|
+
if (offset < 0 || offset > this.length) {
|
|
136
|
+
throw new UserError('Out of bounds.');
|
|
137
|
+
}
|
|
138
|
+
if (offset === 0) {
|
|
139
|
+
return this;
|
|
140
|
+
}
|
|
141
|
+
const [start, current] = this.#findInitialBuffer(offset);
|
|
142
|
+
// Remove other arrays
|
|
143
|
+
if (current > 0) {
|
|
144
|
+
this.buffers.splice(0, current);
|
|
145
|
+
}
|
|
146
|
+
// Trim the new first array
|
|
147
|
+
if (start > 0) {
|
|
148
|
+
this.buffers[0] = this.buffers[0].subarray(start);
|
|
149
|
+
}
|
|
150
|
+
// Compute length again
|
|
151
|
+
this.length = 0;
|
|
152
|
+
for (const buffer of this.buffers) {
|
|
153
|
+
this.length += buffer.length;
|
|
154
|
+
}
|
|
155
|
+
return this;
|
|
156
|
+
}
|
|
157
|
+
toString(encoding = 'utf-8', start = 0, end) {
|
|
158
|
+
return this.slice(start, end).toString(encoding);
|
|
159
|
+
}
|
|
160
|
+
get(offset) {
|
|
161
|
+
if (offset < 0 || offset >= this.length) {
|
|
162
|
+
throw new UserError('Out of bounds.');
|
|
163
|
+
}
|
|
164
|
+
const [finalIndex, current] = this.#findInitialBuffer(offset);
|
|
165
|
+
return this.buffers[current][finalIndex];
|
|
166
|
+
}
|
|
167
|
+
readUInt8(offset = 0) {
|
|
168
|
+
if (offset < 0 || offset >= this.length) {
|
|
169
|
+
throw new UserError('Out of bounds.');
|
|
170
|
+
}
|
|
171
|
+
const [finalIndex, current] = this.#findInitialBuffer(offset);
|
|
172
|
+
this.#readBuffer[0] = this.buffers[current][finalIndex];
|
|
173
|
+
return this.#readBuffer.readUInt8(0);
|
|
174
|
+
}
|
|
175
|
+
readUInt16BE(offset = 0) {
|
|
176
|
+
this.#readMultiple(offset, 2);
|
|
177
|
+
return this.#readBuffer.readUInt16BE(0);
|
|
178
|
+
}
|
|
179
|
+
readUInt16LE(offset = 0) {
|
|
180
|
+
this.#readMultiple(offset, 2);
|
|
181
|
+
return this.#readBuffer.readUInt16LE(0);
|
|
182
|
+
}
|
|
183
|
+
readUInt32BE(offset = 0) {
|
|
184
|
+
this.#readMultiple(offset, 4);
|
|
185
|
+
return this.#readBuffer.readUInt32BE(0);
|
|
186
|
+
}
|
|
187
|
+
readUInt32LE(offset = 0) {
|
|
188
|
+
this.#readMultiple(offset, 4);
|
|
189
|
+
return this.#readBuffer.readUInt32LE(0);
|
|
190
|
+
}
|
|
191
|
+
readBigUInt64BE(offset = 0) {
|
|
192
|
+
this.#readMultiple(offset, 8);
|
|
193
|
+
return this.#readBuffer.readBigUInt64BE(0);
|
|
194
|
+
}
|
|
195
|
+
readBigUInt64LE(offset = 0) {
|
|
196
|
+
this.#readMultiple(offset, 8);
|
|
197
|
+
return this.#readBuffer.readBigUInt64LE(0);
|
|
198
|
+
}
|
|
199
|
+
readUnsignedVarInt(offset) {
|
|
200
|
+
let i = 0;
|
|
201
|
+
let byte;
|
|
202
|
+
let value = 0;
|
|
203
|
+
let read = 0;
|
|
204
|
+
if (offset < 0 || offset >= this.length) {
|
|
205
|
+
throw new UserError('Out of bounds.');
|
|
206
|
+
}
|
|
207
|
+
// Find the initial buffer
|
|
208
|
+
let [startOffset, current] = this.#findInitialBuffer(offset);
|
|
209
|
+
do {
|
|
210
|
+
byte = this.buffers[current][startOffset++];
|
|
211
|
+
read++;
|
|
212
|
+
if (startOffset >= this.buffers[current].length) {
|
|
213
|
+
current++;
|
|
214
|
+
startOffset = 0;
|
|
215
|
+
}
|
|
216
|
+
value += (byte & LEAST_SIGNIFICANT_7_BITS) << i;
|
|
217
|
+
i += 7;
|
|
218
|
+
} while (byte >= MOST_SIGNIFICANT_BIT_FLAG);
|
|
219
|
+
return [value, read];
|
|
220
|
+
}
|
|
221
|
+
readUnsignedVarInt64(offset) {
|
|
222
|
+
let i = 0n;
|
|
223
|
+
let byte;
|
|
224
|
+
let value = 0n;
|
|
225
|
+
let read = 0;
|
|
226
|
+
if (offset < 0 || offset >= this.length) {
|
|
227
|
+
throw new UserError('Out of bounds.');
|
|
228
|
+
}
|
|
229
|
+
// Find the initial buffer
|
|
230
|
+
let [startOffset, current] = this.#findInitialBuffer(offset);
|
|
231
|
+
do {
|
|
232
|
+
byte = BigInt(this.buffers[current][startOffset++]);
|
|
233
|
+
read++;
|
|
234
|
+
if (startOffset >= this.buffers[current].length) {
|
|
235
|
+
current++;
|
|
236
|
+
startOffset = 0;
|
|
237
|
+
}
|
|
238
|
+
value += (byte & LEAST_SIGNIFICANT_7_BITS_64) << i;
|
|
239
|
+
i += 7n;
|
|
240
|
+
} while (byte >= MOST_SIGNIFICANT_BIT_FLAG_64);
|
|
241
|
+
return [value, read];
|
|
242
|
+
}
|
|
243
|
+
readInt8(offset = 0) {
|
|
244
|
+
if (offset < 0 || offset >= this.length) {
|
|
245
|
+
throw new UserError('Out of bounds.');
|
|
246
|
+
}
|
|
247
|
+
const [finalIndex, current] = this.#findInitialBuffer(offset);
|
|
248
|
+
this.#readBuffer[0] = this.buffers[current][finalIndex];
|
|
249
|
+
return this.#readBuffer.readInt8(0);
|
|
250
|
+
}
|
|
251
|
+
readInt16BE(offset = 0) {
|
|
252
|
+
this.#readMultiple(offset, INT16_SIZE);
|
|
253
|
+
return this.#readBuffer.readInt16BE(0);
|
|
254
|
+
}
|
|
255
|
+
readInt16LE(offset = 0) {
|
|
256
|
+
this.#readMultiple(offset, INT16_SIZE);
|
|
257
|
+
return this.#readBuffer.readInt16LE(0);
|
|
258
|
+
}
|
|
259
|
+
readInt32BE(offset = 0) {
|
|
260
|
+
this.#readMultiple(offset, INT32_SIZE);
|
|
261
|
+
return this.#readBuffer.readInt32BE(0);
|
|
262
|
+
}
|
|
263
|
+
readInt32LE(offset = 0) {
|
|
264
|
+
this.#readMultiple(offset, INT32_SIZE);
|
|
265
|
+
return this.#readBuffer.readInt32LE(0);
|
|
266
|
+
}
|
|
267
|
+
readBigInt64BE(offset = 0) {
|
|
268
|
+
this.#readMultiple(offset, INT64_SIZE);
|
|
269
|
+
return this.#readBuffer.readBigInt64BE(0);
|
|
270
|
+
}
|
|
271
|
+
readBigInt64LE(offset = 0) {
|
|
272
|
+
this.#readMultiple(offset, INT64_SIZE);
|
|
273
|
+
return this.#readBuffer.readBigInt64LE(0);
|
|
274
|
+
}
|
|
275
|
+
readVarInt(offset) {
|
|
276
|
+
const [value, read] = this.readUnsignedVarInt(offset);
|
|
277
|
+
return [intZigZagDecode(value), read];
|
|
278
|
+
}
|
|
279
|
+
readVarInt64(offset) {
|
|
280
|
+
const [value, read] = this.readUnsignedVarInt64(offset);
|
|
281
|
+
return [int64ZigZagDecode(value), read];
|
|
282
|
+
}
|
|
283
|
+
readFloatBE(offset = 0) {
|
|
284
|
+
this.#readMultiple(offset, INT32_SIZE);
|
|
285
|
+
return this.#readBuffer.readFloatBE(0);
|
|
286
|
+
}
|
|
287
|
+
readFloatLE(offset = 0) {
|
|
288
|
+
this.#readMultiple(offset, INT32_SIZE);
|
|
289
|
+
return this.#readBuffer.readFloatLE(0);
|
|
290
|
+
}
|
|
291
|
+
readDoubleBE(offset = 0) {
|
|
292
|
+
this.#readMultiple(offset, INT64_SIZE);
|
|
293
|
+
return this.#readBuffer.readDoubleBE(0);
|
|
294
|
+
}
|
|
295
|
+
readDoubleLE(offset = 0) {
|
|
296
|
+
this.#readMultiple(offset, INT64_SIZE);
|
|
297
|
+
return this.#readBuffer.readDoubleLE(0);
|
|
298
|
+
}
|
|
299
|
+
writeUInt8(value, append = true) {
|
|
300
|
+
const buffer = Buffer.allocUnsafe(INT8_SIZE);
|
|
301
|
+
buffer.writeUInt8(value);
|
|
302
|
+
if (append) {
|
|
303
|
+
this.append(buffer);
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
this.prepend(buffer);
|
|
307
|
+
}
|
|
308
|
+
return this;
|
|
309
|
+
}
|
|
310
|
+
writeUInt16BE(value, append = true) {
|
|
311
|
+
const buffer = Buffer.allocUnsafe(INT16_SIZE);
|
|
312
|
+
buffer.writeUInt16BE(value);
|
|
313
|
+
if (append) {
|
|
314
|
+
this.append(buffer);
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
this.prepend(buffer);
|
|
318
|
+
}
|
|
319
|
+
return this;
|
|
320
|
+
}
|
|
321
|
+
writeUInt16LE(value, append = true) {
|
|
322
|
+
const buffer = Buffer.allocUnsafe(INT16_SIZE);
|
|
323
|
+
buffer.writeUInt16LE(value);
|
|
324
|
+
if (append) {
|
|
325
|
+
this.append(buffer);
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
this.prepend(buffer);
|
|
329
|
+
}
|
|
330
|
+
return this;
|
|
331
|
+
}
|
|
332
|
+
writeUInt32BE(value, append = true) {
|
|
333
|
+
const buffer = Buffer.allocUnsafe(INT32_SIZE);
|
|
334
|
+
buffer.writeUInt32BE(value);
|
|
335
|
+
if (append) {
|
|
336
|
+
this.append(buffer);
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
this.prepend(buffer);
|
|
340
|
+
}
|
|
341
|
+
return this;
|
|
342
|
+
}
|
|
343
|
+
writeUInt32LE(value, append = true) {
|
|
344
|
+
const buffer = Buffer.allocUnsafe(INT32_SIZE);
|
|
345
|
+
buffer.writeUInt32LE(value);
|
|
346
|
+
if (append) {
|
|
347
|
+
this.append(buffer);
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
this.prepend(buffer);
|
|
351
|
+
}
|
|
352
|
+
return this;
|
|
353
|
+
}
|
|
354
|
+
writeBigUInt64BE(value, append = true) {
|
|
355
|
+
const buffer = Buffer.allocUnsafe(INT64_SIZE);
|
|
356
|
+
buffer.writeBigUInt64BE(value);
|
|
357
|
+
if (append) {
|
|
358
|
+
this.append(buffer);
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
this.prepend(buffer);
|
|
362
|
+
}
|
|
363
|
+
return this;
|
|
364
|
+
}
|
|
365
|
+
writeBigUInt64LE(value, append = true) {
|
|
366
|
+
const buffer = Buffer.allocUnsafe(INT64_SIZE);
|
|
367
|
+
buffer.writeBigUInt64LE(value);
|
|
368
|
+
if (append) {
|
|
369
|
+
this.append(buffer);
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
this.prepend(buffer);
|
|
373
|
+
}
|
|
374
|
+
return this;
|
|
375
|
+
}
|
|
376
|
+
writeUnsignedVarInt(value, append = true) {
|
|
377
|
+
const buffer = Buffer.alloc(sizeOfUnsignedVarInt(value));
|
|
378
|
+
let position = 0;
|
|
379
|
+
while ((value & BITS_8PLUS_MASK) !== 0) {
|
|
380
|
+
buffer.writeUInt8((value & LEAST_SIGNIFICANT_7_BITS) | MOST_SIGNIFICANT_BIT_FLAG, position);
|
|
381
|
+
position++;
|
|
382
|
+
value >>>= 7;
|
|
383
|
+
}
|
|
384
|
+
buffer.writeUInt8(value & LEAST_SIGNIFICANT_7_BITS, position);
|
|
385
|
+
if (append) {
|
|
386
|
+
this.append(buffer);
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
this.prepend(buffer);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
writeUnsignedVarInt64(value, append = true) {
|
|
393
|
+
const buffer = Buffer.alloc(sizeOfUnsignedVarInt64(value));
|
|
394
|
+
let position = 0;
|
|
395
|
+
while ((value & BITS_8PLUS_MASK_64) !== 0n) {
|
|
396
|
+
buffer.writeUInt8(Number((value & LEAST_SIGNIFICANT_7_BITS_64) | MOST_SIGNIFICANT_BIT_FLAG_64), position);
|
|
397
|
+
position++;
|
|
398
|
+
value >>= 7n;
|
|
399
|
+
}
|
|
400
|
+
buffer.writeUInt8(Number(value & LEAST_SIGNIFICANT_7_BITS_64), position);
|
|
401
|
+
if (append) {
|
|
402
|
+
this.append(buffer);
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
this.prepend(buffer);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
writeInt8(value, append = true) {
|
|
409
|
+
const buffer = Buffer.allocUnsafe(INT8_SIZE);
|
|
410
|
+
buffer.writeInt8(value);
|
|
411
|
+
if (append) {
|
|
412
|
+
this.append(buffer);
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
this.prepend(buffer);
|
|
416
|
+
}
|
|
417
|
+
return this;
|
|
418
|
+
}
|
|
419
|
+
writeInt16BE(value, append = true) {
|
|
420
|
+
const buffer = Buffer.allocUnsafe(INT16_SIZE);
|
|
421
|
+
buffer.writeInt16BE(value);
|
|
422
|
+
if (append) {
|
|
423
|
+
this.append(buffer);
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
this.prepend(buffer);
|
|
427
|
+
}
|
|
428
|
+
return this;
|
|
429
|
+
}
|
|
430
|
+
writeInt16LE(value, append = true) {
|
|
431
|
+
const buffer = Buffer.allocUnsafe(INT16_SIZE);
|
|
432
|
+
buffer.writeInt16LE(value);
|
|
433
|
+
if (append) {
|
|
434
|
+
this.append(buffer);
|
|
435
|
+
}
|
|
436
|
+
else {
|
|
437
|
+
this.prepend(buffer);
|
|
438
|
+
}
|
|
439
|
+
return this;
|
|
440
|
+
}
|
|
441
|
+
writeInt32BE(value, append = true) {
|
|
442
|
+
const buffer = Buffer.allocUnsafe(INT32_SIZE);
|
|
443
|
+
buffer.writeInt32BE(value);
|
|
444
|
+
if (append) {
|
|
445
|
+
this.append(buffer);
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
this.prepend(buffer);
|
|
449
|
+
}
|
|
450
|
+
return this;
|
|
451
|
+
}
|
|
452
|
+
writeInt32LE(value, append = true) {
|
|
453
|
+
const buffer = Buffer.allocUnsafe(INT32_SIZE);
|
|
454
|
+
buffer.writeInt32LE(value);
|
|
455
|
+
if (append) {
|
|
456
|
+
this.append(buffer);
|
|
457
|
+
}
|
|
458
|
+
else {
|
|
459
|
+
this.prepend(buffer);
|
|
460
|
+
}
|
|
461
|
+
return this;
|
|
462
|
+
}
|
|
463
|
+
writeBigInt64BE(value, append = true) {
|
|
464
|
+
const buffer = Buffer.allocUnsafe(INT64_SIZE);
|
|
465
|
+
buffer.writeBigInt64BE(value);
|
|
466
|
+
if (append) {
|
|
467
|
+
this.append(buffer);
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
this.prepend(buffer);
|
|
471
|
+
}
|
|
472
|
+
return this;
|
|
473
|
+
}
|
|
474
|
+
writeBigInt64LE(value, append = true) {
|
|
475
|
+
const buffer = Buffer.allocUnsafe(INT64_SIZE);
|
|
476
|
+
buffer.writeBigInt64LE(value);
|
|
477
|
+
if (append) {
|
|
478
|
+
this.append(buffer);
|
|
479
|
+
}
|
|
480
|
+
else {
|
|
481
|
+
this.prepend(buffer);
|
|
482
|
+
}
|
|
483
|
+
return this;
|
|
484
|
+
}
|
|
485
|
+
writeVarInt(value, append = true) {
|
|
486
|
+
this.writeUnsignedVarInt(intZigZagEncode(value), append);
|
|
487
|
+
}
|
|
488
|
+
writeVarInt64(value, append = true) {
|
|
489
|
+
this.writeUnsignedVarInt64(int64ZigZagEncode(value), append);
|
|
490
|
+
}
|
|
491
|
+
writeFloatBE(value, append = true) {
|
|
492
|
+
const buffer = Buffer.allocUnsafe(INT32_SIZE);
|
|
493
|
+
buffer.writeFloatBE(value);
|
|
494
|
+
if (append) {
|
|
495
|
+
this.append(buffer);
|
|
496
|
+
}
|
|
497
|
+
else {
|
|
498
|
+
this.prepend(buffer);
|
|
499
|
+
}
|
|
500
|
+
return this;
|
|
501
|
+
}
|
|
502
|
+
writeFloatLE(value, append = true) {
|
|
503
|
+
const buffer = Buffer.allocUnsafe(INT32_SIZE);
|
|
504
|
+
buffer.writeFloatLE(value);
|
|
505
|
+
if (append) {
|
|
506
|
+
this.append(buffer);
|
|
507
|
+
}
|
|
508
|
+
else {
|
|
509
|
+
this.prepend(buffer);
|
|
510
|
+
}
|
|
511
|
+
return this;
|
|
512
|
+
}
|
|
513
|
+
writeDoubleBE(value, append = true) {
|
|
514
|
+
const buffer = Buffer.allocUnsafe(INT64_SIZE);
|
|
515
|
+
buffer.writeDoubleBE(value);
|
|
516
|
+
if (append) {
|
|
517
|
+
this.append(buffer);
|
|
518
|
+
}
|
|
519
|
+
else {
|
|
520
|
+
this.prepend(buffer);
|
|
521
|
+
}
|
|
522
|
+
return this;
|
|
523
|
+
}
|
|
524
|
+
writeDoubleLE(value, append = true) {
|
|
525
|
+
const buffer = Buffer.allocUnsafe(INT64_SIZE);
|
|
526
|
+
buffer.writeDoubleLE(value);
|
|
527
|
+
if (append) {
|
|
528
|
+
this.append(buffer);
|
|
529
|
+
}
|
|
530
|
+
else {
|
|
531
|
+
this.prepend(buffer);
|
|
532
|
+
}
|
|
533
|
+
return this;
|
|
534
|
+
}
|
|
535
|
+
#findInitialBuffer(start) {
|
|
536
|
+
let current = 0;
|
|
537
|
+
// Find the initial buffer
|
|
538
|
+
while (start > 0 && start >= this.buffers[current].length) {
|
|
539
|
+
start -= this.buffers[current].length;
|
|
540
|
+
current++;
|
|
541
|
+
}
|
|
542
|
+
return [start, current];
|
|
543
|
+
}
|
|
544
|
+
#readMultiple(index, length) {
|
|
545
|
+
if (index < 0 || index + length > this.length) {
|
|
546
|
+
throw new UserError('Out of bounds.');
|
|
547
|
+
}
|
|
548
|
+
let [startOffset, current] = this.#findInitialBuffer(index);
|
|
549
|
+
for (let i = 0; i < length; i++) {
|
|
550
|
+
this.#readBuffer[i] = this.buffers[current][startOffset++];
|
|
551
|
+
if (startOffset === this.buffers[current].length) {
|
|
552
|
+
current++;
|
|
553
|
+
startOffset = 0;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface ProtocolErrorDefinition {
|
|
2
|
+
id: string;
|
|
3
|
+
code: number;
|
|
4
|
+
canRetry: boolean;
|
|
5
|
+
message: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const protocolErrorsCodesById: Record<number, string>;
|
|
8
|
+
export declare const protocolErrors: Record<string, ProtocolErrorDefinition>;
|