bin-serde 1.4.0 → 1.4.2
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 +18 -10
- package/lib/index.d.ts +1 -1
- package/lib/index.js +17 -10
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -105,7 +105,6 @@ export class Writer {
|
|
|
105
105
|
|
|
106
106
|
public writeStringAscii(val: string) {
|
|
107
107
|
if (val.length === 0) {
|
|
108
|
-
this.writeUInt8(0);
|
|
109
108
|
return this;
|
|
110
109
|
}
|
|
111
110
|
this.ensureSize(val.length);
|
|
@@ -115,16 +114,25 @@ export class Writer {
|
|
|
115
114
|
return this;
|
|
116
115
|
}
|
|
117
116
|
|
|
118
|
-
public writeStringUtf8(val: string) {
|
|
119
|
-
if (
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
117
|
+
public writeStringUtf8(val: string, len?: number) {
|
|
118
|
+
if (len != null) {
|
|
119
|
+
if (len === 0) {
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
this.ensureSize(len);
|
|
123
123
|
pack(val, this.bytes, this.pos);
|
|
124
|
-
this.pos +=
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
this.pos += len;
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
if (val.length === 0) {
|
|
128
|
+
this.writeUVarint(0);
|
|
129
|
+
return this;
|
|
127
130
|
}
|
|
131
|
+
const byteSize = utf8Size(val);
|
|
132
|
+
this.writeUVarint(byteSize);
|
|
133
|
+
this.ensureSize(byteSize);
|
|
134
|
+
pack(val, this.bytes, this.pos);
|
|
135
|
+
this.pos += byteSize;
|
|
128
136
|
return this;
|
|
129
137
|
}
|
|
130
138
|
|
|
@@ -225,7 +233,7 @@ export class Reader {
|
|
|
225
233
|
}
|
|
226
234
|
|
|
227
235
|
public readStringUtf8(len?: number) {
|
|
228
|
-
if (len
|
|
236
|
+
if (len == null) {
|
|
229
237
|
len = this.readUVarint();
|
|
230
238
|
}
|
|
231
239
|
if (len === 0) {
|
package/lib/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare class Writer {
|
|
|
11
11
|
writeFloat(val: number): this;
|
|
12
12
|
writeBits(bits: boolean[]): this;
|
|
13
13
|
writeStringAscii(val: string): this;
|
|
14
|
-
writeStringUtf8(val: string): this;
|
|
14
|
+
writeStringUtf8(val: string, len?: number): this;
|
|
15
15
|
writeBuffer(buf: Uint8Array): this;
|
|
16
16
|
toBuffer(): Uint8Array;
|
|
17
17
|
private ensureSize;
|
package/lib/index.js
CHANGED
|
@@ -92,7 +92,6 @@ export class Writer {
|
|
|
92
92
|
}
|
|
93
93
|
writeStringAscii(val) {
|
|
94
94
|
if (val.length === 0) {
|
|
95
|
-
this.writeUInt8(0);
|
|
96
95
|
return this;
|
|
97
96
|
}
|
|
98
97
|
this.ensureSize(val.length);
|
|
@@ -101,17 +100,25 @@ export class Writer {
|
|
|
101
100
|
}
|
|
102
101
|
return this;
|
|
103
102
|
}
|
|
104
|
-
writeStringUtf8(val) {
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
103
|
+
writeStringUtf8(val, len) {
|
|
104
|
+
if (len != null) {
|
|
105
|
+
if (len === 0) {
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
this.ensureSize(len);
|
|
109
109
|
pack(val, this.bytes, this.pos);
|
|
110
|
-
this.pos +=
|
|
110
|
+
this.pos += len;
|
|
111
|
+
return this;
|
|
111
112
|
}
|
|
112
|
-
|
|
113
|
-
this.
|
|
113
|
+
if (val.length === 0) {
|
|
114
|
+
this.writeUVarint(0);
|
|
115
|
+
return this;
|
|
114
116
|
}
|
|
117
|
+
const byteSize = utf8Size(val);
|
|
118
|
+
this.writeUVarint(byteSize);
|
|
119
|
+
this.ensureSize(byteSize);
|
|
120
|
+
pack(val, this.bytes, this.pos);
|
|
121
|
+
this.pos += byteSize;
|
|
115
122
|
return this;
|
|
116
123
|
}
|
|
117
124
|
writeBuffer(buf) {
|
|
@@ -198,7 +205,7 @@ export class Reader {
|
|
|
198
205
|
return val;
|
|
199
206
|
}
|
|
200
207
|
readStringUtf8(len) {
|
|
201
|
-
if (len
|
|
208
|
+
if (len == null) {
|
|
202
209
|
len = this.readUVarint();
|
|
203
210
|
}
|
|
204
211
|
if (len === 0) {
|