I have basic knowledge of file streams in C ++ and Google FlatBuffers . The schema file is quite simple, a buffer is also created and read from the buffer pointer. What I am not getting is to save several buffers to a binary, and then read this binary to get an arbitrary buffer.
Here is a simple diagram with two arrays of floats:
table Car { field_a:[float]; field_b:[float]; }
.
Function for creating a buffer (although without saving the file):
bool save_flatbuf(string file_path, vector<double> vec_a, vector<double> vec_b) { flatbuffers::FlatBufferBuilder builder; auto vec_floats_a = builder.CreateVector(vec_a, vec_a.size()); auto vec_floats_b = builder.CreateVector(vec_b, vec_b.size()); auto mloc = CreateCar(builder, &vec_floats_a, &vec_floats_b); builder.Finish(mloc);
.
And the function to read the buffer after reading it from a binary file (without reading the file):
bool read_flatbuf(string file_path) {
Not sure if access to buffer information is correct. For example, a way to get the length of the fields in an array.
Code examples for interacting with a file (writing / reading several buffers in one file) are welcome.
c ++ serialization binaryfiles fstream flatbuffers
Davinish
source share