msgpack-javascript icon indicating copy to clipboard operation
msgpack-javascript copied to clipboard

feat: add undefinedAsNil option to Encoder

Open eberlitz opened this issue 5 months ago • 0 comments
trafficstars

Closes #150

Adds a new option to Encoder that is true by default ( to keep current behaviour). With this flag when ignoreUndefined is false, allows to distinguish null from undefined. It requires a custom extension to send undefined like :

extensionCodec.register({
    type: 0,
    encode: (value) => (value === undefined ? new Uint8Array([0]) : null),
    decode: () => undefined,
});

I also found another implementation (msgpackr) implements this as fixint 1 type 0 data 0, but I guess the consumer can decide in his custom extension

eberlitz avatar Jun 12 '25 10:06 eberlitz