I guess it's a bit of a unique scenario in our case... the issue is we have an old type that has two possible fields (ie: explicitly named field1 and field2) , and we're replacing it with a new type that has n-possible fields (ie: a list). the old data is still valid as the new ones as on load we deserialize field1 and field2 into a 2-element list, but we want to not write the old type anymore.
the current solution is to name the old field "deprecated_old_field_do_not_use" which I think kind of gets the point across ( :) ), and I think I can live with, but I was thinking it would be good to make sure that no builders were available for it.
table T1S { buf:[ubyte] (nested_flatbuffer: T1); }
(and then make T2's refer to T1S
I have a type
table foo { obj: [ubyte]; }
where the contents of obj are Yet Another Flatbuffer. with the rust library is there any way to force the embedded bytes of obj
to be aligned to the minimum necessary for the flatbuffer library?
right now it seems like it's getting minimum u8 alignment, and when-all-the-stars-align and I do something like flatbuffers::size_prefixed_root(foo_instance.obj())
I get an error that my object is unaligned
I have a usage-related question.
This is my schema
namespace Client;
enum Gender:byte {Female = 0, Male = 1}
enum Type:byte {Person = 0, Group = 1}
table Person
{
name: string;
age: short;
weight: double;
gender: Gender; // Enum
}
table Group
{
group_name: string;
average_age: double;
average_weight: double;
names: [string];
}
union Foo {Person, Group}
table Data
Now I have to store multiple Persons or Groups in a single flatbuffer
FinishSizePrefix()
useful in this case, I can't find much documentation about it or any example.
C++
and reading it in Python
Person
which has name
, age
...
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.