Skip to content

protobuf bytes -> Uint8Array #137

Description

@td-krzysiek

Hello,

I’m exploring the option of using Rust + WebAssembly to speed up protobuf parsing. Everything works very well except for generating the output types. I explored two main options:

  1. Returning the Rust object directly
#[wasm_bindgen]
pub fn parse(bytes: Vec<u8>) -> Result<ProtobufObject, JsValue> {
}

but this results in:

the trait bound `Result<ProtobufObject, wasm_bindgen::JsValue>: ReturnWasmAbi` is not satisfied
the trait `ReturnWasmAbi` is not implemented for `Result<ProtobufObject, wasm_bindgen::JsValue>
  1. Generating types using the TypeScript library (ts-proto)
    --ts_proto_opt=onlyTypes=true
    --ts_proto_opt=useJsonWireFormat=true
    --ts_proto_opt=forceLong=string
    --ts_proto_opt=useOptionals=all
    --ts_proto_opt=esModuleInterop=true

Here I was able to get almost compatible output, but protobuf bytes are generated as a base64 string by prost-serde and as Uint8Array by ts-proto. I can’t see an option to force either library to use the other format.

Is there any standard way to handle this kind of issue? Ideally, if the types could be generated automatically from the return type, that would be the best solution. Alternatively, the option to return a Uint8Array instead of a string would also be useful.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions