File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import {isFloat32} from '../../util/buffers/isFloat32';
2
2
import { JsonPackExtension } from '../JsonPackExtension' ;
3
3
import { CborEncoderFast } from './CborEncoderFast' ;
4
4
import type { IWriter , IWriterGrowable } from '../../util/buffers' ;
5
+ import { JsonPackValue } from '../JsonPackValue' ;
5
6
6
7
export class CborEncoder < W extends IWriter & IWriterGrowable = IWriter & IWriterGrowable > extends CborEncoderFast < W > {
7
8
/**
@@ -35,6 +36,9 @@ export class CborEncoder<W extends IWriter & IWriterGrowable = IWriter & IWriter
35
36
return this . writeMap ( value as Map < unknown , unknown > ) ;
36
37
case JsonPackExtension :
37
38
return this . writeTag ( ( < JsonPackExtension > value ) . tag , ( < JsonPackExtension > value ) . val ) ;
39
+ case JsonPackValue :
40
+ const buf = ( value as JsonPackValue ) . val ;
41
+ return this . writer . buf ( buf , buf . length ) ;
38
42
default :
39
43
return this . writeUnknown ( value ) ;
40
44
}
Original file line number Diff line number Diff line change 1
1
import { Writer } from '../../../util/buffers/Writer' ;
2
+ import { JsonPackValue } from '../../JsonPackValue' ;
2
3
import { CborEncoder } from '../CborEncoder' ;
3
4
import { decode } from 'cbor' ;
4
5
@@ -398,3 +399,15 @@ describe('tokens (simple values)', () => {
398
399
testJsTokens ( null ) ;
399
400
testJsTokens ( undefined ) ;
400
401
} ) ;
402
+
403
+ describe ( 'JsonPackValue' , ( ) => {
404
+ test ( 'can encode pre-packed value' , ( ) => {
405
+ const internal = encoder . encode ( { foo : 'bar' } ) ;
406
+ const val = new JsonPackValue ( internal ) ;
407
+ const data = { boo : [ 1 , val , 2 ] } ;
408
+ const encoded = encoder . encode ( data ) ;
409
+ expect ( decode ( encoded ) ) . toEqual ( {
410
+ boo : [ 1 , { foo : 'bar' } , 2 ] ,
411
+ } ) ;
412
+ } ) ;
413
+ } ) ;
You can’t perform that action at this time.
0 commit comments