The C bindings are deprecated in favor of New C++ bindings.
The new C++ bindings supports both low-level and high-level use cases, by offering two families of generated domain objects, and corresponding client and server APIs that speak those types.
std::vector, std::optional, and std::string.zx::handle to manage handle ownership.fidl::StringView) and natural type representations (e.g. std::string).zx::handle. Note that since generated structures are views of an underlying buffer, a parent structure will only own child handles if it also owns their underlying buffer. For example, a FIDL struct owns all the handles stored inline, but a FIDL vector of structs containing handles will be represented as a vector view, which will not own the out-of-line handles.Refer to the New C++ tutorial to get started.
std::vector, std::optional, and std::string.zx::handle (libzx) to manage handle ownership.std::string) to in-place buffers (e.g. as a fidl::StringView).Refer to the HLCPP tutorial to get started.
| Category | [DEPRECATED] C | New C++ with wire types | New C++ with natural types | High-level C++ |
|---|---|---|---|---|
| audience | drivers | drivers and performance-critical applications | high-level services | high-level services |
| abstraction overhead | almost zero | RAII closing of handles [1] | heap allocation, construction, destruction | heap allocation, construction, destruction |
| type safe types | enums, structs, unions | enums, structs, unions, handles, protocols | enums, structs, unions, handles, protocols | enums, structs, unions, handles, protocols |
| storage | stack | stack, user-provided buffer, or heap | heap | heap |
| lifecycle | manual free (POD) | manual or automatic free | automatic free (RAII) | automatic free (RAII) |
| receive behavior | copy | decode in-place | decode into heap | decode then move to heap |
| send behavior | copy | copy or vectorize | copy | copy |
| calling protocol methods | free functions | free functions or proxy | free functions or proxy | call through proxies, register callbacks |
| implementing protocol methods | manual dispatch or via ops table | manual dispatch or implement stub interface | implement stub interface | implement stub object, invoke callbacks |
| async client | no | yes | yes | yes |
| async server | limited [2] | yes (unbounded) [3] | yes (unbounded) [3] | yes (unbounded) |
| parallel server dispatch | no | yes [4] | yes [4] | no |
| generated code footprint | small | large | large | large |
Generated types own all handles stored inline. Out-of-line handles e.g. those behind a pointer indirection are not closed when the containing object of the pointer goes away. In those cases, the bindings provide a fidl::unstable::DecodedMessage object to manage all handles associated with a call.
The bindings library can dispatch at most one in-flight transaction.
The bindings library defined in lib/fidl can dispatch an unbounded number of in-flight transactions via fidl::BindServer defined in lib/fidl/cpp/wire/channel.h.
The bindings library lib/fidl enables parallel dispatch using the EnableNextDispatch() API defined in lib/fidl/cpp/wire/async_transaction.h.
TODO