tree: f7a7be699f3427ab07372654003f17a93691bf79 [path history] [tgz]
  1. build/
  2. fidl/
  3. meta/
  4. test/
  5. BUILD.gn
  6. fidl_types.cc
  7. fidl_types.h
  8. hex_dump.cc
  9. hex_dump.h
  10. indent.cc
  11. indent.h
  12. OWNERS
  13. README.md
  14. zx_types.cc
  15. zx_types.h
src/lib/fostr/README.md

fostr: Output Formatting

fostr is an ostream formatting library that provides the following:

  • support for indented formatting (indent.h)
  • hex dumps (hex_dump.h)
  • formatting for public/lib/fidl types (fidl_types.h)
  • formatting for zircon zx:: types (zx_types.h)
  • generated formatting for FIDL types

fostr is not part of the Fuchsia SDK.

FIDL type formatting

Currently, structs, tables, unions, arrays, vectors, and enums can be formatted. Support for formatting serialized messages is also intended.

To use an existing formatter for FIDL types (say, for fuchsia.foo), add the dependency to your BUILD.gn file, which will look like this:

//src/lib/fostr/fidl/fuchsia.foo

Includes look like this:

#include "src/lib/fostr/fidl/fuchsia/foo/formatting.h"

Adding a new FIDL library is pretty simple: just add a new fostr/fidl/xxx subdirectory with a BUILD.gn (see existing files for an example). The target must depend on the fostr/fidl targets for the libraries on which xxx depends. This means you may have to add formatting support for libraries that your FIDL library depends on.

If you have hand-rolled formatters for a library, they can be accommodated. Look for directories containing a file called ‘amendments.json’ for examples of this.

If you have formatters for all the types in your library, you can just provide a formatting.h and skip the amendments business. There are currently no examples of this.

FIDL containers properly print int8 and uint8 as integers

All FIDL containers (structs, tables, unions, arrays, and vectors) print int8 and uint8 FIDL primitives as integers. Structs, tables and unions interpret these as 32-bit types for printing. Arrays and vectors use hex formatting.

Note that if you choose to print an 8-bit data type directly, the C++ STL interprets these as char types, so you'll have to cast it yourself:

uint8_t my_fidl_data = get_some_uint8();
os << static_cast<uint32_t>(my_fidl_data);

Implementation notes

Code-generation templates

The corresponding code-generation templates are located in the sibling directory:

sdk/lib/fostr/build