nodejs-insta-private-api-mqt 1.3.73 → 1.3.74

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.
@@ -3,340 +3,394 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BufferWriter = exports.thriftWriteFromObject = void 0;
4
4
  const thrift_1 = require("./thrift");
5
5
  const errors_1 = require("../errors");
6
+
7
+ /**
8
+ * Thrift Compact Protocol writer (subset) optimized for MQTT-over-Thrift payloads.
9
+ * Improvements vs old version:
10
+ * - avoids Buffer.concat per write (uses chunk list + lazy concat)
11
+ * - faster descriptor lookup via Map
12
+ * - more flexible INT_64 input (number|bigint|string|{int}|Long-like)
13
+ */
14
+
6
15
  function thriftWriteFromObject(obj, descriptors) {
7
- const writer = BufferWriter.empty();
8
- thriftWriteSingleLayerFromObject(obj, descriptors, writer);
9
- writer.writeStop();
10
- return writer.buffer;
16
+ const writer = BufferWriter.empty();
17
+ thriftWriteSingleLayerFromObject(obj, descriptors, writer);
18
+ writer.writeStop();
19
+ return writer.buffer;
11
20
  }
12
21
  exports.thriftWriteFromObject = thriftWriteFromObject;
22
+
23
+ function buildDescriptorMap(descriptors) {
24
+ const map = new Map();
25
+ for (const d of descriptors) map.set(d.fieldName, d);
26
+ return map;
27
+ }
28
+
29
+ function normalizeInt64(v, nameForError) {
30
+ if (typeof v === "bigint") return v;
31
+ if (typeof v === "number") return BigInt(v);
32
+ if (typeof v === "string") return BigInt(v);
33
+ if (v && typeof v === "object") {
34
+ if (typeof v.int === "bigint") return v.int; // our reader shape
35
+ if (typeof v.toString === "function") return BigInt(v.toString());
36
+ }
37
+ throw new errors_1.IllegalArgumentError(`Value of ${nameForError} is neither a bigint nor a number/string`);
38
+ }
39
+
13
40
  function thriftWriteSingleLayerFromObject(obj, descriptors, writer) {
14
- const entries = Object.entries(obj);
15
- for (const entry of entries) {
16
- const name = entry[0];
17
- const value = entry[1];
18
- if (typeof value === 'undefined')
19
- continue;
20
- const descriptor = descriptors.find(d => d.fieldName === name);
21
- if (!descriptor)
22
- throw new errors_1.IllegalArgumentError(`Descriptor for ${name} not found`);
23
- switch (descriptor.type & 0xff) {
24
- case thrift_1.ThriftTypes.BOOLEAN:
25
- case thrift_1.ThriftTypes.TRUE:
26
- case thrift_1.ThriftTypes.FALSE: {
27
- writer.writeBoolean(descriptor.field, !!value);
28
- break;
29
- }
30
- case thrift_1.ThriftTypes.BYTE: {
31
- if (typeof value === 'number') {
32
- writer.writeInt8(descriptor.field, value);
33
- }
34
- else {
35
- throw new errors_1.IllegalArgumentError(`Value of ${name} is not a number`);
36
- }
37
- break;
38
- }
39
- case thrift_1.ThriftTypes.INT_16: {
40
- if (typeof value === 'number') {
41
- writer.writeInt16(descriptor.field, value);
42
- }
43
- else {
44
- throw new errors_1.IllegalArgumentError(`Value of ${name} is not a number`);
45
- }
46
- break;
47
- }
48
- case thrift_1.ThriftTypes.INT_32: {
49
- if (typeof value === 'number') {
50
- writer.writeInt32(descriptor.field, value);
51
- }
52
- else {
53
- throw new errors_1.IllegalArgumentError(`Value of ${name} is not a number`);
54
- }
55
- break;
56
- }
57
- case thrift_1.ThriftTypes.INT_64: {
58
- if (typeof value === 'number') {
59
- writer.writeInt64Buffer(descriptor.field, BigInt(value));
60
- }
61
- else if (typeof value === 'bigint') {
62
- writer.writeInt64Buffer(descriptor.field, value);
63
- }
64
- else {
65
- throw new errors_1.IllegalArgumentError(`Value of ${name} is neither a bigint nor a number`);
66
- }
67
- break;
68
- }
69
- case thrift_1.ThriftTypes.LIST: {
70
- // @ts-ignore
71
- writer.writeList(descriptor.field, descriptor.type >> 8, value);
72
- break;
73
- }
74
- case thrift_1.ThriftTypes.STRUCT: {
75
- writer.writeStruct(descriptor.field);
76
- thriftWriteSingleLayerFromObject(value, descriptor.structDescriptors ?? [], writer);
77
- writer.writeStop();
78
- break;
79
- }
80
- case thrift_1.ThriftTypes.BINARY: {
81
- if (typeof value === 'string') {
82
- writer.writeString(descriptor.field, value);
83
- }
84
- else {
85
- throw new errors_1.IllegalArgumentError(`Value of ${name} is not a string`);
86
- }
87
- break;
88
- }
89
- case thrift_1.ThriftTypes.MAP: {
90
- if (descriptor.type === thrift_1.ThriftTypes.MAP_BINARY_BINARY) {
91
- let pairs;
92
- if (Array.isArray(value)) {
93
- //[{key: 'a', value: 'b'}]
94
- pairs = value.map((x) => [x.key, x.value]);
95
- }
96
- else {
97
- // {a: 'b'}
98
- pairs = Object.entries(value);
99
- }
100
- writer.writeMapHeader(descriptor.field, pairs.length, thrift_1.ThriftTypes.BINARY, thrift_1.ThriftTypes.BINARY);
101
- if (pairs.length !== 0) {
102
- for (const pair of pairs) {
103
- writer.writeStringDirect(pair[0]).writeStringDirect(pair[1]);
104
- }
105
- }
106
- }
107
- else {
108
- throw new errors_1.ThriftError(`Map of type ${descriptor.type} not impl.`);
109
- }
110
- break;
111
- }
112
- default: {
113
- throw new errors_1.ThriftError(`Could not find type ${descriptor.type} for ${name}`);
114
- }
41
+ const descriptorMap = buildDescriptorMap(descriptors);
42
+ const entries = Object.entries(obj);
43
+
44
+ for (const [name, value] of entries) {
45
+ if (typeof value === "undefined") continue;
46
+
47
+ const descriptor = descriptorMap.get(name);
48
+ if (!descriptor) throw new errors_1.IllegalArgumentError(`Descriptor for ${name} not found`);
49
+
50
+ switch (descriptor.type & 0xff) {
51
+ case thrift_1.ThriftTypes.BOOLEAN:
52
+ case thrift_1.ThriftTypes.TRUE:
53
+ case thrift_1.ThriftTypes.FALSE: {
54
+ writer.writeBoolean(descriptor.field, !!value);
55
+ break;
56
+ }
57
+ case thrift_1.ThriftTypes.BYTE: {
58
+ if (typeof value === "number") writer.writeInt8(descriptor.field, value);
59
+ else throw new errors_1.IllegalArgumentError(`Value of ${name} is not a number`);
60
+ break;
61
+ }
62
+ case thrift_1.ThriftTypes.INT_16: {
63
+ if (typeof value === "number") writer.writeInt16(descriptor.field, value);
64
+ else throw new errors_1.IllegalArgumentError(`Value of ${name} is not a number`);
65
+ break;
66
+ }
67
+ case thrift_1.ThriftTypes.INT_32: {
68
+ if (typeof value === "number") writer.writeInt32(descriptor.field, value);
69
+ else throw new errors_1.IllegalArgumentError(`Value of ${name} is not a number`);
70
+ break;
71
+ }
72
+ case thrift_1.ThriftTypes.INT_64: {
73
+ writer.writeInt64Buffer(descriptor.field, normalizeInt64(value, name));
74
+ break;
75
+ }
76
+ case thrift_1.ThriftTypes.LIST: {
77
+ // packed list type is stored in high byte (descriptor.type >> 8)
78
+ // @ts-ignore
79
+ writer.writeList(descriptor.field, descriptor.type >> 8, value);
80
+ break;
81
+ }
82
+ case thrift_1.ThriftTypes.STRUCT: {
83
+ writer.writeStruct(descriptor.field);
84
+ thriftWriteSingleLayerFromObject(value, descriptor.structDescriptors ?? [], writer);
85
+ writer.writeStop();
86
+ break;
87
+ }
88
+ case thrift_1.ThriftTypes.BINARY: {
89
+ if (typeof value === "string") writer.writeString(descriptor.field, value);
90
+ else throw new errors_1.IllegalArgumentError(`Value of ${name} is not a string`);
91
+ break;
92
+ }
93
+ case thrift_1.ThriftTypes.MAP: {
94
+ if (descriptor.type === thrift_1.ThriftTypes.MAP_BINARY_BINARY) {
95
+ let pairs;
96
+ if (Array.isArray(value)) {
97
+ // [{key:'a', value:'b'}]
98
+ pairs = value.map((x) => [x.key, x.value]);
99
+ } else {
100
+ // {a:'b'}
101
+ pairs = Object.entries(value);
102
+ }
103
+ writer.writeMapHeader(descriptor.field, pairs.length, thrift_1.ThriftTypes.BINARY, thrift_1.ThriftTypes.BINARY);
104
+ if (pairs.length !== 0) {
105
+ for (const [k, v] of pairs) writer.writeStringDirect(k).writeStringDirect(v);
106
+ }
107
+ } else {
108
+ throw new errors_1.ThriftError(`Map of type ${descriptor.type} not impl.`);
115
109
  }
110
+ break;
111
+ }
112
+ default: {
113
+ throw new errors_1.ThriftError(`Could not find type ${descriptor.type} for ${name}`);
114
+ }
116
115
  }
116
+ }
117
117
  }
118
+
118
119
  class BufferWriter {
119
- get buffer() {
120
- return this._buffer;
121
- }
122
- get position() {
123
- return this._position;
124
- }
125
- get length() {
126
- return this._buffer.length;
127
- }
128
- get field() {
129
- return this._field;
130
- }
131
- get stack() {
132
- return this._stack;
133
- }
134
- constructor(data, length, buffer) {
135
- this._position = 0;
136
- this._field = 0;
137
- this._stack = [];
138
- this._buffer = data ? Buffer.from(data) : length ? Buffer.alloc(length) : buffer ? buffer : Buffer.from([]);
139
- this._position = 0;
140
- }
141
- static fromLength(len) {
142
- return new BufferWriter(undefined, len, undefined);
143
- }
144
- static fromBuffer(buf) {
145
- return new BufferWriter(undefined, undefined, buf);
146
- }
147
- static fromString(data) {
148
- return new BufferWriter(data, undefined, undefined);
149
- }
150
- static empty() {
151
- return new BufferWriter(undefined, undefined, undefined);
152
- }
153
- move(bytes) {
154
- this._position = this._position + bytes;
155
- return this._position - bytes;
156
- }
157
- writeVarInt(num) {
158
- while (true) {
159
- let byte = num & ~0x7f;
160
- if (byte === 0) {
161
- this.writeByte(num);
162
- break;
163
- }
164
- else if (byte === -128) {
165
- // -128 = 0b1000_0000 but it's the last an no other bytes will follow
166
- this.writeByte(0);
167
- break;
168
- }
169
- else {
170
- byte = (num & 0xff) | 0x80;
171
- this.writeByte(byte);
172
- num = num >> 7;
173
- }
174
- }
175
- return this;
176
- }
177
- writeField(field, type) {
178
- const delta = field - this.field;
179
- if (delta > 0 && delta <= 15) {
180
- this.writeByte((delta << 4) | type);
181
- }
182
- else {
183
- this.writeByte(type);
184
- this.writeWord(field);
185
- }
186
- this._field = field;
187
- return this;
188
- }
189
- writeBuffer(buf) {
190
- this._buffer = Buffer.concat([this._buffer, buf]);
191
- this.move(buf.length);
192
- return this;
193
- }
194
- writeByte(byte) {
195
- const buf = Buffer.alloc(1);
196
- buf.writeUInt8(byte, 0);
197
- this.writeBuffer(buf);
198
- return this;
199
- }
200
- writeWord(num) {
201
- return this.writeVarInt(BufferWriter.toZigZag(num, 0x10));
202
- }
203
- writeInt(num) {
204
- return this.writeVarInt(BufferWriter.toZigZag(num, 0x20));
205
- }
206
- writeLong(num) {
207
- if (typeof num === 'object') {
208
- num = num.int;
209
- }
210
- if (typeof num !== 'bigint') {
211
- num = BigInt(num);
212
- }
213
- this.writeBigint(BufferWriter.bigintToZigZag(num));
214
- return this;
215
- }
216
- writeBigint(n) {
217
- while (true) {
218
- if ((n & ~BigInt(0x7f)) === BigInt(0)) {
219
- this.writeByte(Number(n));
220
- break;
221
- }
222
- else {
223
- this.writeByte(Number((n & BigInt(0x7f)) | BigInt(0x80)));
224
- n = n >> BigInt(7);
225
- }
226
- }
227
- }
228
- writeMapHeader(field, size, keyType, valueType) {
229
- this.writeField(field, thrift_1.ThriftTypes.MAP);
230
- if (size === 0) {
231
- this.writeByte(0);
232
- }
233
- else {
234
- this.writeVarInt(size);
235
- this.writeByte(((keyType & 0xf) << 4) | (valueType & 0xf));
236
- }
237
- return this;
238
- }
239
- writeBoolean(field, bool) {
240
- return this.writeField(field, bool ? thrift_1.ThriftTypes.TRUE : thrift_1.ThriftTypes.FALSE);
241
- }
242
- writeString(field, s) {
243
- this.writeField(field, thrift_1.ThriftTypes.BINARY);
244
- return this.writeStringDirect(s);
245
- }
246
- writeStringDirect(s) {
247
- const buf = Buffer.from(s, 'utf8');
248
- this.writeVarInt(buf.length);
249
- this.writeBuffer(buf);
250
- return this;
251
- }
252
- writeStop() {
253
- this.writeByte(thrift_1.ThriftTypes.STOP);
254
- if (this.stack.length > 0) {
255
- this.popStack();
256
- }
257
- return this;
258
- }
259
- writeInt8(field, num) {
260
- this.writeField(field, thrift_1.ThriftTypes.BYTE);
261
- return this.writeByte(num);
262
- }
263
- writeInt16(field, num) {
264
- this.writeField(field, thrift_1.ThriftTypes.INT_16);
265
- return this.writeWord(num);
266
- }
267
- writeInt32(field, num) {
268
- this.writeField(field, thrift_1.ThriftTypes.INT_32);
269
- return this.writeInt(num);
270
- }
271
- writeInt64Buffer(field, num) {
272
- this.writeField(field, thrift_1.ThriftTypes.INT_64);
273
- return this.writeLong(num);
274
- }
275
- writeList(field, type, list) {
276
- this.writeField(field, thrift_1.ThriftTypes.LIST);
277
- const size = list.length;
278
- if (size < 0x0f) {
279
- this.writeByte((size << 4) | type);
280
- }
281
- else {
282
- this.writeByte(0xf0 | type);
283
- this.writeVarInt(size);
284
- }
285
- switch (type) {
286
- case thrift_1.ThriftTypes.TRUE:
287
- case thrift_1.ThriftTypes.FALSE: {
288
- list.forEach(el => this.writeByte(el ? thrift_1.ThriftTypes.TRUE : thrift_1.ThriftTypes.FALSE));
289
- break;
290
- }
291
- case thrift_1.ThriftTypes.BYTE: {
292
- list.forEach(el => this.writeByte(el));
293
- break;
294
- }
295
- case thrift_1.ThriftTypes.INT_16: {
296
- list.forEach(el => this.writeWord(el));
297
- break;
298
- }
299
- case thrift_1.ThriftTypes.INT_32: {
300
- list.forEach(el => this.writeInt(el));
301
- break;
302
- }
303
- case thrift_1.ThriftTypes.INT_64: {
304
- list.forEach(el => this.writeLong(BigInt(el)));
305
- break;
306
- }
307
- case thrift_1.ThriftTypes.BINARY: {
308
- list.forEach(el => {
309
- const buf = Buffer.from(el, 'utf8');
310
- this.writeVarInt(buf.length);
311
- this.writeBuffer(buf);
312
- });
313
- break;
314
- }
315
- default: {
316
- throw new errors_1.ThriftError('not impl');
317
- }
318
- }
319
- return this;
320
- }
321
- writeStruct(field) {
322
- this.writeField(field, thrift_1.ThriftTypes.STRUCT);
323
- this.pushStack();
324
- return this;
325
- }
326
- pushStack() {
327
- this._stack.push(this.field);
328
- this._field = 0;
329
- }
330
- popStack() {
331
- this._field = this._stack.pop() ?? -1;
332
- }
333
- toString() {
334
- return this._buffer.toString('ascii');
335
- }
336
- static bigintToZigZag(n) {
337
- return (n << BigInt(1)) ^ (n >> BigInt(63));
338
- }
120
+ get buffer() {
121
+ // Lazy concat: only when requested
122
+ if (this._dirty) {
123
+ this._buffer = Buffer.concat(this._chunks, this._length);
124
+ this._dirty = false;
125
+ // free chunks to reduce memory, keep single buffer from now on
126
+ this._chunks = [this._buffer];
127
+ }
128
+ return this._buffer;
129
+ }
130
+ get position() {
131
+ return this._position;
132
+ }
133
+ get length() {
134
+ return this._length;
135
+ }
136
+ get field() {
137
+ return this._field;
138
+ }
139
+ get stack() {
140
+ return this._stack;
141
+ }
142
+
143
+ constructor(data, length, buffer) {
144
+ this._position = 0;
145
+ this._field = 0;
146
+ this._stack = [];
147
+
148
+ // internal chunked buffer state
149
+ this._chunks = [];
150
+ this._length = 0;
151
+ this._dirty = true;
152
+
153
+ if (data) {
154
+ const b = Buffer.from(data);
155
+ this._chunks.push(b);
156
+ this._length = b.length;
157
+ this._buffer = b;
158
+ this._dirty = false;
159
+ } else if (typeof length === "number") {
160
+ // not used in current library, but keep for compatibility
161
+ const b = Buffer.alloc(length);
162
+ this._chunks.push(b);
163
+ this._length = b.length;
164
+ this._buffer = b;
165
+ this._dirty = false;
166
+ } else if (buffer) {
167
+ this._chunks.push(buffer);
168
+ this._length = buffer.length;
169
+ this._buffer = buffer;
170
+ this._dirty = false;
171
+ } else {
172
+ const b = Buffer.from([]);
173
+ this._chunks.push(b);
174
+ this._length = 0;
175
+ this._buffer = b;
176
+ this._dirty = false;
177
+ }
178
+ }
179
+
180
+ static fromLength(len) {
181
+ return new BufferWriter(undefined, len, undefined);
182
+ }
183
+ static fromBuffer(buf) {
184
+ return new BufferWriter(undefined, undefined, buf);
185
+ }
186
+ static fromString(data) {
187
+ return new BufferWriter(data, undefined, undefined);
188
+ }
189
+ static empty() {
190
+ return new BufferWriter(undefined, undefined, undefined);
191
+ }
192
+
193
+ move(bytes) {
194
+ this._position = this._position + bytes;
195
+ return this._position - bytes;
196
+ }
197
+
198
+ writeVarInt(num) {
199
+ // num is int32-ish here
200
+ while (true) {
201
+ let byte = num & ~0x7f;
202
+ if (byte === 0) {
203
+ this.writeByte(num);
204
+ break;
205
+ } else if (byte === -128) {
206
+ // -128 = 0b1000_0000 but it's the last and no other bytes will follow
207
+ this.writeByte(0);
208
+ break;
209
+ } else {
210
+ byte = (num & 0xff) | 0x80;
211
+ this.writeByte(byte);
212
+ num = num >> 7;
213
+ }
214
+ }
215
+ return this;
216
+ }
217
+
218
+ writeField(field, type) {
219
+ const delta = field - this.field;
220
+ if (delta > 0 && delta <= 15) {
221
+ this.writeByte((delta << 4) | type);
222
+ } else {
223
+ this.writeByte(type);
224
+ this.writeWord(field);
225
+ }
226
+ this._field = field;
227
+ return this;
228
+ }
229
+
230
+ writeBuffer(buf) {
231
+ // Chunk append (no concat)
232
+ if (!buf || buf.length === 0) return this;
233
+ this._chunks.push(buf);
234
+ this._length += buf.length;
235
+ this._dirty = true;
236
+ this.move(buf.length);
237
+ return this;
238
+ }
239
+
240
+ writeByte(byte) {
241
+ const b = Buffer.allocUnsafe(1);
242
+ b[0] = byte & 0xff;
243
+ return this.writeBuffer(b);
244
+ }
245
+
246
+ writeWord(num) {
247
+ return this.writeVarInt(BufferWriter.toZigZag(num, 0x10));
248
+ }
249
+ writeInt(num) {
250
+ return this.writeVarInt(BufferWriter.toZigZag(num, 0x20));
251
+ }
252
+
253
+ writeLong(num) {
254
+ if (typeof num === "object") num = num.int;
255
+ if (typeof num !== "bigint") num = BigInt(num);
256
+ this.writeBigint(BufferWriter.bigintToZigZag(num));
257
+ return this;
258
+ }
259
+
260
+ writeBigint(n) {
261
+ while (true) {
262
+ if ((n & ~BigInt(0x7f)) === BigInt(0)) {
263
+ this.writeByte(Number(n));
264
+ break;
265
+ } else {
266
+ this.writeByte(Number((n & BigInt(0x7f)) | BigInt(0x80)));
267
+ n = n >> BigInt(7);
268
+ }
269
+ }
270
+ }
271
+
272
+ writeMapHeader(field, size, keyType, valueType) {
273
+ this.writeField(field, thrift_1.ThriftTypes.MAP);
274
+ if (size === 0) {
275
+ this.writeByte(0);
276
+ } else {
277
+ this.writeVarInt(size);
278
+ this.writeByte(((keyType & 0xf) << 4) | (valueType & 0xf));
279
+ }
280
+ return this;
281
+ }
282
+
283
+ writeBoolean(field, bool) {
284
+ return this.writeField(field, bool ? thrift_1.ThriftTypes.TRUE : thrift_1.ThriftTypes.FALSE);
285
+ }
286
+
287
+ writeString(field, s) {
288
+ this.writeField(field, thrift_1.ThriftTypes.BINARY);
289
+ return this.writeStringDirect(s);
290
+ }
291
+
292
+ writeStringDirect(s) {
293
+ const buf = Buffer.from(s, "utf8");
294
+ this.writeVarInt(buf.length);
295
+ this.writeBuffer(buf);
296
+ return this;
297
+ }
298
+
299
+ writeStop() {
300
+ this.writeByte(thrift_1.ThriftTypes.STOP);
301
+ if (this.stack.length > 0) this.popStack();
302
+ return this;
303
+ }
304
+
305
+ writeInt8(field, num) {
306
+ this.writeField(field, thrift_1.ThriftTypes.BYTE);
307
+ return this.writeByte(num);
308
+ }
309
+ writeInt16(field, num) {
310
+ this.writeField(field, thrift_1.ThriftTypes.INT_16);
311
+ return this.writeWord(num);
312
+ }
313
+ writeInt32(field, num) {
314
+ this.writeField(field, thrift_1.ThriftTypes.INT_32);
315
+ return this.writeInt(num);
316
+ }
317
+ writeInt64Buffer(field, num) {
318
+ this.writeField(field, thrift_1.ThriftTypes.INT_64);
319
+ return this.writeLong(num);
320
+ }
321
+
322
+ writeList(field, type, list) {
323
+ this.writeField(field, thrift_1.ThriftTypes.LIST);
324
+ const size = list.length;
325
+
326
+ if (size < 0x0f) {
327
+ this.writeByte((size << 4) | type);
328
+ } else {
329
+ this.writeByte(0xf0 | type);
330
+ this.writeVarInt(size);
331
+ }
332
+
333
+ switch (type) {
334
+ case thrift_1.ThriftTypes.TRUE:
335
+ case thrift_1.ThriftTypes.FALSE: {
336
+ list.forEach((el) => this.writeByte(el ? thrift_1.ThriftTypes.TRUE : thrift_1.ThriftTypes.FALSE));
337
+ break;
338
+ }
339
+ case thrift_1.ThriftTypes.BYTE: {
340
+ list.forEach((el) => this.writeByte(el));
341
+ break;
342
+ }
343
+ case thrift_1.ThriftTypes.INT_16: {
344
+ list.forEach((el) => this.writeWord(el));
345
+ break;
346
+ }
347
+ case thrift_1.ThriftTypes.INT_32: {
348
+ list.forEach((el) => this.writeInt(el));
349
+ break;
350
+ }
351
+ case thrift_1.ThriftTypes.INT_64: {
352
+ list.forEach((el) => this.writeLong(normalizeInt64(el, "list<int64> item")));
353
+ break;
354
+ }
355
+ case thrift_1.ThriftTypes.BINARY: {
356
+ list.forEach((el) => {
357
+ const buf = Buffer.from(el, "utf8");
358
+ this.writeVarInt(buf.length);
359
+ this.writeBuffer(buf);
360
+ });
361
+ break;
362
+ }
363
+ default: {
364
+ throw new errors_1.ThriftError("not impl");
365
+ }
366
+ }
367
+
368
+ return this;
369
+ }
370
+
371
+ writeStruct(field) {
372
+ this.writeField(field, thrift_1.ThriftTypes.STRUCT);
373
+ this.pushStack();
374
+ return this;
375
+ }
376
+
377
+ pushStack() {
378
+ this._stack.push(this.field);
379
+ this._field = 0;
380
+ }
381
+ popStack() {
382
+ this._field = this._stack.pop() ?? -1;
383
+ }
384
+
385
+ toString() {
386
+ return this.buffer.toString("ascii");
387
+ }
388
+
389
+ static bigintToZigZag(n) {
390
+ return (n << BigInt(1)) ^ (n >> BigInt(63));
391
+ }
339
392
  }
340
393
  exports.BufferWriter = BufferWriter;
394
+
341
395
  BufferWriter.toZigZag = (n, bits) => (n << 1) ^ (n >> (bits - 1));
342
- //# sourceMappingURL=thrift.writing.js.map
396
+