Files
flatbuffers/docs/source/CUsage.md
2016-03-26 09:22:56 +01:00

2.2 KiB

Use in C

The C language binding exists in a separate project named FlatCC.

The flatcc C schema compiler can generate code offline as well as online via a C library. It can also generate buffer verifiers and fast JSON parsers, printers.

Great effort has been made to ensure compatibily with the main flatc project.

General Documention

Basic Reflection

The C-API does support reading binary schema (.bfbs) files via code generated from the reflection.fbs schema, and an example usage shows how to use this. The schema files are pre-generated in the runtime distribution.

Mutating Reflection

The C-API does not support mutating reflection like C++ does.

Although the following isn't reflection, it is possible to create new buffers using complex objects from existing buffers as source. This can be very efficient due to direct copy semantics without endian conversion or temporary stack allocation.

Scalars, structs and strings can be used as source, as well vectors of these.

It is currently not possible to use an existing table or vector of table as source, but it would be possible to add support for this at some point. Vectors of strings

Why not integrate with the flatc tool?

It was considered how the C code generator could be integrated into the flatc tool, but it would either require that the standalone C implementation of the schema compiler was dropped, or it would lead to excessive code duplication, or a complicated intermediate representation would have to be invented. Neither of these alternatives are very attractive, and it isn't a big deal to use the flatcc tool instead of flatc given that the FlatBuffers C runtime library needs to be made available regardless.