@@ -148,10 +148,10 @@ export class Encoder {
148
148
const ext = this . extensionCodec . tryToEncode ( object ) ;
149
149
if ( ext != null ) {
150
150
this . encodeExtension ( ext ) ;
151
- } else if ( ArrayBuffer . isView ( object ) ) {
152
- this . encodeBinary ( object ) ;
153
151
} else if ( Array . isArray ( object ) ) {
154
152
this . encodeArray ( object , depth ) ;
153
+ } else if ( ArrayBuffer . isView ( object ) ) {
154
+ this . encodeBinary ( object ) ;
155
155
} else if ( typeof object === "object" ) {
156
156
this . encodeMap ( object as Record < string , unknown > , depth ) ;
157
157
} else {
@@ -263,7 +263,8 @@ export class Encoder {
263
263
writeU8 ( value : number ) {
264
264
this . ensureBufferSizeToWrite ( 1 ) ;
265
265
266
- this . view . setUint8 ( this . pos ++ , value ) ;
266
+ this . view . setUint8 ( this . pos , value ) ;
267
+ this . pos ++ ;
267
268
}
268
269
269
270
writeU8v ( ...values : ReadonlyArray < number > ) {
@@ -280,62 +281,56 @@ export class Encoder {
280
281
writeI8 ( value : number ) {
281
282
this . ensureBufferSizeToWrite ( 1 ) ;
282
283
283
- this . view . setInt8 ( this . pos ++ , value ) ;
284
+ this . view . setInt8 ( this . pos , value ) ;
285
+ this . pos ++ ;
284
286
}
285
287
286
288
writeU16 ( value : number ) {
287
289
this . ensureBufferSizeToWrite ( 2 ) ;
288
290
289
- const pos = this . pos ;
291
+ this . view . setUint16 ( this . pos , value ) ;
290
292
this . pos += 2 ;
291
- this . view . setUint16 ( pos , value ) ;
292
293
}
293
294
294
295
writeI16 ( value : number ) {
295
296
this . ensureBufferSizeToWrite ( 2 ) ;
296
297
297
- const pos = this . pos ;
298
+ this . view . setInt16 ( this . pos , value ) ;
298
299
this . pos += 2 ;
299
- this . view . setInt16 ( pos , value ) ;
300
300
}
301
301
302
302
writeU32 ( value : number ) {
303
303
this . ensureBufferSizeToWrite ( 4 ) ;
304
304
305
- const pos = this . pos ;
305
+ this . view . setUint32 ( this . pos , value ) ;
306
306
this . pos += 4 ;
307
- this . view . setUint32 ( pos , value ) ;
308
307
}
309
308
310
309
writeI32 ( value : number ) {
311
310
this . ensureBufferSizeToWrite ( 4 ) ;
312
311
313
- const pos = this . pos ;
312
+ this . view . setInt32 ( this . pos , value ) ;
314
313
this . pos += 4 ;
315
- this . view . setInt32 ( pos , value ) ;
316
314
}
317
315
318
316
writeF64 ( value : number ) {
319
317
this . ensureBufferSizeToWrite ( 8 ) ;
320
318
321
- const pos = this . pos ;
319
+ this . view . setFloat64 ( this . pos , value ) ;
322
320
this . pos += 8 ;
323
- this . view . setFloat64 ( pos , value ) ;
324
321
}
325
322
326
323
writeU64 ( value : number ) {
327
324
this . ensureBufferSizeToWrite ( 8 ) ;
328
325
329
- const pos = this . pos ;
326
+ encodeUint64 ( value , this . view , this . pos ) ;
330
327
this . pos += 8 ;
331
- encodeUint64 ( value , this . view , pos ) ;
332
328
}
333
329
334
330
writeI64 ( value : number ) {
335
331
this . ensureBufferSizeToWrite ( 8 ) ;
336
332
337
- const pos = this . pos ;
333
+ encodeInt64 ( value , this . view , this . pos ) ;
338
334
this . pos += 8 ;
339
- encodeInt64 ( value , this . view , pos ) ;
340
335
}
341
336
}
0 commit comments