I have a flatbuffers question I was hoping I could get some help with.
I am trying to use flatbuffers to form up a command buffer that looks similar to the following:
+------------+------------+------------+------------+------------+
| Cmd 1 | Cmd 2 | Cmd 3 | Cmd 4 | Cmd 5 |
| Type x | Type x | Type y | Type z | Type y |
+------------+------------+------------+------------+------------+
The flatbuffers schema I currently have is:
// Complete command buffer. It is made up of one or more individual commands
table CommandBuffer {
cmd_array: [Command];
}
// Individual commands, these are placed in the command buffer. A single command
// can only have one of the listed command type fields populated.
table Command {
cmd_x: CmdXType;
cmd_y: CmdYType;
cmd_z: CmdZType;
}
table CmdXType {
field_x_1: ubyte;
field_x_2: short;
field_x_3: string;
}
table CmdYType {
field_y_1: ubyte;
field_y_2: string;
}
table CmdZType {
field_z_1: ubyte;
field_z_2: [ubyte];
}
Whilst I currently have this working, I feel that using a union instead of a table of tables might be a neater solution to this problem. Does that sound correct?
If this is correct, I've had a lot of problems getting it working and would greatly appreciate some help from the flatbuffers community on what the serialisation and de-serialisation code should look like? I've tried using the test code provided with flatbuffers to achieve this, but to no avail.
Thanks in advance for any help people can provide.
Cheers,
Brian