-
Notifications
You must be signed in to change notification settings - Fork 75
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
Is it possible to just decode specific parts of a message? #1052
Comments
I'm not aware of any API in ts-proto that would allow you to parse messages one field at a time. You can split your message definition. For example: message MyResponseFoos {
repeated Foo foos = 1;
}
message MyResponseBars {
repeated Bar bars = 2;
}
message MyResponseBazs {
repeated Baz bazs = 3;
} Then parse the response data with each message in subsequently. Optionally, create a When you parse |
@timostamm Thank you. That was also a potential solution I considered. In the end, I took out all binary data from the message (which took up almost 50% the size) and instead appended them to the response body. Before:Protobuf:message Foo {
bytes data = 1;
}
message MyResponse {
repeated Foo foos = 1;
repeated Bar bars = 2;
repeated Baz bazs = 3;
} Body:
After:Protobuf:message Foo {
uint64 length = 1;
}
message MyResponse {
repeated Foo foos = 1;
repeated Bar bars = 2;
repeated Baz bazs = 3;
} Body:
This way, I can read the first Admittedly, the |
Our API works by sending a serialized protobuf in the request/response body. No gRPC involved. We have a mobile app that is mainly a web view (using Capacitor). One of our endpoints has begun to return a large response (~30 MB). In turns out that iOS' WebKit has a longtime bug where, if the memory usage spikes, it can crash. So, when we attempt to deserialize the response body, the web view crashes.
We're discussing many potential solutions. One solution could be, if we could decode certain parts of a message at a time, we can avoid a large memory spike.
For example, consider the following message:
Is there a way to just decode one-or-more fields at a time?
Note that we use ts-proto on top of protobuf-es.
The text was updated successfully, but these errors were encountered: