@andrew_l/tl-pack 0.1.8 → 0.1.9
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 +21 -0
- package/README.md +5 -5
- package/dist/index.cjs +36 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +28 -0
- package/dist/index.d.mts +28 -0
- package/dist/index.d.ts +28 -5
- package/dist/index.mjs +28 -0
- package/dist/index.mjs.map +1 -0
- package/dist/shared/tl-pack.CdcwN4dG.d.cts +195 -0
- package/dist/shared/tl-pack.CdcwN4dG.d.mts +195 -0
- package/dist/shared/tl-pack.CdcwN4dG.d.ts +195 -0
- package/dist/shared/tl-pack.DnNse4P6.mjs +1112 -0
- package/dist/shared/tl-pack.DnNse4P6.mjs.map +1 -0
- package/dist/shared/tl-pack.VfbARqWq.cjs +1122 -0
- package/dist/shared/tl-pack.VfbARqWq.cjs.map +1 -0
- package/dist/stream.cjs +72 -0
- package/dist/stream.cjs.map +1 -0
- package/dist/stream.d.cts +20 -0
- package/dist/stream.d.mts +20 -0
- package/dist/stream.d.ts +8 -8
- package/dist/stream.mjs +69 -0
- package/dist/stream.mjs.map +1 -0
- package/package.json +42 -53
- package/dist/BinaryReader.d.ts +0 -109
- package/dist/BinaryReader.js +0 -412
- package/dist/BinaryWriter.d.ts +0 -47
- package/dist/BinaryWriter.js +0 -385
- package/dist/constants.d.ts +0 -26
- package/dist/constants.js +0 -27
- package/dist/dictionary.d.ts +0 -17
- package/dist/dictionary.js +0 -51
- package/dist/extension.d.ts +0 -13
- package/dist/extension.js +0 -13
- package/dist/helpers.d.ts +0 -11
- package/dist/helpers.js +0 -321
- package/dist/index.js +0 -5
- package/dist/stream.js +0 -67
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Andrew L. <andrew.io.dev@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
  
