I am evaluating using Flat Buffers on a project where I have need for a message bus between processes (Nanomsg).
There are many types of messages on the bus. Those that need certain data can grab it.
What I am trying to figure out is the best way to map it.
With the root_type table, I can map a series of items and use the (id:) to help match them up.
I can have a message type filed that would help on the decode.
The main question is, should the main table have a content field that would be a union of structures for the various types of message?
So, if I have
enum MessageType: byte { None = 0,
Msg1 = 1,
...
Msg10 = 10,
}
table Msg1Struct
{
var1: short;
var2: long;
}
table Msg2Struct
{
var3: bool;
var4: float;
}
... the reset of the tables
union Message { Msg1Struct, Msg2Struct, ....}
table MessageBus
{
MsgType:MessageType (id:0);
Packet: Message (id:1);
}
root_type MessageBus
Would this work that if a task receives a message, it looks at MsgType to cast the Packet structure and
each table type would be serialized properly?
Flat Buffers has worked well on some simpler case project work, but I'm trying to figure out the best way to handle the more complex setup.
A big thank you to whoever can help on this topic.
Thanks!