Skip to content

Commit c6fb376

Browse files
zstewar1gnoliyil
authored andcommitted
[fidl][docs] Update Wire* type docs
Update the docs for the new C++ bindings to indicate that fidl::WireRequest and fidl::WireEvent are type aliases, and refer to fidl::WireResult instead of fidl::WireResponse (which is mostly not user-visible). Provide a clearer description of what is available in fidl::WireResult. Change-Id: Ie95f46b67090d7d3e92712e0903035b3f6197872 Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/773625 Reviewed-by: Yifei Teng <yifeit@google.com> Commit-Queue: Zachary Stewart <zstewart@google.com>
1 parent c0e5467 commit c6fb376

File tree

1 file changed

+46
-18
lines changed

1 file changed

+46
-18
lines changed

docs/reference/fidl/bindings/cpp-bindings.md

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -439,31 +439,59 @@ server.
439439

440440
See the class documentation on these types for more details.
441441

442-
### Request and response structs {#request-response-structs}
442+
### Request and response types {#request-response-structs}
443443

444-
FIDL generates a type for each request, response, and event in the protocol by
445-
treating the parameters as struct fields. For example, the `MakeMoveRequest` is
446-
generated as if it were a struct with two fields: `uint8 row`, and `uint8 col`,
447-
providing the same generated code API as [regular structs](#structs):
448-
449-
```c++
450-
struct MakeMoveRequest final {
451-
uint8_t row;
452-
uint8_t col;
453-
}
454-
```
455-
456-
For this example, the following types are generated:
444+
The request type for a FIDL method or event can be accessed through a pair of
445+
aliases, `fidl::WireRequest` and `fidl::WireEvent`:
457446

458447
* `fidl::WireRequest<TicTacToe::StartGame>`
459448
* `fidl::WireRequest<TicTacToe::MakeMove>`
460-
* `fidl::WireResponse<TicTacToe::MakeMove>`
461449
* `fidl::WireEvent<TicTacToe::OnOpponentMove>`
462450

463-
The naming scheme for requests is `[Method]Request`. The naming scheme for
464-
responses is `[Method]Response`. The naming scheme for events is `[Method]Event`.
451+
If the type used for the request or event is a named type, the alias will point
452+
to that type. If the request type was an anonymous type, the alias will point to
453+
the type name generated for that anonymous type. For both method requests and
454+
events, the generated request type is named `[Method]Request`.
455+
456+
Unlike requests, responses to two-way methods are generated as a new type,
457+
`fidl::WireResult`:
458+
459+
* `fidl::WireResult<TicTacToe::MakeMove>`
460+
461+
The `fidl::WireResult` type inherits from `fidl::Status`, and its status tells
462+
whether the call succeeded at the FIDL layer. If the method has a non-empty
463+
response or uses FIDL error syntax, the generated `WireResult` type will also
464+
have a set of accessors for accessing the return value or application-layer
465+
error. The available accessors for the contained result are:
466+
467+
* `WireResultUnwrapType<FidlMethod>* Unwrap()`
468+
* `const WireResultUnwrapType<FidlMethod>* Unwrap() const`
469+
* `WireResultUnwrapType<FidlMethod>& value()`
470+
* `const WireResultUnwrapType<FidlMethod>& value() const`
471+
* `WireResultUnwrapType<FidlMethod>* operator->()`
472+
* `const WireResultUnwrapType<FidlMethod>* operator->() const`
473+
* `WireResultUnwrapType<FidlMethod>& operator*()`
474+
* `const WireResultUnwrapType<FidlMethod>& operator*() const`
475+
476+
The `WireResultUnwrapType` is another type alias, which depends on whether the
477+
method uses error syntax. Given this example library,
478+
479+
```fidl
480+
library response.examples;
481+
482+
protocol Test {
483+
Foo() -> (struct { x int32; });
484+
Bar() -> () error int32;
485+
Baz() -> (struct { x int32; }) error int32;
486+
};
487+
```
488+
489+
here is what the `fidl::WireResultUnwrapType` is for each method in the `Test`
490+
protocol:
465491

466-
Any empty request, response, or event is represented by a `nullptr`.
492+
* `fidl::WireResultUnwrapType<response_examples::Test::Foo> = response_examples::wire::TestFooResponse`
493+
* `fidl::WireResultUnwrapType<response_examples::Test::Bar> = fit::result<int32_t>`
494+
* `fidl::WireResultUnwrapType<response_examples::Test::Baz> = fit::result<int32_t, ::response_examples::wire::TestBazResponse*>`
467495

468496
### Client {#client}
469497

0 commit comments

Comments
 (0)