Skip to content

Error when directly decoding Uint8Array #605

@osechet

Description

@osechet

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));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions