I understand how to use the FlatBufferBuilder
and specific type builder (e.g., MyNestedTableBuilder
) to get the WIPOffset
and then use that to get the finished_data
buffer (&[u8]
). I then have been using get_root
to get an object based on the buffer, so now I have an instance of MyNestedTable
. Then I need to pass that to another function and create a new table instance via a new builder, MyTable
, that has the field add_my_nested_table
. I cannot see how to do this without unpacking MyNestedTable
and rebuilding it again (which seems very inefficient). I am sure there is a good way to do this, I just haven't found it, even after studying the generated code and API.
Generally we have a need to pass objects around and reuse them, over the network or via API calls in Rust.
MyNestedTable
isn't really an object, it is a handle to data inside the serialized data (your [u8]
), and any field accesses look up this data on the fly.
None of the base APIs for any of the FlatBuffers supported languages (including Rust) have code generated that allows automatic re-serializing, since that is not a frequent operation in most use cases (you already have the serialized data).
The way to do it is through the optional "object API", supported in C++ and some other languages, but not yet in Rust. As you can see, CasperN is working on such an API.
Until then, you may consider using nested_flatbuffer
or some other construct to directly pass the serialized data to wherever it needs to go.