You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
how do we use ExtensionCodec with En/Decoder classes? they dont accept an options 2nd param
even if we pass the extensionCodec in the constructor, and continue as normal, encoding fails
import{Encoder,Decoder,encode,decode,ExtensionCodec,}from"@msgpack/msgpack";// Encoder && Decoder doesnt work with extensioncodecconstextensionCodec=newExtensionCodec();constdecoder=newDecoder({ extensionCodec });constencoder=newEncoder({ extensionCodec });// Set<T>constSET_EXT_TYPE=0;// Any in 0-127extensionCodec.register({type: SET_EXT_TYPE,encode: (object: unknown): Uint8Array|null=>{if(objectinstanceofSet){// return encoder.encode([...object], { extensionCodec }); // <-- when using encode fnreturnencoder.encode([...object]);}else{returnnull;}},decode: (data: Uint8Array)=>{// const array = decoder.decode(data, { extensionCodec }) as Array<unknown>; // <-- when using decode fnconstarray=decoder.decode(data)asArray<unknown>;returnnewSet(array);},});// Map<T>constMAP_EXT_TYPE=1;// Any in 0-127extensionCodec.register({type: MAP_EXT_TYPE,encode: (object: unknown): Uint8Array=>{if(objectinstanceofMap){// return encoder.encode([...object], { extensionCodec }); // <---- when using encode fnreturnencoder.encode([...object]);}else{returnnull;}},decode: (data: Uint8Array)=>{// const array = decoder.decode(data, { extensionCodec }) as Array< // <--- when using decode fnconstarray=decoder.decode(data)asArray<[unknown,unknown]>;returnnewMap(array);},});
example log of error when using En/Decoder classes
original Map(2) {
"nirvai": Map(8) {
"updated_at": 2023-11-19T13:43:27.000Z,
"callsign": "nirvai",
"created_at": 2023-11-19T13:43:27.000Z,
"id": "15796774249725404537",
"label": "player",
"type": "org",
"created_by": "15796774249725404537",
"email": "[email protected]",
},
"knoa": Map(8) {
"updated_at": 2023-11-19T13:43:27.000Z,
"callsign": "knoa",
"created_at": 2023-11-19T13:43:27.000Z,
"id": "11806400024551464037",
"label": "player",
"type": "human",
"created_by": "15796774249725404537",
"email": "noah@ogobar",
},
}
RangeError: Extra 475 of 630 byte(s) found at buffer[155]
--> GET /v1/players 500 8ms
The text was updated successfully, but these errors were encountered:
noahehall
changed the title
Encoder / Decoder factories dont work with new ExtensionCodec() for handling Set and Map in typescript
Encoder / Decoder classes dont work with new ExtensionCodec() for handling Set and Map in typescript
Nov 19, 2023
issue:
even if we pass the extensionCodec in the constructor, and continue as normal, encoding fails
The text was updated successfully, but these errors were encountered: