Reputation: 25
I am building an UDP messaging system with Protocol Buffers. I have several messages (e.g. ChannelUpdate, MessageCreate, ACK). If I send a message to the remote, how can I also send what type of message I am sending?
Upvotes: 1
Views: 190
Reputation: 1064294
Your best bet is to always send the same message type: a root message that has one of the others. For example:
message SomeRoot {
oneof content {
ChannelUpdate channelUpdate = 1;
MessageCreate msgCreate = 2;
// etc
}
}
Now you're using an inbuilt protocol feature to enforce the logic.
Upvotes: 2