flatbuffers::FlatBufferBuilder builder(1024);
// Create Person.
WritePerson0(builder);
// Create Group.
WritePerson(builder);
// Getting ready to the write buffer to a file.
uint8_t *buf = builder.GetBufferPointer();
int size = builder.GetSize();
// Writing to a file.
std::ofstream writer("fb_bytes.bin", std::ios::binary);
writer.write((char*)buf, size);
writer.close();
Persons
like this
with open("fb_bytes.bin", "rb") as f:
buf = f.read()
foo = Client.Person.Person.GetRootAs(buf)
print(foo.Name().decode('utf-8'), end = ", ")
print(str(foo.Age()), end = ", ")
print(str(foo.Weight()))
buf = buf[48:]
foo0 = Client.Person.Person.GetRootAs(buf1)
print(foo0.Name().decode('utf-8'), end = ", ")
print(str(foo0.Age()), end = ", ")
print(str(foo0.Weight()))
len()
by writing only one Person
and thus sliced the buf
Persons
auto pName = builder.CreateString("BiasdasdgFoot");
auto pAge = 91;
auto pWeight = 123.5;
auto Person = CreatePerson(builder, pName, pAge, pWeight, Gender_Male);
// builder.FinishSizePrefixed(Person);
builder.Finish(Person);
Person
without using vector?Person
and keep appending to the file?
Finish
once.asserts
are off.
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=DEBUG
builder.Clear()
and reusing it.
flatc
for this use case, maybe by writing a plugin for it?
flatc
is able to write out a binary version of a parsed schema.. using FlatBuffers itself! This data is perfect for writing external code generators. You can easily read this data in any language that FlatBuffers already supports. The option is --bfbs
I believe, and the schema for the data is in reflection/
.. see also some github issues where we talk more about using this for external code generators @dbaileychess