参考资料:
国外最早教FlatBuffer使用的家伙。
https://medium.freecodecamp.com/why-consider-flatbuffer-over-json-2e4aa8d4ed07#.g0li3oki8
Windows 7 64位 cmake 安装
https://cmake.org/download/
FlatBuffer 源码
https://github.com/google/flatbuffers
步骤:
1 下载源代码
2 编译出flatc ,执行文件。用于翻译你的描述文件。
3 编写对应描述文件,翻译成对应语言的类。把对应的类, 放到你的工程中。
英文步骤:
How to start with flatBuffer
- $ git clone https://github.com/google/flatbuffers.git
- $ cd flatbuffers
Run the command on the basis of your platform
- $ cmake -G “Unix Makefiles”
- $ cmake -G “Visual Studio 10”
- $ cmake -G “Xcode”
now build for your platform as usual. This should result in a flatc executable
Now create your schema file with extension .fbs. Guide to write a schema can be found here.And also have your sample json file.
- $ ./flatc -j -b schema.fbs sample.json
This will create few java file and one bin file. Java files are like model(POJO for flatBuffer) of your json.Place the java files in your application package and bin file in raw folder(bin file is only for testing as it is converted to byte that is to be passed to flatbuffer for testing).