|
|
4
4
|
|
|
5
|
-
This library is
|
|
6
|
-
|
|
7
|
-
You don't needed in schema for data serialization/deserialization unlike official TL implementation at least in this version.
|
|
5
|
+
This library is an alternative binary serialization, like MessagePack, inspired by TL (Type Language) from the original VK team. Unlike official TL, it requires no schema for serialization/deserialization in this version.
|
|
8
6
|
|
|
9
7
|
## Benchmark
|
|
10
8
|
|
|
11
9
|
A bit faster and a bit more compact than **@msgpack/msgpack**
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
⚠️ May not be true
|
|
12
|
+
|
|
13
|
+
## Example
|
|
14
14
|
|
|
15
15
|
```javascript
|
|
16
16
|
import { BinaryWriter, BinaryReader } from '@andrew_l/tl-pack';
|
|
@@ -100,7 +100,7 @@ const decode = new TLDecode();
|
|
|
100
100
|
|
|
101
101
|
dataStream.pipe(encode).pipe(decode);
|
|
102
102
|
|
|
103
|
-
decode.on('data',
|
|
103
|
+
decode.on('data', data => console.log('stream', data));
|
|
104
104
|
decode.on('error', console.error);
|
|
105
105
|
```
|
|
106
106
|
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const BinaryWriter = require('./shared/tl-pack.VfbARqWq.cjs');
|
|
4
|
+
const toolkit = require('@andrew_l/toolkit');
|
|
5
|
+
require('pako');
|
|
6
|
+
|
|
7
|
+
function createExtension(token, { encode, decode }) {
|
|
8
|
+
toolkit.assert.ok(Math.trunc(token) === token, " Token must be integer value.");
|
|
9
|
+
toolkit.assert.ok(
|
|
10
|
+
token >= 0 && token <= 255,
|
|
11
|
+
"Token must be a 8 bit number. (0 - 255)"
|
|
12
|
+
);
|
|
13
|
+
toolkit.assert.ok(token >= 35, "Tokens from 0 to 34 reserved.");
|
|
14
|
+
return {
|
|
15
|
+
token,
|
|
16
|
+
encode,
|
|
17
|
+
decode
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function tlEncode(value, opts) {
|
|
22
|
+
return new BinaryWriter.BinaryWriter(opts).writeObject(value).getBuffer();
|
|
23
|
+
}
|
|
24
|
+
function tlDecode(buffer, opts) {
|
|
25
|
+
return new BinaryWriter.BinaryReader(buffer, opts).readObject();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
exports.BinaryReader = BinaryWriter.BinaryReader;
|
|
29
|
+
exports.BinaryWriter = BinaryWriter.BinaryWriter;
|
|
30
|
+
exports.CORE_TYPES = BinaryWriter.CORE_TYPES;
|
|
31
|
+
exports.MAX_BUFFER_SIZE = BinaryWriter.MAX_BUFFER_SIZE;
|
|
32
|
+
exports.createDictionary = BinaryWriter.createDictionary;
|
|
33
|
+
exports.createExtension = createExtension;
|
|
34
|
+
exports.tlDecode = tlDecode;
|
|
35
|
+
exports.tlEncode = tlEncode;
|
|
36
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/extension.ts","../src/index.ts"],"sourcesContent":["import { assert } from '@andrew_l/toolkit';\nimport type { BinaryReader } from './BinaryReader';\nimport type { BinaryWriter } from './BinaryWriter';\n\nexport type EncodeHandler = (this: BinaryWriter, value: any) => void;\n\nexport type DecodeHandler = (this: BinaryReader) => any;\n\nexport interface TLExtension {\n token: number;\n encode: EncodeHandler;\n decode: DecodeHandler;\n}\n\nexport function createExtension(\n token: number,\n { encode, decode }: { encode: EncodeHandler; decode: DecodeHandler },\n): TLExtension {\n assert.ok(Math.trunc(token) === token, ' Token must be integer value.');\n\n assert.ok(\n token >= 0 && token <= 255,\n 'Token must be a 8 bit number. (0 - 255)',\n );\n\n assert.ok(token >= 35, 'Tokens from 0 to 34 reserved.');\n\n return {\n token,\n encode,\n decode,\n };\n}\n","import { BinaryReader, type BinaryReaderOptions } from './BinaryReader';\nimport { BinaryWriter, type BinaryWriterOptions } from './BinaryWriter';\n\nexport { BinaryReader, type BinaryReaderOptions } from './BinaryReader';\nexport { BinaryWriter, type BinaryWriterOptions } from './BinaryWriter';\nexport * from './constants';\nexport { createDictionary } from './dictionary';\nexport {\n createExtension,\n type DecodeHandler,\n type EncodeHandler,\n type TLExtension,\n} from './extension';\n\n/**\n * Encode any value into `Uint8Array`\n *\n * @example\n * const buffer = tlEncode(new Date(0));\n *\n * console.log(buffer); // Uint8Array([5, 0, 0, 0, 0, 0, 0, 0, 0])\n *\n * @group Main\n */\nexport function tlEncode(\n value: unknown,\n opts?: BinaryWriterOptions,\n): Uint8Array {\n return new BinaryWriter(opts).writeObject(value).getBuffer();\n}\n\n/**\n * Decode value from `Uint8Array`\n *\n * @example\n * const buffer = new Uint8Array([5, 0, 0, 0, 0, 0, 0, 0, 0]);\n * const value = tlDecode(buffer);\n *\n * console.log(value); // Thu Jan 01 1970 01:00:00 GMT+0100 (Central European Standard Time)\n *\n * @group Main\n */\nexport function tlDecode<T = any>(\n buffer: Uint8Array,\n opts?: BinaryReaderOptions,\n): T {\n return new BinaryReader(buffer, opts).readObject();\n}\n"],"names":["assert","BinaryWriter","BinaryReader"],"mappings":";;;;;;AAcO,SAAS,eACd,CAAA,KAAA,EACA,EAAE,MAAA,EAAQ,QACG,EAAA;AACb,EAAAA,cAAA,CAAO,GAAG,IAAK,CAAA,KAAA,CAAM,KAAK,CAAA,KAAM,OAAO,+BAA+B,CAAA,CAAA;AAEtE,EAAOA,cAAA,CAAA,EAAA;AAAA,IACL,KAAA,IAAS,KAAK,KAAS,IAAA,GAAA;AAAA,IACvB,yCAAA;AAAA,GACF,CAAA;AAEA,EAAOA,cAAA,CAAA,EAAA,CAAG,KAAS,IAAA,EAAA,EAAI,+BAA+B,CAAA,CAAA;AAEtD,EAAO,OAAA;AAAA,IACL,KAAA;AAAA,IACA,MAAA;AAAA,IACA,MAAA;AAAA,GACF,CAAA;AACF;;ACRgB,SAAA,QAAA,CACd,OACA,IACY,EAAA;AACZ,EAAA,OAAO,IAAIC,yBAAa,CAAA,IAAI,EAAE,WAAY,CAAA,KAAK,EAAE,SAAU,EAAA,CAAA;AAC7D,CAAA;AAagB,SAAA,QAAA,CACd,QACA,IACG,EAAA;AACH,EAAA,OAAO,IAAIC,yBAAA,CAAa,MAAQ,EAAA,IAAI,EAAE,UAAW,EAAA,CAAA;AACnD;;;;;;;;;;;"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { B as BinaryWriterOptions, a as BinaryReaderOptions } from './shared/tl-pack.CdcwN4dG.cjs';
|
|
2
|
+
export { b as BinaryReader, c as BinaryWriter, C as CORE_TYPES, D as DecodeHandler, E as EncodeHandler, M as MAX_BUFFER_SIZE, T as TLExtension, d as createDictionary, e as createExtension } from './shared/tl-pack.CdcwN4dG.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Encode any value into `Uint8Array`
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const buffer = tlEncode(new Date(0));
|
|
9
|
+
*
|
|
10
|
+
* console.log(buffer); // Uint8Array([5, 0, 0, 0, 0, 0, 0, 0, 0])
|
|
11
|
+
*
|
|
12
|
+
* @group Main
|
|
13
|
+
*/
|
|
14
|
+
declare function tlEncode(value: unknown, opts?: BinaryWriterOptions): Uint8Array;
|
|
15
|
+
/**
|
|
16
|
+
* Decode value from `Uint8Array`
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const buffer = new Uint8Array([5, 0, 0, 0, 0, 0, 0, 0, 0]);
|
|
20
|
+
* const value = tlDecode(buffer);
|
|
21
|
+
*
|
|
22
|
+
* console.log(value); // Thu Jan 01 1970 01:00:00 GMT+0100 (Central European Standard Time)
|
|
23
|
+
*
|
|
24
|
+
* @group Main
|
|
25
|
+
*/
|
|
26
|
+
declare function tlDecode<T = any>(buffer: Uint8Array, opts?: BinaryReaderOptions): T;
|
|
27
|
+
|
|
28
|
+
export { BinaryReaderOptions, BinaryWriterOptions, tlDecode, tlEncode };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { B as BinaryWriterOptions, a as BinaryReaderOptions } from './shared/tl-pack.CdcwN4dG.mjs';
|
|
2
|
+
export { b as BinaryReader, c as BinaryWriter, C as CORE_TYPES, D as DecodeHandler, E as EncodeHandler, M as MAX_BUFFER_SIZE, T as TLExtension, d as createDictionary, e as createExtension } from './shared/tl-pack.CdcwN4dG.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Encode any value into `Uint8Array`
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const buffer = tlEncode(new Date(0));
|
|
9
|
+
*
|
|
10
|
+
* console.log(buffer); // Uint8Array([5, 0, 0, 0, 0, 0, 0, 0, 0])
|
|
11
|
+
*
|
|
12
|
+
* @group Main
|
|
13
|
+
*/
|
|
14
|
+
declare function tlEncode(value: unknown, opts?: BinaryWriterOptions): Uint8Array;
|
|
15
|
+
/**
|
|
16
|
+
* Decode value from `Uint8Array`
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const buffer = new Uint8Array([5, 0, 0, 0, 0, 0, 0, 0, 0]);
|
|
20
|
+
* const value = tlDecode(buffer);
|
|
21
|
+
*
|
|
22
|
+
* console.log(value); // Thu Jan 01 1970 01:00:00 GMT+0100 (Central European Standard Time)
|
|
23
|
+
*
|
|
24
|
+
* @group Main
|
|
25
|
+
*/
|
|
26
|
+
declare function tlDecode<T = any>(buffer: Uint8Array, opts?: BinaryReaderOptions): T;
|
|
27
|
+
|
|
28
|
+
export { BinaryReaderOptions, BinaryWriterOptions, tlDecode, tlEncode };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { B as BinaryWriterOptions, a as BinaryReaderOptions } from './shared/tl-pack.CdcwN4dG.js';
|
|
2
|
+
export { b as BinaryReader, c as BinaryWriter, C as CORE_TYPES, D as DecodeHandler, E as EncodeHandler, M as MAX_BUFFER_SIZE, T as TLExtension, d as createDictionary, e as createExtension } from './shared/tl-pack.CdcwN4dG.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Encode any value into `Uint8Array`
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const buffer = tlEncode(new Date(0));
|
|
9
|
+
*
|
|
10
|
+
* console.log(buffer); // Uint8Array([5, 0, 0, 0, 0, 0, 0, 0, 0])
|
|
11
|
+
*
|
|
12
|
+
* @group Main
|
|
13
|
+
*/
|
|
14
|
+
declare function tlEncode(value: unknown, opts?: BinaryWriterOptions): Uint8Array;
|
|
15
|
+
/**
|
|
16
|
+
* Decode value from `Uint8Array`
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const buffer = new Uint8Array([5, 0, 0, 0, 0, 0, 0, 0, 0]);
|
|
20
|
+
* const value = tlDecode(buffer);
|
|
21
|
+
*
|
|
22
|
+
* console.log(value); // Thu Jan 01 1970 01:00:00 GMT+0100 (Central European Standard Time)
|
|
23
|
+
*
|
|
24
|
+
* @group Main
|
|
25
|
+
*/
|
|
26
|
+
declare function tlDecode<T = any>(buffer: Uint8Array, opts?: BinaryReaderOptions): T;
|
|
27
|
+
|
|
28
|
+
export { BinaryReaderOptions, BinaryWriterOptions, tlDecode, tlEncode };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { B as BinaryWriter, a as BinaryReader } from './shared/tl-pack.DnNse4P6.mjs';
|
|
2
|
+
export { C as CORE_TYPES, M as MAX_BUFFER_SIZE, c as createDictionary } from './shared/tl-pack.DnNse4P6.mjs';
|
|
3
|
+
import { assert } from '@andrew_l/toolkit';
|
|
4
|
+
import 'pako';
|
|
5
|
+
|
|
6
|
+
function createExtension(token, { encode, decode }) {
|
|
7
|
+
assert.ok(Math.trunc(token) === token, " Token must be integer value.");
|
|
8
|
+
assert.ok(
|
|
9
|
+
token >= 0 && token <= 255,
|
|
10
|
+
"Token must be a 8 bit number. (0 - 255)"
|
|
11
|
+
);
|
|
12
|
+
assert.ok(token >= 35, "Tokens from 0 to 34 reserved.");
|
|
13
|
+
return {
|
|
14
|
+
token,
|
|
15
|
+
encode,
|
|
16
|
+
decode
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function tlEncode(value, opts) {
|
|
21
|
+
return new BinaryWriter(opts).writeObject(value).getBuffer();
|
|
22
|
+
}
|
|
23
|
+
function tlDecode(buffer, opts) {
|
|
24
|
+
return new BinaryReader(buffer, opts).readObject();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { BinaryReader, BinaryWriter, createExtension, tlDecode, tlEncode };
|
|
28
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/extension.ts","../src/index.ts"],"sourcesContent":["import { assert } from '@andrew_l/toolkit';\nimport type { BinaryReader } from './BinaryReader';\nimport type { BinaryWriter } from './BinaryWriter';\n\nexport type EncodeHandler = (this: BinaryWriter, value: any) => void;\n\nexport type DecodeHandler = (this: BinaryReader) => any;\n\nexport interface TLExtension {\n token: number;\n encode: EncodeHandler;\n decode: DecodeHandler;\n}\n\nexport function createExtension(\n token: number,\n { encode, decode }: { encode: EncodeHandler; decode: DecodeHandler },\n): TLExtension {\n assert.ok(Math.trunc(token) === token, ' Token must be integer value.');\n\n assert.ok(\n token >= 0 && token <= 255,\n 'Token must be a 8 bit number. (0 - 255)',\n );\n\n assert.ok(token >= 35, 'Tokens from 0 to 34 reserved.');\n\n return {\n token,\n encode,\n decode,\n };\n}\n","import { BinaryReader, type BinaryReaderOptions } from './BinaryReader';\nimport { BinaryWriter, type BinaryWriterOptions } from './BinaryWriter';\n\nexport { BinaryReader, type BinaryReaderOptions } from './BinaryReader';\nexport { BinaryWriter, type BinaryWriterOptions } from './BinaryWriter';\nexport * from './constants';\nexport { createDictionary } from './dictionary';\nexport {\n createExtension,\n type DecodeHandler,\n type EncodeHandler,\n type TLExtension,\n} from './extension';\n\n/**\n * Encode any value into `Uint8Array`\n *\n * @example\n * const buffer = tlEncode(new Date(0));\n *\n * console.log(buffer); // Uint8Array([5, 0, 0, 0, 0, 0, 0, 0, 0])\n *\n * @group Main\n */\nexport function tlEncode(\n value: unknown,\n opts?: BinaryWriterOptions,\n): Uint8Array {\n return new BinaryWriter(opts).writeObject(value).getBuffer();\n}\n\n/**\n * Decode value from `Uint8Array`\n *\n * @example\n * const buffer = new Uint8Array([5, 0, 0, 0, 0, 0, 0, 0, 0]);\n * const value = tlDecode(buffer);\n *\n * console.log(value); // Thu Jan 01 1970 01:00:00 GMT+0100 (Central European Standard Time)\n *\n * @group Main\n */\nexport function tlDecode<T = any>(\n buffer: Uint8Array,\n opts?: BinaryReaderOptions,\n): T {\n return new BinaryReader(buffer, opts).readObject();\n}\n"],"names":[],"mappings":";;;;;AAcO,SAAS,eACd,CAAA,KAAA,EACA,EAAE,MAAA,EAAQ,QACG,EAAA;AACb,EAAA,MAAA,CAAO,GAAG,IAAK,CAAA,KAAA,CAAM,KAAK,CAAA,KAAM,OAAO,+BAA+B,CAAA,CAAA;AAEtE,EAAO,MAAA,CAAA,EAAA;AAAA,IACL,KAAA,IAAS,KAAK,KAAS,IAAA,GAAA;AAAA,IACvB,yCAAA;AAAA,GACF,CAAA;AAEA,EAAO,MAAA,CAAA,EAAA,CAAG,KAAS,IAAA,EAAA,EAAI,+BAA+B,CAAA,CAAA;AAEtD,EAAO,OAAA;AAAA,IACL,KAAA;AAAA,IACA,MAAA;AAAA,IACA,MAAA;AAAA,GACF,CAAA;AACF;;ACRgB,SAAA,QAAA,CACd,OACA,IACY,EAAA;AACZ,EAAA,OAAO,IAAI,YAAa,CAAA,IAAI,EAAE,WAAY,CAAA,KAAK,EAAE,SAAU,EAAA,CAAA;AAC7D,CAAA;AAagB,SAAA,QAAA,CACd,QACA,IACG,EAAA;AACH,EAAA,OAAO,IAAI,YAAA,CAAa,MAAQ,EAAA,IAAI,EAAE,UAAW,EAAA,CAAA;AACnD;;;;"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
declare enum CORE_TYPES {
|
|
2
|
+
None = 0,
|
|
3
|
+
Binary = 1,
|
|
4
|
+
BoolFalse = 2,
|
|
5
|
+
BoolTrue = 3,
|
|
6
|
+
Null = 4,
|
|
7
|
+
Date = 5,
|
|
8
|
+
Vector = 6,
|
|
9
|
+
VectorDynamic = 7,
|
|
10
|
+
Int32 = 8,
|
|
11
|
+
Int16 = 9,
|
|
12
|
+
Int8 = 10,
|
|
13
|
+
UInt32 = 11,
|
|
14
|
+
UInt16 = 12,
|
|
15
|
+
UInt8 = 13,
|
|
16
|
+
Float = 14,
|
|
17
|
+
Double = 15,
|
|
18
|
+
Map = 16,
|
|
19
|
+
DictValue = 17,
|
|
20
|
+
DictIndex = 18,
|
|
21
|
+
String = 19,
|
|
22
|
+
Repeat = 20,
|
|
23
|
+
GZIP = 25
|
|
24
|
+
}
|
|
25
|
+
declare const MAX_BUFFER_SIZE = 2144337920;
|
|
26
|
+
|
|
27
|
+
declare function createDictionary(values?: string[]): Dictionary;
|
|
28
|
+
declare class Dictionary {
|
|
29
|
+
private _count;
|
|
30
|
+
private _wordToIndex;
|
|
31
|
+
private _words;
|
|
32
|
+
private _offset;
|
|
33
|
+
constructor(values?: string[], offset?: number);
|
|
34
|
+
get size(): number;
|
|
35
|
+
/**
|
|
36
|
+
* Returns inserted index or nothing
|
|
37
|
+
*/
|
|
38
|
+
maybeInsert(word: string): number | null;
|
|
39
|
+
getValue(index: number): string | null;
|
|
40
|
+
getIndex(value: string): number | null;
|
|
41
|
+
hasValue(value: string): boolean;
|
|
42
|
+
hasIndex(index: number): boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface BinaryWriterOptions {
|
|
46
|
+
gzip?: boolean;
|
|
47
|
+
dictionary?: string[] | Dictionary;
|
|
48
|
+
extensions?: TLExtension[];
|
|
49
|
+
}
|
|
50
|
+
declare class BinaryWriter {
|
|
51
|
+
private withGzip;
|
|
52
|
+
private target;
|
|
53
|
+
private dictionary?;
|
|
54
|
+
private dictionaryExtended;
|
|
55
|
+
private extensions;
|
|
56
|
+
private _last;
|
|
57
|
+
private _repeat?;
|
|
58
|
+
offset: number;
|
|
59
|
+
constructor(options?: BinaryWriterOptions);
|
|
60
|
+
allocate(size: number): this;
|
|
61
|
+
private makeRoom;
|
|
62
|
+
get safeEnd(): number;
|
|
63
|
+
getBuffer(): Uint8Array;
|
|
64
|
+
writeByte(value: number): this;
|
|
65
|
+
writeBool(value: boolean): this;
|
|
66
|
+
writeNull(): this;
|
|
67
|
+
writeInt32(value: number, signed?: boolean): this;
|
|
68
|
+
writeInt16(value: number, signed?: boolean): this;
|
|
69
|
+
writeInt8(value: number, signed?: boolean): this;
|
|
70
|
+
writeFloat(value: number): this;
|
|
71
|
+
writeDouble(value: number): this;
|
|
72
|
+
writeDate(value: number | Date): this;
|
|
73
|
+
writeString(value: string): this;
|
|
74
|
+
writeBytes(value: Uint8Array): this;
|
|
75
|
+
writeLength(value: number): this;
|
|
76
|
+
writeVector(value: Array<any>): this;
|
|
77
|
+
writeMap(object: Record<string, any>): this;
|
|
78
|
+
wireDictionary(value: string): this;
|
|
79
|
+
writeGzip(value: Uint8Array | ArrayBuffer): this;
|
|
80
|
+
encode(value: any): Uint8Array;
|
|
81
|
+
startDynamicVector(): this;
|
|
82
|
+
endDynamicVector(): this;
|
|
83
|
+
private _writeCustom;
|
|
84
|
+
writeObject(value: any): this;
|
|
85
|
+
writeObjectGzip(value: any): this;
|
|
86
|
+
private writeCore;
|
|
87
|
+
private writeRepeat;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
type EncodeHandler = (this: BinaryWriter, value: any) => void;
|
|
91
|
+
type DecodeHandler = (this: BinaryReader) => any;
|
|
92
|
+
interface TLExtension {
|
|
93
|
+
token: number;
|
|
94
|
+
encode: EncodeHandler;
|
|
95
|
+
decode: DecodeHandler;
|
|
96
|
+
}
|
|
97
|
+
declare function createExtension(token: number, { encode, decode }: {
|
|
98
|
+
encode: EncodeHandler;
|
|
99
|
+
decode: DecodeHandler;
|
|
100
|
+
}): TLExtension;
|
|
101
|
+
|
|
102
|
+
interface BinaryReaderOptions {
|
|
103
|
+
dictionary?: string[] | Dictionary;
|
|
104
|
+
extensions?: TLExtension[];
|
|
105
|
+
}
|
|
106
|
+
declare class BinaryReader {
|
|
107
|
+
private target;
|
|
108
|
+
private _last?;
|
|
109
|
+
private _lastObject?;
|
|
110
|
+
private dictionary?;
|
|
111
|
+
private dictionaryExtended;
|
|
112
|
+
private extensions;
|
|
113
|
+
private _repeat?;
|
|
114
|
+
offset: number;
|
|
115
|
+
length: number;
|
|
116
|
+
/**
|
|
117
|
+
* Small utility class to read binary data.
|
|
118
|
+
*/
|
|
119
|
+
constructor(data: Uint8Array, options?: BinaryReaderOptions);
|
|
120
|
+
readByte(): number;
|
|
121
|
+
readInt32(signed?: boolean): number;
|
|
122
|
+
readInt16(signed?: boolean): number;
|
|
123
|
+
readInt8(signed?: boolean): number;
|
|
124
|
+
/**
|
|
125
|
+
* Reads a real floating point (4 bytes) value.
|
|
126
|
+
* @returns {number}
|
|
127
|
+
*/
|
|
128
|
+
readFloat(): number;
|
|
129
|
+
/**
|
|
130
|
+
* Reads a real floating point (8 bytes) value.
|
|
131
|
+
* @returns {BigInteger}
|
|
132
|
+
*/
|
|
133
|
+
readDouble(): number;
|
|
134
|
+
/**
|
|
135
|
+
* Read the given amount of bytes, or -1 to read all remaining.
|
|
136
|
+
* @param length {number}
|
|
137
|
+
*/
|
|
138
|
+
assertRead(length: number): void;
|
|
139
|
+
assertConstructor(constructorId: CORE_TYPES): void;
|
|
140
|
+
/**
|
|
141
|
+
* Gets the byte array representing the current buffer as a whole.
|
|
142
|
+
*/
|
|
143
|
+
getBuffer(): Uint8Array;
|
|
144
|
+
readNull(): null;
|
|
145
|
+
readLength(): number;
|
|
146
|
+
readAll(): any[];
|
|
147
|
+
readBytes(): Uint8Array;
|
|
148
|
+
/**
|
|
149
|
+
* Reads encoded string.
|
|
150
|
+
*/
|
|
151
|
+
readString(): string;
|
|
152
|
+
/**
|
|
153
|
+
* Reads a boolean value.
|
|
154
|
+
*/
|
|
155
|
+
readBool(): boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Reads and converts Unix time
|
|
158
|
+
* into a Javascript {Date} object.
|
|
159
|
+
*/
|
|
160
|
+
readDate(): Date;
|
|
161
|
+
/**
|
|
162
|
+
* Reads a object.
|
|
163
|
+
*/
|
|
164
|
+
readObject(): any;
|
|
165
|
+
readObjectGzip(): any;
|
|
166
|
+
readGzip(): any;
|
|
167
|
+
private readCore;
|
|
168
|
+
getDictionaryValue(index: number): string | null;
|
|
169
|
+
readDictionary(): null | string;
|
|
170
|
+
readMap(checkConstructor?: boolean): Record<string, any>;
|
|
171
|
+
decode<T = any>(value: Uint8Array): T;
|
|
172
|
+
/**
|
|
173
|
+
* Reads a vector (a list) of objects.
|
|
174
|
+
*/
|
|
175
|
+
readVector<T = any>(checkConstructor?: boolean): T[];
|
|
176
|
+
/**
|
|
177
|
+
* Reads a vector (a list) of objects.
|
|
178
|
+
*/
|
|
179
|
+
readVectorDynamic<T>(checkConstructor?: boolean): T[];
|
|
180
|
+
/**
|
|
181
|
+
* Tells the current position on the stream.
|
|
182
|
+
*/
|
|
183
|
+
tellPosition(): number;
|
|
184
|
+
/**
|
|
185
|
+
* Sets the current position on the stream.
|
|
186
|
+
*/
|
|
187
|
+
setPosition(position: number): void;
|
|
188
|
+
/**
|
|
189
|
+
* Seeks the stream position given an offset from the current position.
|
|
190
|
+
* The offset may be negative.
|
|
191
|
+
*/
|
|
192
|
+
seek(offset: number): void;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export { type BinaryWriterOptions as B, CORE_TYPES as C, type DecodeHandler as D, type EncodeHandler as E, MAX_BUFFER_SIZE as M, type TLExtension as T, type BinaryReaderOptions as a, BinaryReader as b, BinaryWriter as c, createDictionary as d, createExtension as e };
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
declare enum CORE_TYPES {
|
|
2
|
+
None = 0,
|
|
3
|
+
Binary = 1,
|
|
4
|
+
BoolFalse = 2,
|
|
5
|
+
BoolTrue = 3,
|
|
6
|
+
Null = 4,
|
|
7
|
+
Date = 5,
|
|
8
|
+
Vector = 6,
|
|
9
|
+
VectorDynamic = 7,
|
|
10
|
+
Int32 = 8,
|
|
11
|
+
Int16 = 9,
|
|
12
|
+
Int8 = 10,
|
|
13
|
+
UInt32 = 11,
|
|
14
|
+
UInt16 = 12,
|
|
15
|
+
UInt8 = 13,
|
|
16
|
+
Float = 14,
|
|
17
|
+
Double = 15,
|
|
18
|
+
Map = 16,
|
|
19
|
+
DictValue = 17,
|
|
20
|
+
DictIndex = 18,
|
|
21
|
+
String = 19,
|
|
22
|
+
Repeat = 20,
|
|
23
|
+
GZIP = 25
|
|
24
|
+
}
|
|
25
|
+
declare const MAX_BUFFER_SIZE = 2144337920;
|
|
26
|
+
|
|
27
|
+
declare function createDictionary(values?: string[]): Dictionary;
|
|
28
|
+
declare class Dictionary {
|
|
29
|
+
private _count;
|
|
30
|
+
private _wordToIndex;
|
|
31
|
+
private _words;
|
|
32
|
+
private _offset;
|
|
33
|
+
constructor(values?: string[], offset?: number);
|
|
34
|
+
get size(): number;
|
|
35
|
+
/**
|
|
36
|
+
* Returns inserted index or nothing
|
|
37
|
+
*/
|
|
38
|
+
maybeInsert(word: string): number | null;
|
|
39
|
+
getValue(index: number): string | null;
|
|
40
|
+
getIndex(value: string): number | null;
|
|
41
|
+
hasValue(value: string): boolean;
|
|
42
|
+
hasIndex(index: number): boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface BinaryWriterOptions {
|
|
46
|
+
gzip?: boolean;
|
|
47
|
+
dictionary?: string[] | Dictionary;
|
|
48
|
+
extensions?: TLExtension[];
|
|
49
|
+
}
|
|
50
|
+
declare class BinaryWriter {
|
|
51
|
+
private withGzip;
|
|
52
|
+
private target;
|
|
53
|
+
private dictionary?;
|
|
54
|
+
private dictionaryExtended;
|
|
55
|
+
private extensions;
|
|
56
|
+
private _last;
|
|
57
|
+
private _repeat?;
|
|
58
|
+
offset: number;
|
|
59
|
+
constructor(options?: BinaryWriterOptions);
|
|
60
|
+
allocate(size: number): this;
|
|
61
|
+
private makeRoom;
|
|
62
|
+
get safeEnd(): number;
|
|
63
|
+
getBuffer(): Uint8Array;
|
|
64
|
+
writeByte(value: number): this;
|
|
65
|
+
writeBool(value: boolean): this;
|
|
66
|
+
writeNull(): this;
|
|
67
|
+
writeInt32(value: number, signed?: boolean): this;
|
|
68
|
+
writeInt16(value: number, signed?: boolean): this;
|
|
69
|
+
writeInt8(value: number, signed?: boolean): this;
|
|
70
|
+
writeFloat(value: number): this;
|
|
71
|
+
writeDouble(value: number): this;
|
|
72
|
+
writeDate(value: number | Date): this;
|
|
73
|
+
writeString(value: string): this;
|
|
74
|
+
writeBytes(value: Uint8Array): this;
|
|
75
|
+
writeLength(value: number): this;
|
|
76
|
+
writeVector(value: Array<any>): this;
|
|
77
|
+
writeMap(object: Record<string, any>): this;
|
|
78
|
+
wireDictionary(value: string): this;
|
|
79
|
+
writeGzip(value: Uint8Array | ArrayBuffer): this;
|
|
80
|
+
encode(value: any): Uint8Array;
|
|
81
|
+
startDynamicVector(): this;
|
|
82
|
+
endDynamicVector(): this;
|
|
83
|
+
private _writeCustom;
|
|
84
|
+
writeObject(value: any): this;
|
|
85
|
+
writeObjectGzip(value: any): this;
|
|
86
|
+
private writeCore;
|
|
87
|
+
private writeRepeat;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
type EncodeHandler = (this: BinaryWriter, value: any) => void;
|
|
91
|
+
type DecodeHandler = (this: BinaryReader) => any;
|
|
92
|
+
interface TLExtension {
|
|
93
|
+
token: number;
|
|
94
|
+
encode: EncodeHandler;
|
|
95
|
+
decode: DecodeHandler;
|
|
96
|
+
}
|
|
97
|
+
declare function createExtension(token: number, { encode, decode }: {
|
|
98
|
+
encode: EncodeHandler;
|
|
99
|
+
decode: DecodeHandler;
|
|
100
|
+
}): TLExtension;
|
|
101
|
+
|
|
102
|
+
interface BinaryReaderOptions {
|
|
103
|
+
dictionary?: string[] | Dictionary;
|
|
104
|
+
extensions?: TLExtension[];
|
|
105
|
+
}
|
|
106
|
+
declare class BinaryReader {
|
|
107
|
+
private target;
|
|
108
|
+
private _last?;
|
|
109
|
+
private _lastObject?;
|
|
110
|
+
private dictionary?;
|
|
111
|
+
private dictionaryExtended;
|
|
112
|
+
private extensions;
|
|
113
|
+
private _repeat?;
|
|
114
|
+
offset: number;
|
|
115
|
+
length: number;
|
|
116
|
+
/**
|
|
117
|
+
* Small utility class to read binary data.
|
|
118
|
+
*/
|
|
119
|
+
constructor(data: Uint8Array, options?: BinaryReaderOptions);
|
|
120
|
+
readByte(): number;
|
|
121
|
+
readInt32(signed?: boolean): number;
|
|
122
|
+
readInt16(signed?: boolean): number;
|
|
123
|
+
readInt8(signed?: boolean): number;
|
|
124
|
+
/**
|
|
125
|
+
* Reads a real floating point (4 bytes) value.
|
|
126
|
+
* @returns {number}
|
|
127
|
+
*/
|
|
128
|
+
readFloat(): number;
|
|
129
|
+
/**
|
|
130
|
+
* Reads a real floating point (8 bytes) value.
|
|
131
|
+
* @returns {BigInteger}
|
|
132
|
+
*/
|
|
133
|
+
readDouble(): number;
|
|
134
|
+
/**
|
|
135
|
+
* Read the given amount of bytes, or -1 to read all remaining.
|
|
136
|
+
* @param length {number}
|
|
137
|
+
*/
|
|
138
|
+
assertRead(length: number): void;
|
|
139
|
+
assertConstructor(constructorId: CORE_TYPES): void;
|
|
140
|
+
/**
|
|
141
|
+
* Gets the byte array representing the current buffer as a whole.
|
|
142
|
+
*/
|
|
143
|
+
getBuffer(): Uint8Array;
|
|
144
|
+
readNull(): null;
|
|
145
|
+
readLength(): number;
|
|
146
|
+
readAll(): any[];
|
|
147
|
+
readBytes(): Uint8Array;
|
|
148
|
+
/**
|
|
149
|
+
* Reads encoded string.
|
|
150
|
+
*/
|
|
151
|
+
readString(): string;
|
|
152
|
+
/**
|
|
153
|
+
* Reads a boolean value.
|
|
154
|
+
*/
|
|
155
|
+
readBool(): boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Reads and converts Unix time
|
|
158
|
+
* into a Javascript {Date} object.
|
|
159
|
+
*/
|
|
160
|
+
readDate(): Date;
|
|
161
|
+
/**
|
|
162
|
+
* Reads a object.
|
|
163
|
+
*/
|
|
164
|
+
readObject(): any;
|
|
165
|
+
readObjectGzip(): any;
|
|
166
|
+
readGzip(): any;
|
|
167
|
+
private readCore;
|
|
168
|
+
getDictionaryValue(index: number): string | null;
|
|
169
|
+
readDictionary(): null | string;
|
|
170
|
+
readMap(checkConstructor?: boolean): Record<string, any>;
|
|
171
|
+
decode<T = any>(value: Uint8Array): T;
|
|
172
|
+
/**
|
|
173
|
+
* Reads a vector (a list) of objects.
|
|
174
|
+
*/
|
|
175
|
+
readVector<T = any>(checkConstructor?: boolean): T[];
|
|
176
|
+
/**
|
|
177
|
+
* Reads a vector (a list) of objects.
|
|
178
|
+
*/
|
|
179
|
+
readVectorDynamic<T>(checkConstructor?: boolean): T[];
|
|
180
|
+
/**
|
|
181
|
+
* Tells the current position on the stream.
|
|
182
|
+
*/
|
|
183
|
+
tellPosition(): number;
|
|
184
|
+
/**
|
|
185
|
+
* Sets the current position on the stream.
|
|
186
|
+
*/
|
|
187
|
+
setPosition(position: number): void;
|
|
188
|
+
/**
|
|
189
|
+
* Seeks the stream position given an offset from the current position.
|
|
190
|
+
* The offset may be negative.
|
|
191
|
+
*/
|
|
192
|
+
seek(offset: number): void;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export { type BinaryWriterOptions as B, CORE_TYPES as C, type DecodeHandler as D, type EncodeHandler as E, MAX_BUFFER_SIZE as M, type TLExtension as T, type BinaryReaderOptions as a, BinaryReader as b, BinaryWriter as c, createDictionary as d, createExtension as e };
|