The values of all members in a bits
declaration must not be any number that is not a power of two:
{% include “docs/reference/fidl/language/error-catalog/label/_bad.md” %}
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/bad/fi-0067.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
Instead, member values should always be powers of two:
{% include “docs/reference/fidl/language/error-catalog/label/_good.md” %}
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/good/fi-0067-a.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
An easy way to avoid getting tripped up by this restriction is to just use bit masks, rather than decimal numbers, for bit member values:
{% include “docs/reference/fidl/language/error-catalog/label/_good.md” %}
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/good/fi-0067-b.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
The bits
construct represents a bit array. This is the most memory-efficient way to represent a sequence of boolean flags. Because each member of the bits
declaration is mapped to a specific bit of its underlying memory, the values used for that mapping must clearly identify a specific bit in an unsigned integer to assign to.