Issues using pack with Unpackr instance
turnerEP opened this issue · comments
Hi!
I have just observed this behavior:
const obj = {
hello: "world",
date: new Date(),
float: 1.23,
};
const packr = new Packr();
const unpackr = new Unpackr();
const packedWithFunc = pack(obj)
const packedWithInst = packr.pack(obj)
const unpackedFromFuncWithFunc = unpack(packedWithFunc);
const unpackedFromFuncWithInst = unpackr.unpack(packedWithFunc)
const unpackedFromInstWithFunc = unpack(packedWithInst);
const unpackedFromInstWithInst = unpackr.unpack(packedWithInst)
console.log(unpackedFromFuncWithFunc instanceof Map) // false
console.log(unpackedFromFuncWithInst instanceof Map) // true
console.log(unpackedFromInstWithFunc instanceof Map) // false
console.log(unpackedFromInstWithInst instanceof Map) // false
Is this intended behavior? The 2. unpacked value should be a literal object imo and not a Map...
Cheers!
Yes, this was intentional. I intended for the plain functions to be fully MessagePack compliant, and the constructor/instance to be used for accessing the extension functionality that defaults to be enabled from the instance (but can be turned off with useRecords: false). Maybe that wasn't a great idea, but it was intentional.