bin-serde 1.4.1 → 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 -9
- package/lib/index.d.ts +1 -1
- package/lib/index.js +17 -9
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -114,16 +114,25 @@ export class Writer {
|
|
|
114
114
|
return this;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
public writeStringUtf8(val: string) {
|
|
118
|
-
if (
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
117
|
+
public writeStringUtf8(val: string, len?: number) {
|
|
118
|
+
if (len != null) {
|
|
119
|
+
if (len === 0) {
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
this.ensureSize(len);
|
|
122
123
|
pack(val, this.bytes, this.pos);
|
|
123
|
-
this.pos +=
|
|
124
|
-
|
|
125
|
-
|
|
124
|
+
this.pos += len;
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
if (val.length === 0) {
|
|
128
|
+
this.writeUVarint(0);
|
|
129
|
+
return this;
|
|
126
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;
|
|
127
136
|
return this;
|
|
128
137
|
}
|
|
129
138
|
|
|
@@ -224,7 +233,7 @@ export class Reader {
|
|
|
224
233
|
}
|
|
225
234
|
|
|
226
235
|
public readStringUtf8(len?: number) {
|
|
227
|
-
if (len
|
|
236
|
+
if (len == null) {
|
|
228
237
|
len = this.readUVarint();
|
|
229
238
|
}
|
|
230
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
|
@@ -100,17 +100,25 @@ export class Writer {
|
|
|
100
100
|
}
|
|
101
101
|
return this;
|
|
102
102
|
}
|
|
103
|
-
writeStringUtf8(val) {
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
103
|
+
writeStringUtf8(val, len) {
|
|
104
|
+
if (len != null) {
|
|
105
|
+
if (len === 0) {
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
this.ensureSize(len);
|
|
108
109
|
pack(val, this.bytes, this.pos);
|
|
109
|
-
this.pos +=
|
|
110
|
+
this.pos += len;
|
|
111
|
+
return this;
|
|
110
112
|
}
|
|
111
|
-
|
|
112
|
-
this.
|
|
113
|
+
if (val.length === 0) {
|
|
114
|
+
this.writeUVarint(0);
|
|
115
|
+
return this;
|
|
113
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;
|
|
114
122
|
return this;
|
|
115
123
|
}
|
|
116
124
|
writeBuffer(buf) {
|
|
@@ -197,7 +205,7 @@ export class Reader {
|
|
|
197
205
|
return val;
|
|
198
206
|
}
|
|
199
207
|
readStringUtf8(len) {
|
|
200
|
-
if (len
|
|
208
|
+
if (len == null) {
|
|
201
209
|
len = this.readUVarint();
|
|
202
210
|
}
|
|
203
211
|
if (len === 0) {
|