bin-serde 1.3.0 → 1.4.1
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 +24 -2
- package/lib/index.d.ts +4 -2
- package/lib/index.js +22 -2
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -103,7 +103,18 @@ export class Writer {
|
|
|
103
103
|
return this;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
public
|
|
106
|
+
public writeStringAscii(val: string) {
|
|
107
|
+
if (val.length === 0) {
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
this.ensureSize(val.length);
|
|
111
|
+
for (let i = 0; i < val.length; i++) {
|
|
112
|
+
this.view.setUint8(this.pos++, val.charCodeAt(i));
|
|
113
|
+
}
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public writeStringUtf8(val: string) {
|
|
107
118
|
if (val.length > 0) {
|
|
108
119
|
const byteSize = utf8Size(val);
|
|
109
120
|
this.writeUVarint(byteSize);
|
|
@@ -201,7 +212,18 @@ export class Reader {
|
|
|
201
212
|
return bits;
|
|
202
213
|
}
|
|
203
214
|
|
|
204
|
-
public
|
|
215
|
+
public readStringAscii(len: number) {
|
|
216
|
+
if (len === 0) {
|
|
217
|
+
return "";
|
|
218
|
+
}
|
|
219
|
+
let val = "";
|
|
220
|
+
for (let i = 0; i < len; i++) {
|
|
221
|
+
val += String.fromCharCode(this.view.getUint8(this.pos++));
|
|
222
|
+
}
|
|
223
|
+
return val;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
public readStringUtf8(len?: number) {
|
|
205
227
|
if (len === undefined) {
|
|
206
228
|
len = this.readUVarint();
|
|
207
229
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -10,7 +10,8 @@ export declare class Writer {
|
|
|
10
10
|
writeVarint(val: number): this;
|
|
11
11
|
writeFloat(val: number): this;
|
|
12
12
|
writeBits(bits: boolean[]): this;
|
|
13
|
-
|
|
13
|
+
writeStringAscii(val: string): this;
|
|
14
|
+
writeStringUtf8(val: string): this;
|
|
14
15
|
writeBuffer(buf: Uint8Array): this;
|
|
15
16
|
toBuffer(): Uint8Array;
|
|
16
17
|
private ensureSize;
|
|
@@ -27,7 +28,8 @@ export declare class Reader {
|
|
|
27
28
|
readVarint(): number;
|
|
28
29
|
readFloat(): number;
|
|
29
30
|
readBits(numBits: number): boolean[];
|
|
30
|
-
|
|
31
|
+
readStringAscii(len: number): string;
|
|
32
|
+
readStringUtf8(len?: number): string;
|
|
31
33
|
readBuffer(numBytes: number): Uint8Array;
|
|
32
34
|
remaining(): number;
|
|
33
35
|
}
|
package/lib/index.js
CHANGED
|
@@ -90,7 +90,17 @@ export class Writer {
|
|
|
90
90
|
}
|
|
91
91
|
return this;
|
|
92
92
|
}
|
|
93
|
-
|
|
93
|
+
writeStringAscii(val) {
|
|
94
|
+
if (val.length === 0) {
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
this.ensureSize(val.length);
|
|
98
|
+
for (let i = 0; i < val.length; i++) {
|
|
99
|
+
this.view.setUint8(this.pos++, val.charCodeAt(i));
|
|
100
|
+
}
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
writeStringUtf8(val) {
|
|
94
104
|
if (val.length > 0) {
|
|
95
105
|
const byteSize = utf8Size(val);
|
|
96
106
|
this.writeUVarint(byteSize);
|
|
@@ -176,7 +186,17 @@ export class Reader {
|
|
|
176
186
|
this.pos += numBytes;
|
|
177
187
|
return bits;
|
|
178
188
|
}
|
|
179
|
-
|
|
189
|
+
readStringAscii(len) {
|
|
190
|
+
if (len === 0) {
|
|
191
|
+
return "";
|
|
192
|
+
}
|
|
193
|
+
let val = "";
|
|
194
|
+
for (let i = 0; i < len; i++) {
|
|
195
|
+
val += String.fromCharCode(this.view.getUint8(this.pos++));
|
|
196
|
+
}
|
|
197
|
+
return val;
|
|
198
|
+
}
|
|
199
|
+
readStringUtf8(len) {
|
|
180
200
|
if (len === undefined) {
|
|
181
201
|
len = this.readUVarint();
|
|
182
202
|
}
|