pw-js-world 0.2.1-dev.ee2fd11 → 0.3.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.
@@ -0,0 +1,330 @@
1
+ /**
2
+ * CREDIT: Anatoly for making this Buffer Reader so I don't have to!
3
+ * Source: https://github.com/Anatoly03/pixelwalker.js/blob/9bb3c7e39a45006086a2abae8c515599bd3db835/src/util/buffer-reader.ts
4
+ * License: ISC
5
+ */
6
+ /**
7
+ * Data during the communication in the process is dynamic
8
+ * typed. Every entry is followed by a byte identifying the
9
+ * type, followed by data. The type header is noted by its'
10
+ * 7-bit notation.
11
+ */
12
+ export declare enum ComponentTypeHeader {
13
+ String = 0,
14
+ Byte = 1,
15
+ Int16 = 2,
16
+ Int32 = 3,
17
+ Int64 = 4,
18
+ Float = 5,
19
+ Double = 6,
20
+ Boolean = 7,
21
+ ByteArray = 8,
22
+ UInt32 = 9
23
+ }
24
+ /**
25
+ * A Buffer reader is a special buffer extension made to perform
26
+ * game-specific tasks in the field of communication.
27
+ *
28
+ * @implements Buffer
29
+ */
30
+ export default class BufferReader {
31
+ private buffer;
32
+ private offset;
33
+ /**
34
+ *
35
+ */
36
+ private constructor();
37
+ /**
38
+ *
39
+ */
40
+ static from(from: Uint8Array | Buffer): BufferReader;
41
+ /**
42
+ *
43
+ */
44
+ static alloc(amount: number): BufferReader;
45
+ /**
46
+ * @param {string} value
47
+ * @returns {Buffer}
48
+ */
49
+ static String(value?: string): Buffer;
50
+ /**
51
+ * @param {number} value
52
+ * @returns {Buffer}
53
+ */
54
+ static Byte(value?: number): Buffer;
55
+ /**
56
+ * @param {number} value
57
+ * @returns {Buffer}
58
+ */
59
+ static Int16(value?: number): Buffer;
60
+ /**
61
+ * @param {number} value
62
+ * @returns {Buffer}
63
+ */
64
+ static Int32(value?: number): Buffer;
65
+ /**
66
+ * @param {bigint} value
67
+ * @returns {Buffer}
68
+ */
69
+ static Int64(value?: bigint): Buffer;
70
+ /**
71
+ * @param {number} value
72
+ * @returns {Buffer}
73
+ */
74
+ static Float(value?: number): Buffer;
75
+ /**
76
+ * @param {number} value
77
+ * @returns {Buffer}
78
+ */
79
+ static Double(value?: number): Buffer;
80
+ /**
81
+ * @param {boolean} value
82
+ * @returns {Buffer}
83
+ */
84
+ static Boolean(value?: boolean): Buffer;
85
+ /**
86
+ * @param {Uint8Array} buffer
87
+ * @returns {Buffer}
88
+ */
89
+ static ByteArray(buffer?: Buffer): Buffer;
90
+ /**
91
+ * @param {number} value
92
+ * @returns {Buffer}
93
+ */
94
+ static UInt32(value?: number): Buffer;
95
+ /**
96
+ * @param {number} value
97
+ * @returns {Buffer}
98
+ */
99
+ static Magic(value: number): Buffer;
100
+ /**
101
+ * @param {number} value
102
+ * @returns {Buffer}
103
+ */
104
+ static Bit7(value?: number): Buffer;
105
+ /**
106
+ * @param tt
107
+ * @param value
108
+ */
109
+ static Dynamic(tt: ComponentTypeHeader, value: boolean | number | bigint | string | Buffer): Buffer;
110
+ /**
111
+ *
112
+ */
113
+ get length(): number;
114
+ /**
115
+ *
116
+ */
117
+ subarray(start?: number, end?: number): BufferReader;
118
+ /**
119
+ *
120
+ */
121
+ write(value: string): number;
122
+ /**
123
+ *
124
+ */
125
+ writeBigInt64BE(value: bigint): number;
126
+ /**
127
+ *
128
+ */
129
+ writeBigInt64LE(value: bigint): number;
130
+ /**
131
+ *
132
+ */
133
+ writeUInt8(value: number): number;
134
+ /**
135
+ *
136
+ */
137
+ writeUInt16LE(value: number): number;
138
+ /**
139
+ *
140
+ */
141
+ writeUInt16BE(value: number): number;
142
+ /**
143
+ *
144
+ */
145
+ writeUInt32LE(value: number): number;
146
+ /**
147
+ *
148
+ */
149
+ writeUInt32BE(value: number): number;
150
+ /**
151
+ *
152
+ */
153
+ writeInt8(value: number): number;
154
+ /**
155
+ *
156
+ */
157
+ writeInt16LE(value: number): number;
158
+ /**
159
+ *
160
+ */
161
+ writeInt16BE(value: number): number;
162
+ /**
163
+ *
164
+ */
165
+ writeInt32LE(value: number): number;
166
+ /**
167
+ *
168
+ */
169
+ writeInt32BE(value: number): number;
170
+ /**
171
+ *
172
+ */
173
+ writeFloatLE(value: number): number;
174
+ /**
175
+ *
176
+ */
177
+ writeFloatBE(value: number): number;
178
+ /**
179
+ *
180
+ */
181
+ writeDoubleLE(value: number): number;
182
+ /**
183
+ *
184
+ */
185
+ writeDoubleBE(value: number): number;
186
+ /**
187
+ *
188
+ */
189
+ readBigUInt64BE(): bigint;
190
+ /**
191
+ *
192
+ */
193
+ readBigUInt64LE(): bigint;
194
+ /**
195
+ *
196
+ */
197
+ readBigInt64BE(): bigint;
198
+ /**
199
+ *
200
+ */
201
+ readBigInt64LE(): bigint;
202
+ /**
203
+ *
204
+ */
205
+ expectUInt8(value: number): number;
206
+ /**
207
+ *
208
+ */
209
+ readUInt8(): number;
210
+ /**
211
+ *
212
+ */
213
+ readUInt16LE(): number;
214
+ /**
215
+ *
216
+ */
217
+ readUInt16BE(): number;
218
+ /**
219
+ *
220
+ */
221
+ readUInt32LE(): number;
222
+ /**
223
+ *
224
+ */
225
+ readUInt32BE(): number;
226
+ /**
227
+ *
228
+ */
229
+ readInt8(): number;
230
+ /**
231
+ *
232
+ */
233
+ readInt16LE(): number;
234
+ /**
235
+ *
236
+ */
237
+ readInt16BE(): number;
238
+ /**
239
+ *
240
+ */
241
+ readInt32LE(): number;
242
+ /**
243
+ *
244
+ */
245
+ readInt32BE(): number;
246
+ /**
247
+ *
248
+ */
249
+ readFloatLE(): number;
250
+ /**
251
+ *
252
+ */
253
+ readFloatBE(): number;
254
+ /**
255
+ *
256
+ */
257
+ readDoubleLE(): number;
258
+ /**
259
+ *
260
+ */
261
+ readDoubleBE(): number;
262
+ read(tt: ComponentTypeHeader, littleEndian?: boolean): string | number | bigint | boolean | Buffer;
263
+ read(tt: ComponentTypeHeader.String, littleEndian?: boolean): string;
264
+ read(tt: ComponentTypeHeader.Byte, littleEndian?: boolean): number;
265
+ read(tt: ComponentTypeHeader.Int16, littleEndian?: boolean): number;
266
+ read(tt: ComponentTypeHeader.Int32, littleEndian?: boolean): number;
267
+ read(tt: ComponentTypeHeader.Int64, littleEndian?: boolean): bigint;
268
+ read(tt: ComponentTypeHeader.Float, littleEndian?: boolean): number;
269
+ read(tt: ComponentTypeHeader.Double, littleEndian?: boolean): number;
270
+ read(tt: ComponentTypeHeader.Boolean, littleEndian?: boolean): boolean;
271
+ read(tt: ComponentTypeHeader.ByteArray, littleEndian?: boolean): Buffer;
272
+ /**
273
+ *
274
+ */
275
+ toBuffer(): Buffer;
276
+ /**
277
+ * https://stackoverflow.com/questions/8609289/convert-a-binary-nodejs-buffer-to-javascript-arraybuffer
278
+ */
279
+ toArrayBuffer(): ArrayBuffer;
280
+ /**
281
+ *
282
+ */
283
+ at(idx: number): number;
284
+ /**
285
+ * Advanced the buffer reader by pffset.
286
+ */
287
+ advanceOffset(relativeOffset?: number): this;
288
+ /**
289
+ * This function reads how many bytes a normal integer would take
290
+ * as a 7-bit number
291
+ *
292
+ * 1(000 0001) 0(111 1110)
293
+ */
294
+ static length7BitInt(value: number): number;
295
+ /**
296
+ * Reads in an integer in 7-bit notation. A 7-bit integer
297
+ * encoding splits a number into a variable size of bits,
298
+ * in which the first bit is set while bytes are following.
299
+ *
300
+ * @example
301
+ *
302
+ * ```
303
+ * 1111 0000 1010 1010 1000 0000 0000 0001 Reading In
304
+ * ^--- ---- ^--- ---- ^--- ---- ^--- ----
305
+ * 111 0000 010 1010 000 0000 000 0001 Writing Out
306
+ * ```
307
+ */
308
+ read7BitInt(): number;
309
+ /**
310
+ * Write a normal integer value into buffer at offset.
311
+ */
312
+ write7BitInt(value: number): void;
313
+ /**
314
+ * Reads a dynamic buffer which is prepended by its' length
315
+ * in 7-bit encoding.
316
+ */
317
+ readDynamicBuffer(): Buffer<ArrayBufferLike>;
318
+ /**
319
+ * Append a buffer to the current buffer. Asserts the cursor
320
+ * to be at the end of the current buffer.
321
+ */
322
+ append(buffer: Buffer): this;
323
+ /**
324
+ * Keep Deserializing the buffer for typed data until
325
+ * you reach the end of the buffer. Typed data consists
326
+ * of a type indicator in 7-bit-encoding and data following
327
+ * accordingly.
328
+ */
329
+ deserialize(): (string | number | bigint | boolean | Buffer<ArrayBufferLike>)[];
330
+ }