Skip to content
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

A field with type 'bytes' is decoded into an empty array instead of an empty buffer #1012

Open
assaf-xm opened this issue Apr 11, 2018 · 3 comments

Comments

@assaf-xm
Copy link
Contributor

protobuf.js version: 6.8.6

Any empty 'bytes' field on a message, will be decoded into an empty javascript array.
The expected behavior is that it will be decoded into an empty buffer, in order to keep consistency with the case the field has data.

  • in protobuf js v5 it was decoded into an empty buffer.
@metled
Copy link

metled commented Apr 15, 2018

function toObject(message, options) {
...
    if (message.bytesField != null && message.hasOwnProperty("bytesField"))
        options.bytes === String ? $util.base64.encode(message.bytesField, 0, message.bytesField.length) : options.bytes === Array ? Array.prototype.slice.call(message.bytesField) : message.bytesField

@assaf-xm
Copy link
Contributor Author

Both 'decode' and 'toObject' return the field as an empty array. So the root cause might be on the 'decode' implementation.
I'm using 'toObjcet' without setting the 'bytes' option (I don't want it base64 or an array, I want it to be kept as Buffer).

@Amitcoh1
Copy link

close it please as it's already merged 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants