bin-serde 1.6.4 → 1.6.5
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/index.ts +8 -2
- package/lib/index.d.ts +2 -1
- package/lib/index.js +7 -2
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -224,11 +224,10 @@ export class Writer {
|
|
|
224
224
|
export class Reader {
|
|
225
225
|
private pos = 0;
|
|
226
226
|
private bytes: Uint8Array;
|
|
227
|
-
private
|
|
227
|
+
private _view: DataView | null = null; // lazily allocated
|
|
228
228
|
|
|
229
229
|
constructor(buf: Uint8Array) {
|
|
230
230
|
this.bytes = buf;
|
|
231
|
-
this.view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
232
231
|
}
|
|
233
232
|
|
|
234
233
|
readUInt8() {
|
|
@@ -315,4 +314,11 @@ export class Reader {
|
|
|
315
314
|
remaining() {
|
|
316
315
|
return this.bytes.length - this.pos;
|
|
317
316
|
}
|
|
317
|
+
|
|
318
|
+
private get view(): DataView {
|
|
319
|
+
if (!this._view) {
|
|
320
|
+
this._view = new DataView(this.bytes.buffer, this.bytes.byteOffset);
|
|
321
|
+
}
|
|
322
|
+
return this._view;
|
|
323
|
+
}
|
|
318
324
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export declare class Writer {
|
|
|
22
22
|
export declare class Reader {
|
|
23
23
|
private pos;
|
|
24
24
|
private bytes;
|
|
25
|
-
private
|
|
25
|
+
private _view;
|
|
26
26
|
constructor(buf: Uint8Array);
|
|
27
27
|
readUInt8(): number;
|
|
28
28
|
readUInt16(): number;
|
|
@@ -35,4 +35,5 @@ export declare class Reader {
|
|
|
35
35
|
readStringUtf8(len?: number): string;
|
|
36
36
|
readBuffer(numBytes: number): Uint8Array;
|
|
37
37
|
remaining(): number;
|
|
38
|
+
private get view();
|
|
38
39
|
}
|
package/lib/index.js
CHANGED
|
@@ -199,10 +199,9 @@ export class Writer {
|
|
|
199
199
|
export class Reader {
|
|
200
200
|
pos = 0;
|
|
201
201
|
bytes;
|
|
202
|
-
|
|
202
|
+
_view = null; // lazily allocated
|
|
203
203
|
constructor(buf) {
|
|
204
204
|
this.bytes = buf;
|
|
205
|
-
this.view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
206
205
|
}
|
|
207
206
|
readUInt8() {
|
|
208
207
|
return this.bytes[this.pos++];
|
|
@@ -278,4 +277,10 @@ export class Reader {
|
|
|
278
277
|
remaining() {
|
|
279
278
|
return this.bytes.length - this.pos;
|
|
280
279
|
}
|
|
280
|
+
get view() {
|
|
281
|
+
if (!this._view) {
|
|
282
|
+
this._view = new DataView(this.bytes.buffer, this.bytes.byteOffset);
|
|
283
|
+
}
|
|
284
|
+
return this._view;
|
|
285
|
+
}
|
|
281
286
|
}
|