Appending in FlatBuffer

181 Views Asked by At

We already are using a flatbuffer with a similar scheme

namespace potter;

union Magic { Weapon, Wand }

table Weapon {
   name:string;     
   power:int; 
}

table Wand {
   make:string;
   animal:string;
}

table MagicHolder {   
    name:string;   
    age:int;    
    magic:Magic; 
}

root_type MagicHolder;

Now, if we want to add two things.

  1. level:string in the MagicHolder
  2. Under the Wand a key:value type, where key:string, and value can be either string or int or float or bool

What I’m trying is

table MagicHolder {   
    name:string;   
    age:int; 
    level:string; /*new addition*/  
    magic:Magic; 
}

table KeyValue {
   key:string;  
   vint:int; 
   vfloat:float; 
   vbool:bool; 
   vstring:string;
   vtype:string; /* since I cannot differentiate between bool set or not, trying to store type here */
}

table Wand {
   make:string;
   animal:string;
   kv:KeyValue;  
}

Is this the best approach? What would be the pros/cons.. Any other recommended ways to do this new additions more efficiently

0

There are 0 best solutions below