Search code examples
jsonserializationdeserializationflatbuffers

Create single flatbuffer for multiple json files or concatenate the multiple flatbuffers created from the jsons


I am trying to create a single flatbuffer from my multiple json files, using the flatc compiler, we can create a single flatbuffer from a json file, as given in the example Json with flatbuffers.

#json file example.
{
  pos: {
    x: 1,
    y: 2,
    z: 3
  },
  hp: 300,
  name: "Orc"
}

#from the command line
$./../flatc -b monster.fbs monsterdata.json

I've looked at the documentation given by google on flatbuffers and cannot figure out how to make a single flatbuffer. I also checked out the following google-groups link but couldn't comprehend much, and also to this github link

Would be great if someone can help me create a single flatbuffer from my multiple json files, also are flatbuffers meant to be created for single json objects or singular data?


Solution

  • You can't do that automatically. You'll need to specify exactly how you want those multiple buffers are supposed to be represented in the schema, e.g.

    table Monsters { monsters:[Monster]; }
    root_type Monsters;
    

    Where Monster is the type of just one of your JSON files. Then you concatenate all JSON files, with { monsters: [ prefixed, ] } postfixed, and , in between.