Overview
Currently, the flatbuffers library does not have a way to validate a flatbuffer buffer once and to be able to move it around and put it into long lived structures before using the flatbuffer struct later.
The unsafe function root_unchecked lets us accomplish this, but it is difficult to reason about this unsafe function since the check may happen at a different time in program execution and it may be difficult to reason about which buffers are, or are not, validated flatbuffers.
Approach
This library exposes 3 structs:
- FlatbufferRetained ** This takes an unprefixed flatbuffer and validates it in the new function and allows a user to get the deserialized flatbuffer quickly.
- SizePrefixedFlatbufferRetained ** This takes a size-prefixed flatbuffer and validates it in the new function and allows a user to get the deserialized flatbuffer quickly.
- Retained ** This allows a user to load in either an unprefixed or size-prefixed flatbuffer and deserialize it quickly.
Example
A basic example, modified from the tutorial https://google.github.io/flatbuffers/flatbuffers_guide_tutorial.html is present in examples/basic.rs
it can be run by invoking
cargo run --example basic
An example of how this can be used to store data inside
acceleration structures may be observed here.
The test test_stored_in_map
in tests/test.rs contains a full example.