Skip to content

Commit 1f9f63e

Browse files
authored
Merge branch 'master' into grpc_callbackservice
2 parents 7aa060d + af4b99a commit 1f9f63e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

docs/source/languages/rust.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,34 @@ functions require a mutable (aka exclusive) reference which can only be created
177177
when no other references to the `FlatBufferBuilder` exist, and may not be copied
178178
within the same thread, let alone to a second thread.
179179

180+
## Reflection (& Resizing)
181+
182+
There is experimental support for reflection in FlatBuffers, allowing you to
183+
read and write data even if you don't know the exact format of a buffer, and
184+
even allows you to change sizes of strings in-place.
185+
186+
The way this works is very elegant; there is actually a FlatBuffer schema that
187+
describes schemas (\!) which you can find in `reflection/reflection.fbs`.
188+
The compiler, `flatc`, can write out any schemas it has just parsed as a binary
189+
FlatBuffer, corresponding to this meta-schema.
190+
191+
Loading in one of these binary schemas at runtime allows you to traverse any
192+
FlatBuffer data that corresponds to it without knowing the exact format. You
193+
can query what fields are present, and then read/write them after.
194+
195+
For convenient field manipulation, you can use the crate
196+
`flatbuffers-reflection` which includes both the generated code from the meta
197+
schema, as well as a lot of helper functions.
198+
199+
And example of usage, for the time being, can be found in
200+
`tests/rust_reflection_test/src/lib.rs`. Two sets of APIs are provided:
201+
202+
- [Unsafe getters/setters](https://docs.rs/flatbuffers-reflection/latest/flatbuffers_reflection/#functions),
203+
which you can use when you are processing trusted data (either from a source you know, or has been verified)
204+
205+
- Safe getters in [SafeBuffer](https://docs.rs/flatbuffers-reflection/latest/flatbuffers_reflection/struct.SafeBuffer.html),
206+
which does verification when constructed so you can use it for any data source
207+
180208
## Useful tools created by others
181209

182210
* [flatc-rust](https://github.com/frol/flatc-rust) - FlatBuffers compiler

0 commit comments

Comments
 (0)