Skip to content

[FeatureRequest] More type out of box #182

Open
@loynoir

Description

@loynoir

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions