tree: 538097be3af23dd5cef07ab3e1d2192ca6abecdd [path history] [tgz]
  1. client/
  2. client_sync/
  3. client_thread_safety/
  4. domain_objects/
  5. request_pipelining/
  6. server/
  7. server_async_completer/
  8. services/
  9. BUILD.gn
  10. README.md
examples/fidl/cpp/README.md

New C++ FIDL bindings examples

This directory contains example code for using the new C++ bindings.

To use the unified bindings for a library //examples/fidl/fuchsia.examples, declare the following dependency:

deps = [
    "//examples/fidl/fuchsia.examples:fuchsia.examples_cpp",
]

and include the following header:

#include <fidl/fuchsia.examples/cpp/fidl.h>

Client example

To run the client example, run the echo_realm component. This creates the client and server component instances and routes the capabilities:

ffx component run /core/ffx-laboratory:echo_realm fuchsia-pkg://fuchsia.com/echo-cpp-client#meta/echo_realm.cm

Then, we can start the echo_client instance:

ffx component start /core/ffx-laboratory:echo_realm/echo_client

The server component starts when the client attempts to connect to the Echo protocol. You should see the following output using fx log:

[echo_server][I] Running echo server
[echo_server][I] Incoming connection for fuchsia.examples.Echo
[echo_client][I] (Natural types) got response: hello
[echo_client][I] (Natural types) got response: hello
[echo_client][I] (Wire types) got response: hello
[echo_server][W] server error: FIDL endpoint was unbound due to peer closed, status: ZX_ERR_PEER_CLOSED (-24)