@@ -20,7 +20,7 @@ export type CodecLike<Encodable, Decoded = Encodable> = {
20
20
readonly encode : ( encodable : Encodable ) => Bytes ;
21
21
readonly decode : (
22
22
decodable : BytesLike ,
23
- config ?: { compatible ?: boolean } ,
23
+ config ?: { isExtraFieldIgnored ?: boolean } ,
24
24
) => Decoded ;
25
25
readonly byteLength ?: number ;
26
26
} ;
@@ -29,7 +29,7 @@ export class Codec<Encodable, Decoded = Encodable> {
29
29
public readonly encode : ( encodable : Encodable ) => Bytes ,
30
30
public readonly decode : (
31
31
decodable : BytesLike ,
32
- config ?: { compatible ?: boolean } ,
32
+ config ?: { isExtraFieldIgnored ?: boolean } ,
33
33
) => Decoded ,
34
34
public readonly byteLength ?: number , // if provided, treat codec as fixed length
35
35
) { }
@@ -49,7 +49,7 @@ export class Codec<Encodable, Decoded = Encodable> {
49
49
}
50
50
return encoded ;
51
51
} ,
52
- ( decodable , config = { compatible : false } ) => {
52
+ ( decodable , config = { isExtraFieldIgnored : false } ) => {
53
53
const decodableBytes = bytesFrom ( decodable ) ;
54
54
if (
55
55
byteLength !== undefined &&
@@ -75,7 +75,7 @@ export class Codec<Encodable, Decoded = Encodable> {
75
75
return new Codec (
76
76
( encodable ) =>
77
77
this . encode ( ( inMap ? inMap ( encodable ) : encodable ) as Encodable ) ,
78
- ( buffer , config = { compatible : false } ) =>
78
+ ( buffer , config = { isExtraFieldIgnored : false } ) =>
79
79
( outMap
80
80
? outMap ( this . decode ( buffer , config ) )
81
81
: this . decode ( buffer , config ) ) as NewDecoded ,
@@ -388,7 +388,7 @@ export function table<
388
388
) ;
389
389
}
390
390
const byteLength = uint32From ( value . slice ( 0 , 4 ) ) ;
391
- if ( byteLength !== value . byteLength && ! config ?. compatible ) {
391
+ if ( byteLength !== value . byteLength ) {
392
392
throw new Error (
393
393
`table: invalid buffer size, expected ${ byteLength } , but got ${ value . byteLength } ` ,
394
394
) ;
@@ -408,7 +408,7 @@ export function table<
408
408
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
409
409
Object . assign ( object , { [ field ] : codec . decode ( payload , config ) } ) ;
410
410
} catch ( _e : unknown ) {
411
- if ( config ?. compatible ) {
411
+ if ( config ?. isExtraFieldIgnored ) {
412
412
Object . assign ( object , { [ field ] : null } ) ;
413
413
} else {
414
414
throw new Error ( `table.${ field } (${ _e ?. toString ( ) } )` ) ;
0 commit comments