kriszyp / msgpackr

Ultra-fast MessagePack implementation with extension for record and structural cloning / msgpack.org[JavaScript/NodeJS]

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Decoding ArrayBuffer fails when using `moreTypes`

tsmaeder opened this issue · comments

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]}}

Published in v1.10.2.