Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FeatureRequest] More type out of box #182

Open
loynoir opened this issue Jun 16, 2021 · 2 comments
Open

[FeatureRequest] More type out of box #182

loynoir opened this issue Jun 16, 2021 · 2 comments

Comments

@loynoir
Copy link

loynoir commented Jun 16, 2021

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;
@loynoir loynoir changed the title [FeatureRequest] better type guard [FeatureRequest] More type out of box Aug 1, 2021
@loynoir
Copy link
Author

loynoir commented Aug 1, 2021

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

@kefniark
Copy link

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.

makiuchi-d added a commit to KLab/wsnet2 that referenced this issue Feb 17, 2023
Fixes #24.


一部TypedArrayがサポートされてないため、msgpack通信を無効化しました([参考](msgpack/msgpack-javascript#182
-
[msgpack-lite](https://www.npmjs.com/package/msgpack-lite)の方がサポートされてるTypeは多いようですが、パッケージが古い(6年〜)・decodeAsyncがサポートされてないなどの理由で不採用。
- カスタム拡張を自作することで対応できそうですが、時間がかかる・frontend/backend両方実装する必要があると難易度が高い。

その他変更点まとめ:
- `npm audit fix`でdashboardの依存パッケージ脆弱性を修正
- M1Macでも動けるよう、`docker-compose.yml`に`platform`指定を追加
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants