4

Is it possible to deserialize a binary flatbuffers object that represents a non-root table?

Suppose the following flatbuffers schema:

table Foo {
    ...
}
table Bar {
    value:[Foo];
}
root_type Bar;

Suppose we have access to the binary data that represents the Foo object. Is it possible to deserialize this binary to an object of class Foo? Looking at my c++ generated header file, I do not see any generated function like GetFoo().

Pejman
  • 1,328
  • 1
  • 18
  • 26

1 Answers1

6

GetFoo is just a convenience function for the declared root_type that calls GetRoot<Foo>, you can use GetRoot<Bar> to access any type as the root, assuming the buffer was constructed as such.

Aardappel
  • 5,559
  • 1
  • 19
  • 22
  • Oh, this is embarrassing. Thank you so much. Your answer prompted me to look at the documentation once again and find this comment right in the tutorial: "`GetMonster` is a convenience function that calls `GetRoot`, the latter is also available for non-root types." – Pejman Aug 12 '18 at 15:51