msgpack-javascript
msgpack-javascript copied to clipboard
[FeatureRequest] More type out of box
Background
Migrate from msgpack-lite
, which has support for many types out of box.
And I had a look at types at @msgpack/msgpack/dist/encode.d.ts
,
seems everything is also OK out-of-box.
export declare function encode<ContextType = undefined>(
// seems everything is OK out-of-box
value: unknown,
options?: EncodeOptions<SplitUndefined<ContextType>>
): Uint8Array;
Reproduce
var msgpack=require('@msgpack/msgpack')
var nop=x=>msgpack.decode(msgpack.encode(x))
Actual
> nop({x:Buffer.from('x'), y:new ArrayBuffer(0), z:new Error('msg')})
{ x: Uint8Array(1) [ 120 ], y: {}, z: {} }
Expected
> msgpack = require('msgpack-lite')
> nop({x:Buffer.from('x'), y:new ArrayBuffer(0), z:new Error('msg')})
{
x: <Buffer 78>,
y: ArrayBuffer { [Uint8Contents]: <>, byteLength: 0 },
z: Error: msg
}
Suggestion
export declare function encode<ContextType = undefined>(
value: unknown,
options?: EncodeOptions<SplitUndefined<ContextType>>
): Uint8Array;
export declare function encodeOutOfBox<ContextType = undefined>(
// any types are tested, `decode(encode(value))` should be same out of box
value: TESTED_TYPES,
options?: EncodeOptions<SplitUndefined<ContextType>>
): Uint8Array;
Hi, @gfx
Are there any plans to support more types out of box in the future?
Are there any plans to transplant 24 types supported by msgpack-lite
, which haven't updated since 2016?
https://github.com/kawanet/msgpack-lite/blob/master/lib/ext-packer.js
https://github.com/kawanet/msgpack-lite/blob/master/lib/ext-unpacker.js
Same there, been migrating a project from msgpack-lite
, and the lack of TypedArray was really annoying to deal with.
Took me some time to figure why it mostly worked but only some fields were ExtData.
So I end up writing my own codec extension and finally it works (my data is backward compatible with the one previously generated with msgpack-lite
).
But the process was really annoying and time consuming, for basic JS types like Uint8Array
and Int32Array
.
So 👍 to get more types, even if its only as an optional typedarray
extension code.