Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Message Identifier in Protobug Message

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.

like image 948
Nidhoegger Avatar asked Apr 23 '26 22:04

Nidhoegger


1 Answers

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.

like image 106
jpa Avatar answered Apr 26 '26 12:04

jpa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!