Is there an efficient technique to batch different Protobuf events while sending over HTTP?
The goal is to have a list of multi-type Protobuf messages in one request. One idea I have is to separate messages in small arrays and specify their type to be able to deserialize them on the server.
You can use some Any
message type combined with repeated
, as follows:
message Any {
string type_url = 1;
bytes value = 2;
}
message Envelope {
repeated Any events = 1;
}
Then, in your code:
type_url
according to the message type that you serialize in value
type_url
to know which type is contained in value
, and deserialize accordinglyThe example above reproduces the google/protobuf/any
, that is documented here:
https://developers.google.com/protocol-buffers/docs/proto3#any
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With