@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.
@@ -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 };