I’m trying to serialize data, which is specified by the following protobuf file:
message Response {
enum Status {OK = 0; ERROR = 1;};
Status status = 1; // Always present
string errMsg = 2;
uint64 shortest_path_length = 3; // [mm]
uint64 total_length = 4; // [mm]
}
I need to create a Response
, that has only the status field filled out with the OK
variant, the encoded_len()
function returns 0. To me, this seems, that the default values of the message are ignored by the encoder, which is understandable, it wants to minimize the message size. But what if I want to send just a message with a single default field? In thate case, the message size amounts to zero and no message is encoded.
Is there a way around this nonsense? Note that I cannot edit the .proto specification file.
I’ve tried using just the ERROR
variant of the status enum, and that returned a valid, non-zero encoded_len()
, but I also need to serialize to OK
variant.
1