[fidl] Convert non-nullable absent vectors/strings to empty when
linearizing

The decoded form of a present but empty vector/string has been:
count set to zero; data pointer set to the next out-of-line location.
This is difficult to construct by hand.

In the C bindings, people have been using "data=nullptr, count=0" to
denote an empty vector. The C bindings translate this to the valid
decoded form i.e. "data=next-out-of-line, count=0".

For LLCPP, we would like to support sending empty vectors, while
avoiding to manually construct the "next-out-of-line" data pointer.
There are a few approaches:

1. Amend the decoded form to use a magic address/special object location
as the data pointer of a present and empty vector. For example, we could
define the decoded form of an empty vector to be
"data=0xAAAAAAAA, count=0", and modify the fidl::VectorView class to
implement this behavior. We could add a VectorView::Empty() factory
method to create vectors of this form.

Pro: Consistent handling in the walker. Using an invalid address clearly
signals that the data pointer should not be dereferenced when the count
is zero.
Con: fidl::VectorView has setter functions for data and count. Setting
count to zero would have an "action at a distance" where unexpectedly the
data pointer is reset to this special address. Overall it had been
difficult to maintain an intuitive API while ensuring the
empty-means-special-address invariant.

2. Use the FIDL linearizer to translate absent vectors to empty vectors
when the corresponding field is non-nullable.

Pro: fidl::VectorView remains a "pure data class" with no surprising
behaviors.
Con: When the field is nullable, sending "data=nullptr, count=0" would
mean an absent vector. When the field is non-nullable, sending the same
would result in an empty vector. The same object content has differing
semantics.

After weighing the approaches, I think #2 results in the least amount of
surprises in the long run.

FIDL-682 #done

Change-Id: Ic6e38173bf3b185701c44758afdaee02e161afaf
12 files changed
tree: 62168dbd994489f7cfc080920429335bce63fff0
  1. boards/
  2. build/
  3. buildtools/
  4. bundles/
  5. docs/
  6. examples/
  7. garnet/
  8. peridot/
  9. products/
  10. scripts/
  11. sdk/
  12. src/
  13. third_party/
  14. tools/
  15. zircon/
  16. .clang-format
  17. .clang-tidy
  18. .dir-locals.el
  19. .gitattributes
  20. .gitignore
  21. .gn
  22. AUTHORS
  23. BUILD.gn
  24. CODE_OF_CONDUCT.md
  25. CONTRIBUTING.md
  26. LICENSE
  27. OWNERS
  28. PATENTS
  29. README.md
  30. rustfmt.toml
README.md

Fuchsia

Pink + Purple == Fuchsia (a new operating system)

What is Fuchsia?

Fuchsia is a modular, capability-based operating system. Fuchsia runs on modern 64-bit Intel and ARM processors.

Fuchsia is an open source project with a code of conduct that we expect everyone who interacts with the project to respect.

How can I build and run Fuchsia?

See Getting Started.

Where can I learn more about Fuchsia?

See the documentation.