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

Decoding ArrayBuffer fails when using moreTypes #135

Closed
tsmaeder opened this issue May 10, 2024 · 1 comment
Closed

Decoding ArrayBuffer fails when using moreTypes #135

tsmaeder opened this issue May 10, 2024 · 1 comment

Comments

@tsmaeder
Copy link

The following script:

const { Packr } = require ('msgpackr');

const inst= new Packr({ moreTypes: true});

const value = {
    type: 16,
    value: new ArrayBuffer(10)
};

const serializedAsBuffer = inst.encode(value);
const data = inst.decode(serializedAsBuffer);
console.log(`object is ${JSON.stringify(data)}`);

throws an error:

Error: Could not find typed array for code 16
    at currentExtensions.<computed> (C:\Users\thomas\code\EclipseSource\theia\node_modules\msgpackr\dist\node.cjs:1056:9)
    at readExt (C:\Users\thomas\code\EclipseSource\theia\node_modules\msgpackr\dist\node.cjs:892:33)
    at read (C:\Users\thomas\code\EclipseSource\theia\node_modules\msgpackr\dist\node.cjs:339:12)
    at Array.readObject [as read] (C:\Users\thomas\code\EclipseSource\theia\node_modules\msgpackr\dist\node.cjs:522:18)
    at recordDefinition (C:\Users\thomas\code\EclipseSource\theia\node_modules\msgpackr\dist\node.cjs:992:19)
    at read (C:\Users\thomas\code\EclipseSource\theia\node_modules\msgpackr\dist\node.cjs:418:13)
    at checkedRead (C:\Users\thomas\code\EclipseSource\theia\node_modules\msgpackr\dist\node.cjs:197:13)
    at Packr.unpack (C:\Users\thomas\code\EclipseSource\theia\node_modules\msgpackr\dist\node.cjs:107:12)
    at Packr.decode (C:\Users\thomas\code\EclipseSource\theia\node_modules\msgpackr\dist\node.cjs:179:15)
    at Object.<anonymous> (C:\Users\thomas\code\EclipseSource\theia\scripts\testpack.js:11:19)

Node.js v18.17.1

When flipping moreTypes to false, the output reads:

object is {"type":16,"value":{"type":"Buffer","data":[0,0,0,0,0,0,0,0,0,0]}}
@kriszyp
Copy link
Owner

kriszyp commented May 11, 2024

Published in v1.10.2.

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