-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
encoding small message has buffer bytelength of 8192 #852
Comments
This is because the library uses a node-like buffer pool internally. The allocated backing buffer is 8k, but byteOffset and byteLength of the returned Uint8Array point to just the relevant part of it. |
Is there a "correct" way to handle this in the browser? I've worked around it by copying it to a new Uint8Array, but that seems suboptimal. |
When working with unknown-length data, using a buffer pool has its advantages. For instance, node.js also uses one but also provides APIs that accept views (there: Of course you can also experiment with this yourself by overriding |
Makes sense. Thanks |
quick workaround to get ArrayBuffer with correct length |
I'm sure that my messages are all below 512 bytes. Does it matters if I change the pool size to 512 ? Should this be a configuration ? May 8192 cause the memery usage grow fast? |
I can confirm that @sergerusso fix with slice() works without issue. No need to call slice().buffer since XHR2 supports data views directly. This prevent the proto unmarshall errors due to the server receiving a buffer that has a bunch of trailing zeros for padding out the internal pool that protobuf.js uses. |
I'm trying to get this working on IE11 and the Anyone have an idea for a workaround? |
Does IE11 have |
The following polyfill gets around the
However, I don't think it actually works. Because when I
Without getting this thread too far off track, @dcodeIO does protobuf.js support IE11? If so I'll keep going down the rabbit hole. |
I think it should, but can't give any hard guarantees. Such errors usually appear when the data is either truncated or not encoded properly, with the latter usually happening when binary becomes somehow converted to (utf8) text. This must be avoided, i.e. by encoding the data as base64 before POSTing it, and decoding again at the receiver's end. |
I figured it out. The typedarray-slice is true polyfill implementation of |
I made my [own parser](https://github.com/intech/socket.io-cbor-x-parser) and ran into a problem when working with binary data. Reference some issue: protobufjs/protobuf.js#852
it works. Great |
Hmmm... shouldn't we expect the |
Still an issue in 2024... 🙃 Using slice() worked well for me though. |
protobuf.js version: 6.8.0
I'm encoding a very small payload and having it sent over socket io as an arraybuffer. However, for some reason, the bytelength of the underlying buffer of my encoded message is 8192, which you can see in this example (https://jsfiddle.net/fLp62wvx/1/) even though the payload is very small. Is this expected behavior?
The text was updated successfully, but these errors were encountered: