'how to convert flatbuffer .fbs file to .bin file

i am learning flatbuffers in java I want to create a .bin file from .fbs file and I don't have .json file already how do i create a json file so that I can create a bin file?

as they already had mosterdata.json file in thier sample code but what if we don't have the JSON file? and we just had the .fbs file and it's generated java code only? as mentioned here how will i get the data file ?



Solution 1:[1]

There are two ways to make your .bin file.

  1. Use JSON to specify the contents.

    flatc -b <your_schema.fbs> <your_data.json>
    

    Where -b means generate a binary file.

    To make your_data.json you'll have to make it yourself, using your_schema.fbs to guide you on how to specify the json fields. I would check out how the monsterdata_test.json is specified by its corresponding schema monster_test.fbs

  1. Use flatc to output the Java code gen, and then programmatically generate the .bin using the generated code.

    flatc --java <your_schema.fbs>
    

    This way is a lot more involved, since you have to make a program that uses the generated code and output the binary yourself. Check out the tutorial (switch to the java language) for example usage.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Moop