You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a use case where I send a few values and a chuck of bytes to JavaScript using msgpack. Most libraries (including msgpackr) try to unpack the data with as little copying as possible. Therefore, the chunk of bytes is unpacked as a Uint8Array which actually is just a view of the entire message with an offset (I could ask msgpackr to copy the data into a newly allocated array, but I try to avoid copying).
The chuck of bytes are actually 16-bit values, so I want convert it (still using the same original data) using new Uint16Array(msg.data.buffer, msg.data.byteOffset).
However, this doesn't work for my message, because the offset happens to be odd in this specific message and JS requires it to be divisible by 2 (as I'm asking for 16-bit values). I manually introduced new items in my dictionary where I tweaked the string lengths to shift the chunk of bytes to an appropriate alignment, but that feels wrong.
Does the msgpack format have something like a padding value (ideally a single byte) which could by used by packers to shift data to preferred byte alignments?
I know that msgpack is all about the smallest message size, but being able to add a single byte (or two or three) could save you a lot of copying on the receiver side.
The text was updated successfully, but these errors were encountered:
No official padding support but you could misuse Nil (0xc0) for that purpose.
Be sure to document it well if any 3rd party is to be consuming or providing the content :-)
I have a use case where I send a few values and a chuck of bytes to JavaScript using msgpack. Most libraries (including msgpackr) try to unpack the data with as little copying as possible. Therefore, the chunk of bytes is unpacked as a
Uint8Array
which actually is just a view of the entire message with an offset (I could ask msgpackr to copy the data into a newly allocated array, but I try to avoid copying).The chuck of bytes are actually 16-bit values, so I want convert it (still using the same original data) using
new Uint16Array(msg.data.buffer, msg.data.byteOffset)
.However, this doesn't work for my message, because the offset happens to be odd in this specific message and JS requires it to be divisible by 2 (as I'm asking for 16-bit values). I manually introduced new items in my dictionary where I tweaked the string lengths to shift the chunk of bytes to an appropriate alignment, but that feels wrong.
Does the msgpack format have something like a padding value (ideally a single byte) which could by used by packers to shift data to preferred byte alignments?
I know that msgpack is all about the smallest message size, but being able to add a single byte (or two or three) could save you a lot of copying on the receiver side.
The text was updated successfully, but these errors were encountered: