Skip to content

Commit 969d890

Browse files
Add documentation for native_type on tables.
1 parent 036d43a commit 969d890

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

docs/source/languages/cpp.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,40 @@ provide the following functions to aide in the serialization process:
242242
}
243243
```
244244

245+
- `native_type("type")` (on a table): Tables can also be represented with
246+
native types. For example, the following schema:
247+
248+
```cpp
249+
table Matrix {
250+
rows: int32;
251+
columns: int32;
252+
values: [float];
253+
}
254+
```
255+
256+
Could be represented by a user-defined C++ class:
257+
258+
```cpp
259+
class Matrix { ... }
260+
```
261+
262+
In this case, the following function declarations are generated by the compiler.
263+
The user must provide and link the matching function definitions:
264+
265+
```cpp
266+
struct Matrix FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
267+
// ...
268+
void UnPackTo(
269+
Native::Matrix *_o,
270+
const ::flatbuffers::resolver_function_t *_resolver = nullptr) const;
271+
}
272+
273+
::flatbuffers::Offset<Matrix> CreateMatrix(
274+
::flatbuffers::FlatBufferBuilder &_fbb,
275+
const NativeMatrixType *_o,
276+
const ::flatbuffers::rehasher_function_t *_rehasher = nullptr);
277+
```
278+
245279
Finally, the following top-level attributes:
246280
247281
- `native_include("path")` (at file level): Because the `native_type` attribute
@@ -419,7 +453,7 @@ Each root type will have a verification function generated for it,
419453
e.g. for `Monster`, you can call:
420454
421455
```cpp
422-
Verifier verifier(buf, len);
456+
Verifier verifier(buf, len);
423457
bool ok = VerifyMonsterBuffer(verifier);
424458
```
425459

0 commit comments

Comments
 (0)