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

Error when directly decoding Uint8Array #605

Closed
osechet opened this issue Jan 2, 2017 · 3 comments
Closed

Error when directly decoding Uint8Array #605

osechet opened this issue Jan 2, 2017 · 3 comments

Comments

@osechet
Copy link

osechet commented Jan 2, 2017

protobuf.js version: 6.3.1

Here is my proto message:

message Response {
    fixed32 id = 1;
    bytes data = 2;
    string error = 3;
}

When I directly decode the data sent from my server as a Uint8Array, for example:

let data = Uint8Array.from([26, 5, 69, 114, 114, 111, 114]);
let foo = Response.decode(data);

I get the following error:

TypeError: this.buf.utf8Slice is not a function
    at BufferReader.read_string_buffer [as string]
    at Function.decode

If I pass a Reader to the decode function, it works:

let data = Uint8Array.from([26, 5, 69, 114, 114, 111, 114]);
let foo = Response.decode(new Reader(data));
@dcodeIO
Copy link
Member

dcodeIO commented Jan 2, 2017

Why would you use Uint8Array.from over Buffer.from on node? Can of course be checked for, though.

@dcodeIO dcodeIO closed this as completed in 0c03f32 Jan 2, 2017
@osechet
Copy link
Author

osechet commented Jan 2, 2017

@dcodeIO This was just for the example. In my application, I'm not creating the data array, I get it from a c++ server and I receive it as a Uint8Array.

@dcodeIO
Copy link
Member

dcodeIO commented Jan 2, 2017

Alright, just note that passing an Uint8Array uses the browser reader now which doesn't benefit from node's buffer binding for strings and so on.

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

2 participants