How can we convert the msgpack-encoded str back to the origin info
meloalright opened this issue · 2 comments
meloalright commented
const encoded = encode({ name: 'abcde' });
const str = new util.TextDecoder().decode(encoded);
console.log(str) // ��name�abcde
// Then the str has been send to another service using rpc
// How can we convert the msgpack-encoded str back to the origin infocc00010 commented
Hey @meloalright ! You should first decode it using the function msgpack.decode ( not TextDecoder's decode ):
const { encode, decode } = require('@msgpack/msgpack');
const encoded = encode({ name: 'abcde' });
const decoded = decode(encoded);
console.log(decoded.name); // `decoded` is an object
// the output will be 'abcde'Here's the definition of decode:
decode(buffer: ArrayLike<number> | BufferSource, options?: DecodeOptions): unknownmeloalright commented
Easy question..
Thanks