@andrew_l/tl-pack 0.2.19 → 0.2.20

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/README.md CHANGED
@@ -35,9 +35,11 @@ writer.writeObject({
35
35
  uint8: 255,
36
36
  uint16: 256,
37
37
  uint32: 65536,
38
+ uint64: 2n ** 64n - 1n,
38
39
  int8: -128,
39
40
  int16: -32768,
40
41
  int32: -2147483648,
42
+ int64: -100n,
41
43
  double: 3.14,
42
44
  string: 'Hello world',
43
45
  vector: [1, 2, 3, 4, 5, { text: 'hi' }],
@@ -298,9 +300,11 @@ const SecureData = defineStructure({
298
300
  | Int8 | 1 |
299
301
  | Int16 | 2 |
300
302
  | Int32 | 4 |
303
+ | Int64 | 8 |
301
304
  | UInt8 | 1 |
302
305
  | UInt16 | 2 |
303
306
  | UInt32 | 4 |
307
+ | UInt64 | 8 |
304
308
  | Float | 4 |
305
309
  | Double | 8 |
306
310
  | Map | 2 + sizeof(object) |
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const BinaryReader = require('./shared/tl-pack.c8vOMguk.cjs');
3
+ const BinaryReader = require('./shared/tl-pack.BdWYOLsg.cjs');
4
4
  const toolkit = require('@andrew_l/toolkit');
5
5
  require('pako');
6
6
 
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { B as BinaryWriterOptions, a as BinaryReaderOptions } from './shared/tl-pack.DWKHpLIt.cjs';
2
- export { b as BinaryReader, c as BinaryWriter, C as CORE_TYPES, D as DecodeHandler, f as DefineStructureOptions, E as EncodeHandler, M as MAX_BUFFER_SIZE, S as Structure, T as TLExtension, d as createDictionary, e as createExtension, g as defineStructure } from './shared/tl-pack.DWKHpLIt.cjs';
1
+ import { B as BinaryWriterOptions, a as BinaryReaderOptions } from './shared/tl-pack.B7UgWY_K.cjs';
2
+ export { b as BinaryReader, c as BinaryWriter, C as CORE_TYPES, D as DecodeHandler, f as DefineStructureOptions, E as EncodeHandler, M as MAX_BUFFER_SIZE, S as Structure, T as TLExtension, d as createDictionary, e as createExtension, g as defineStructure } from './shared/tl-pack.B7UgWY_K.cjs';
3
3
  import '@andrew_l/toolkit';
4
4
 
5
5
  /**
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { B as BinaryWriterOptions, a as BinaryReaderOptions } from './shared/tl-pack.DWKHpLIt.mjs';
2
- export { b as BinaryReader, c as BinaryWriter, C as CORE_TYPES, D as DecodeHandler, f as DefineStructureOptions, E as EncodeHandler, M as MAX_BUFFER_SIZE, S as Structure, T as TLExtension, d as createDictionary, e as createExtension, g as defineStructure } from './shared/tl-pack.DWKHpLIt.mjs';
1
+ import { B as BinaryWriterOptions, a as BinaryReaderOptions } from './shared/tl-pack.B7UgWY_K.mjs';
2
+ export { b as BinaryReader, c as BinaryWriter, C as CORE_TYPES, D as DecodeHandler, f as DefineStructureOptions, E as EncodeHandler, M as MAX_BUFFER_SIZE, S as Structure, T as TLExtension, d as createDictionary, e as createExtension, g as defineStructure } from './shared/tl-pack.B7UgWY_K.mjs';
3
3
  import '@andrew_l/toolkit';
4
4
 
5
5
  /**
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { B as BinaryWriterOptions, a as BinaryReaderOptions } from './shared/tl-pack.DWKHpLIt.js';
2
- export { b as BinaryReader, c as BinaryWriter, C as CORE_TYPES, D as DecodeHandler, f as DefineStructureOptions, E as EncodeHandler, M as MAX_BUFFER_SIZE, S as Structure, T as TLExtension, d as createDictionary, e as createExtension, g as defineStructure } from './shared/tl-pack.DWKHpLIt.js';
1
+ import { B as BinaryWriterOptions, a as BinaryReaderOptions } from './shared/tl-pack.B7UgWY_K.js';
2
+ export { b as BinaryReader, c as BinaryWriter, C as CORE_TYPES, D as DecodeHandler, f as DefineStructureOptions, E as EncodeHandler, M as MAX_BUFFER_SIZE, S as Structure, T as TLExtension, d as createDictionary, e as createExtension, g as defineStructure } from './shared/tl-pack.B7UgWY_K.js';
3
3
  import '@andrew_l/toolkit';
4
4
 
5
5
  /**
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { B as BinaryWriter, a as BinaryReader } from './shared/tl-pack.JLeffH7U.mjs';
2
- export { C as CORE_TYPES, M as MAX_BUFFER_SIZE, S as Structure, c as createDictionary, d as defineStructure } from './shared/tl-pack.JLeffH7U.mjs';
1
+ import { B as BinaryWriter, a as BinaryReader } from './shared/tl-pack.CN5ucZro.mjs';
2
+ export { C as CORE_TYPES, M as MAX_BUFFER_SIZE, S as Structure, c as createDictionary, d as defineStructure } from './shared/tl-pack.CN5ucZro.mjs';
3
3
  import { assert } from '@andrew_l/toolkit';
4
4
  import 'pako';
5
5
 
@@ -7,6 +7,7 @@ declare class Dictionary {
7
7
  private _words;
8
8
  private _offset;
9
9
  constructor(values?: string[], offset?: number);
10
+ clear(): void;
10
11
  get size(): number;
11
12
  /**
12
13
  * Returns inserted index or nothing
@@ -59,6 +60,7 @@ declare class BinaryWriter {
59
60
  writeByte(value: number): this;
60
61
  writeBool(value: boolean): this;
61
62
  writeNull(): this;
63
+ writeInt64(value: number | bigint, signed?: boolean): this;
62
64
  writeInt32(value: number, signed?: boolean): this;
63
65
  writeInt16(value: number, signed?: boolean): this;
64
66
  writeInt8(value: number, signed?: boolean): this;
@@ -93,9 +95,11 @@ declare enum CORE_TYPES {
93
95
  Date = 5,
94
96
  Vector = 6,
95
97
  VectorDynamic = 7,
98
+ Int64 = 22,
96
99
  Int32 = 8,
97
100
  Int16 = 9,
98
101
  Int8 = 10,
102
+ UInt64 = 23,
99
103
  UInt32 = 11,
100
104
  UInt16 = 12,
101
105
  UInt8 = 13,
@@ -391,6 +395,7 @@ declare class BinaryReader {
391
395
  */
392
396
  constructor(data: Uint8Array, { dictionary, extensions, structures, }?: BinaryReaderOptions);
393
397
  readByte(): number;
398
+ readInt64(signed?: boolean): bigint;
394
399
  readInt32(signed?: boolean): number;
395
400
  readInt16(signed?: boolean): number;
396
401
  readInt8(signed?: boolean): number;
@@ -401,7 +406,6 @@ declare class BinaryReader {
401
406
  readFloat(): number;
402
407
  /**
403
408
  * Reads a real floating point (8 bytes) value.
404
- * @returns {BigInteger}
405
409
  */
406
410
  readDouble(): number;
407
411
  /**
@@ -465,6 +469,10 @@ declare class BinaryReader {
465
469
  * The offset may be negative.
466
470
  */
467
471
  seek(offset: number): void;
472
+ /**
473
+ * Sets the current buffer and reset initial state.
474
+ */
475
+ reset(data?: Uint8Array): void;
468
476
  }
469
477
 
470
478
  export { type BinaryWriterOptions as B, CORE_TYPES as C, type DecodeHandler as D, type EncodeHandler as E, MAX_BUFFER_SIZE as M, Structure as S, type TLExtension as T, type BinaryReaderOptions as a, BinaryReader as b, BinaryWriter as c, createDictionary as d, createExtension as e, type DefineStructureOptions as f, defineStructure as g };
@@ -7,6 +7,7 @@ declare class Dictionary {
7
7
  private _words;
8
8
  private _offset;
9
9
  constructor(values?: string[], offset?: number);
10
+ clear(): void;
10
11
  get size(): number;
11
12
  /**
12
13
  * Returns inserted index or nothing
@@ -59,6 +60,7 @@ declare class BinaryWriter {
59
60
  writeByte(value: number): this;
60
61
  writeBool(value: boolean): this;
61
62
  writeNull(): this;
63
+ writeInt64(value: number | bigint, signed?: boolean): this;
62
64
  writeInt32(value: number, signed?: boolean): this;
63
65
  writeInt16(value: number, signed?: boolean): this;
64
66
  writeInt8(value: number, signed?: boolean): this;
@@ -93,9 +95,11 @@ declare enum CORE_TYPES {
93
95
  Date = 5,
94
96
  Vector = 6,
95
97
  VectorDynamic = 7,
98
+ Int64 = 22,
96
99
  Int32 = 8,
97
100
  Int16 = 9,
98
101
  Int8 = 10,
102
+ UInt64 = 23,
99
103
  UInt32 = 11,
100
104
  UInt16 = 12,
101
105
  UInt8 = 13,
@@ -391,6 +395,7 @@ declare class BinaryReader {
391
395
  */
392
396
  constructor(data: Uint8Array, { dictionary, extensions, structures, }?: BinaryReaderOptions);
393
397
  readByte(): number;
398
+ readInt64(signed?: boolean): bigint;
394
399
  readInt32(signed?: boolean): number;
395
400
  readInt16(signed?: boolean): number;
396
401
  readInt8(signed?: boolean): number;
@@ -401,7 +406,6 @@ declare class BinaryReader {
401
406
  readFloat(): number;
402
407
  /**
403
408
  * Reads a real floating point (8 bytes) value.
404
- * @returns {BigInteger}
405
409
  */
406
410
  readDouble(): number;
407
411
  /**
@@ -465,6 +469,10 @@ declare class BinaryReader {
465
469
  * The offset may be negative.
466
470
  */
467
471
  seek(offset: number): void;
472
+ /**
473
+ * Sets the current buffer and reset initial state.
474
+ */
475
+ reset(data?: Uint8Array): void;
468
476
  }
469
477
 
470
478
  export { type BinaryWriterOptions as B, CORE_TYPES as C, type DecodeHandler as D, type EncodeHandler as E, MAX_BUFFER_SIZE as M, Structure as S, type TLExtension as T, type BinaryReaderOptions as a, BinaryReader as b, BinaryWriter as c, createDictionary as d, createExtension as e, type DefineStructureOptions as f, defineStructure as g };
@@ -7,6 +7,7 @@ declare class Dictionary {
7
7
  private _words;
8
8
  private _offset;
9
9
  constructor(values?: string[], offset?: number);
10
+ clear(): void;
10
11
  get size(): number;
11
12
  /**
12
13
  * Returns inserted index or nothing
@@ -59,6 +60,7 @@ declare class BinaryWriter {
59
60
  writeByte(value: number): this;
60
61
  writeBool(value: boolean): this;
61
62
  writeNull(): this;
63
+ writeInt64(value: number | bigint, signed?: boolean): this;
62
64
  writeInt32(value: number, signed?: boolean): this;
63
65
  writeInt16(value: number, signed?: boolean): this;
64
66
  writeInt8(value: number, signed?: boolean): this;
@@ -93,9 +95,11 @@ declare enum CORE_TYPES {
93
95
  Date = 5,
94
96
  Vector = 6,
95
97
  VectorDynamic = 7,
98
+ Int64 = 22,
96
99
  Int32 = 8,
97
100
  Int16 = 9,
98
101
  Int8 = 10,
102
+ UInt64 = 23,
99
103
  UInt32 = 11,
100
104
  UInt16 = 12,
101
105
  UInt8 = 13,
@@ -391,6 +395,7 @@ declare class BinaryReader {
391
395
  */
392
396
  constructor(data: Uint8Array, { dictionary, extensions, structures, }?: BinaryReaderOptions);
393
397
  readByte(): number;
398
+ readInt64(signed?: boolean): bigint;
394
399
  readInt32(signed?: boolean): number;
395
400
  readInt16(signed?: boolean): number;
396
401
  readInt8(signed?: boolean): number;
@@ -401,7 +406,6 @@ declare class BinaryReader {
401
406
  readFloat(): number;
402
407
  /**
403
408
  * Reads a real floating point (8 bytes) value.
404
- * @returns {BigInteger}
405
409
  */
406
410
  readDouble(): number;
407
411
  /**
@@ -465,6 +469,10 @@ declare class BinaryReader {
465
469
  * The offset may be negative.
466
470
  */
467
471
  seek(offset: number): void;
472
+ /**
473
+ * Sets the current buffer and reset initial state.
474
+ */
475
+ reset(data?: Uint8Array): void;
468
476
  }
469
477
 
470
478
  export { type BinaryWriterOptions as B, CORE_TYPES as C, type DecodeHandler as D, type EncodeHandler as E, MAX_BUFFER_SIZE as M, Structure as S, type TLExtension as T, type BinaryReaderOptions as a, BinaryReader as b, BinaryWriter as c, createDictionary as d, createExtension as e, type DefineStructureOptions as f, defineStructure as g };
@@ -16,9 +16,11 @@ var CORE_TYPES = /* @__PURE__ */ ((CORE_TYPES2) => {
16
16
  CORE_TYPES2[CORE_TYPES2["Date"] = 5] = "Date";
17
17
  CORE_TYPES2[CORE_TYPES2["Vector"] = 6] = "Vector";
18
18
  CORE_TYPES2[CORE_TYPES2["VectorDynamic"] = 7] = "VectorDynamic";
19
+ CORE_TYPES2[CORE_TYPES2["Int64"] = 22] = "Int64";
19
20
  CORE_TYPES2[CORE_TYPES2["Int32"] = 8] = "Int32";
20
21
  CORE_TYPES2[CORE_TYPES2["Int16"] = 9] = "Int16";
21
22
  CORE_TYPES2[CORE_TYPES2["Int8"] = 10] = "Int8";
23
+ CORE_TYPES2[CORE_TYPES2["UInt64"] = 23] = "UInt64";
22
24
  CORE_TYPES2[CORE_TYPES2["UInt32"] = 11] = "UInt32";
23
25
  CORE_TYPES2[CORE_TYPES2["UInt16"] = 12] = "UInt16";
24
26
  CORE_TYPES2[CORE_TYPES2["UInt8"] = 13] = "UInt8";
@@ -40,11 +42,12 @@ function createDictionary(values) {
40
42
  return new Dictionary(values);
41
43
  }
42
44
  class Dictionary {
43
- _count = 0;
45
+ _count;
44
46
  _wordToIndex;
45
47
  _words;
46
48
  _offset;
47
49
  constructor(values, offset = 0) {
50
+ this._count = 0;
48
51
  this._words = [];
49
52
  this._wordToIndex = /* @__PURE__ */ new Map();
50
53
  this._offset = offset;
@@ -56,6 +59,11 @@ class Dictionary {
56
59
  });
57
60
  }
58
61
  }
62
+ clear() {
63
+ this._count = 0;
64
+ this._words.length = 0;
65
+ this._wordToIndex.clear();
66
+ }
59
67
  get size() {
60
68
  return this._count;
61
69
  }
@@ -143,7 +151,7 @@ class BinaryWriter {
143
151
  this.offsetChecksum = 0;
144
152
  this._last = noop;
145
153
  this._repeat = void 0;
146
- this.dictionaryExtended = new Dictionary(void 0, this.dictionary.size);
154
+ this.dictionaryExtended.clear();
147
155
  return this;
148
156
  }
149
157
  allocate(size) {
@@ -199,6 +207,15 @@ class BinaryWriter {
199
207
  this.writeByte(CORE_TYPES.Null);
200
208
  return this;
201
209
  }
210
+ writeInt64(value, signed = true) {
211
+ this.allocate(8);
212
+ if (typeof value === "number") value = BigInt(value);
213
+ const low32 = Number(value & 0xffffffffn);
214
+ const high32 = Number(value >> 32n);
215
+ this.writeInt32(low32, signed);
216
+ this.writeInt32(high32, signed);
217
+ return this;
218
+ }
202
219
  writeInt32(value, signed = true) {
203
220
  this.allocate(4);
204
221
  if (signed) {
@@ -462,6 +479,9 @@ class BinaryWriter {
462
479
  case CORE_TYPES.Date: {
463
480
  return this.writeDate(value);
464
481
  }
482
+ case CORE_TYPES.Int64: {
483
+ return this.writeInt64(value);
484
+ }
465
485
  case CORE_TYPES.Int32: {
466
486
  return this.writeInt32(value);
467
487
  }
@@ -471,6 +491,9 @@ class BinaryWriter {
471
491
  case CORE_TYPES.Int8: {
472
492
  return this.writeInt8(value);
473
493
  }
494
+ case CORE_TYPES.UInt64: {
495
+ return this.writeInt64(value, false);
496
+ }
474
497
  case CORE_TYPES.UInt32: {
475
498
  return this.writeInt32(value, false);
476
499
  }
@@ -906,6 +929,14 @@ function coreType(value) {
906
929
  case "boolean": {
907
930
  return value ? CORE_TYPES.BoolTrue : CORE_TYPES.BoolFalse;
908
931
  }
932
+ case "bigint": {
933
+ if (value >= 0n && value <= 0xffffffffffffffffn) {
934
+ return CORE_TYPES.UInt64;
935
+ } else if (value >= -0x8000000000000000n && value <= 0x7fffffffffffffffn) {
936
+ return CORE_TYPES.Int64;
937
+ }
938
+ return CORE_TYPES.None;
939
+ }
909
940
  case "number": {
910
941
  if (Math.trunc(value) === value) {
911
942
  if (value >= 0 && value <= 255) {
@@ -1195,6 +1226,12 @@ class BinaryReader {
1195
1226
  this._last = this.target[this.offset++];
1196
1227
  return this._last;
1197
1228
  }
1229
+ readInt64(signed = true) {
1230
+ const low32 = this.readInt32(signed);
1231
+ const high32 = this.readInt32(signed);
1232
+ this._last = BigInt(high32) << 32n | BigInt(low32);
1233
+ return this._last;
1234
+ }
1198
1235
  readInt32(signed = true) {
1199
1236
  this.assertRead(4);
1200
1237
  this._last = this.target[this.offset++] | this.target[this.offset++] << 8 | this.target[this.offset++] << 16 | this.target[this.offset++] << 24;
@@ -1231,7 +1268,6 @@ class BinaryReader {
1231
1268
  }
1232
1269
  /**
1233
1270
  * Reads a real floating point (8 bytes) value.
1234
- * @returns {BigInteger}
1235
1271
  */
1236
1272
  readDouble() {
1237
1273
  this.assertRead(8);
@@ -1399,12 +1435,16 @@ class BinaryReader {
1399
1435
  return this.readString();
1400
1436
  case CORE_TYPES.Date:
1401
1437
  return this.readDate();
1438
+ case CORE_TYPES.Int64:
1439
+ return this.readInt64();
1402
1440
  case CORE_TYPES.Int32:
1403
1441
  return this.readInt32();
1404
1442
  case CORE_TYPES.Int16:
1405
1443
  return this.readInt16();
1406
1444
  case CORE_TYPES.Int8:
1407
1445
  return this.readInt8();
1446
+ case CORE_TYPES.UInt64:
1447
+ return this.readInt64(false);
1408
1448
  case CORE_TYPES.UInt32:
1409
1449
  return this.readInt32(false);
1410
1450
  case CORE_TYPES.UInt16:
@@ -1580,6 +1620,21 @@ class BinaryReader {
1580
1620
  seek(offset) {
1581
1621
  this.offset += offset;
1582
1622
  }
1623
+ /**
1624
+ * Sets the current buffer and reset initial state.
1625
+ */
1626
+ reset(data) {
1627
+ this.offset = 0;
1628
+ this._checksumOffset = 0;
1629
+ this._lastObject = void 0;
1630
+ this._last = void 0;
1631
+ this._repeat = void 0;
1632
+ this.dictionaryExtended.clear();
1633
+ if (data) {
1634
+ this.length = data.length;
1635
+ this.target = data;
1636
+ }
1637
+ }
1583
1638
  }
1584
1639
 
1585
1640
  exports.BinaryReader = BinaryReader;
@@ -1589,4 +1644,4 @@ exports.MAX_BUFFER_SIZE = MAX_BUFFER_SIZE;
1589
1644
  exports.Structure = Structure;
1590
1645
  exports.createDictionary = createDictionary;
1591
1646
  exports.defineStructure = defineStructure;
1592
- //# sourceMappingURL=tl-pack.c8vOMguk.cjs.map
1647
+ //# sourceMappingURL=tl-pack.BdWYOLsg.cjs.map