Is there a way to get something like an ID for a protobuf message.
E.g. I have:
syntax = "proto3";
package protobuf;
message parameters_t
{
string audio_device = 1;
}
message master_t
{
enum type_t
{
unknown = 0;
login_rsp = 1;
}
type_t type = 1;
}
What I want to do in C++ is send the size over the wire, then some ID of the message and the the buffer.
E.g. paramters_t is ID 0 (statically accessible) and master_t is ID 1, so I can do in my code:
if (id == protobuf::master_t::id) {
...
}
else if (id == protobuf::paramters_t::id) {
...
}
Is there any way to achieve this without manually assigning the values? I want that to be set in the protofile somehow. It can be a constant I define myself, i dont care.
A typical way is to just define an enum:
enum MsgId {
MSGID_MASTER = 0;
MSGID_PARAMETERS = 1;
}
You can then access them in C++ like constants.
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