forked from BigfootDev/flatbuffers
Support native_type for tables when using the C++ object API. (#8668)
* Support native_type for tables when using the C++ object API. If native_type is specified on a table: - No object API struct type is generated. - The object API refers to the table by its native_type. - UnPack and Create<TableName> methods are declared but not defined; as they must be user-provided. * Add tests for native_type on tables. * Add documentation for native_type on tables.
This commit is contained in:
@@ -242,6 +242,41 @@ provide the following functions to aide in the serialization process:
|
||||
}
|
||||
```
|
||||
|
||||
- `native_type("type")` (on a table): Tables can also be represented with
|
||||
native types. For example, the following schema:
|
||||
|
||||
```cpp
|
||||
table Matrix (native_type: "NativeMatrix") {
|
||||
rows: int32;
|
||||
columns: int32;
|
||||
values: [float];
|
||||
}
|
||||
```
|
||||
|
||||
Would be represented by a user-defined C++ class:
|
||||
|
||||
```cpp
|
||||
class NativeMatrix { ... }
|
||||
```
|
||||
|
||||
In this case, the following function declarations are generated by the compiler.
|
||||
The user must provide and link the matching function definitions:
|
||||
|
||||
```cpp
|
||||
struct Matrix FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
// ...
|
||||
|
||||
static ::flatbuffers::Offset<Matrix> Pack(
|
||||
::flatbuffers::FlatBufferBuilder& _fbb,
|
||||
const NativeMatrix* _o,
|
||||
const ::flatbuffers::rehasher_function_t* _rehasher = nullptr);
|
||||
|
||||
void UnPackTo(
|
||||
NativeMatrix* _o,
|
||||
const ::flatbuffers::resolver_function_t* _resolver = nullptr) const;
|
||||
}
|
||||
```
|
||||
|
||||
Finally, the following top-level attributes:
|
||||
|
||||
- `native_include("path")` (at file level): Because the `native_type` attribute
|
||||
|
||||
Reference in New Issue
Block a user