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

Serializing stream to binary. #595

Open
singerxt opened this issue Oct 24, 2023 · 2 comments
Open

Serializing stream to binary. #595

singerxt opened this issue Oct 24, 2023 · 2 comments

Comments

@singerxt
Copy link

Hello!

I have a React application that uses msw.js for mocking requests. I'm able to to knock simple responses by serializing proto message. However things are getting complicating when the response is stream and I'm unable to find any method which would be helpful to serialize array of objects to binary which I could use as response body.

Do you know how I can serialize objects to stream?

For reference proto file looks like this.

syntax = "proto3"

message Point {
  int32 latitude = 1;
  int32 longitude = 2;
}

service RouteGuide {
   rpc streamPoints() returns (stream Point) {}
}
@timostamm
Copy link
Owner

I assume you're using gRPC-web? It encodes messages and final trailers in the response body with a simple framing described in the spec.

protobuf-ts implements reading messages and a final trailer from a response body (here), but it only implements encoding a single message for a request body (here), because that's the only required case for clients.

To mock a gRPC-web response with MSW, a couple of parts are missing:

  • encoding trailers following the spec, with at least grpc-status and grpc-message fields
  • encoding 0 or more messages to support unary and server-streaming RPCs
  • conditionally base64 encoding the body based on the request content-type (only for the gRPC-web text encoding)

I do not have the spare time to implement those parts, but with a bit of patience, it's definitely doable 🙂

@singerxt
Copy link
Author

singerxt commented Oct 25, 2023

@timostamm Thank you!

Do you think that kind feature should part of your library? If so I'm more then happy to work on it.

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