By default fields are accessed in IO space using the current default endianness. However, it is possible to annotate fields with an explicit endianness, like in:
type Foo = struct { little int a; big int b; int c; };
In the example above, the field a
will be stored using
little-endian, the field b
will be stored using big-endian, and
the field c
will be stored using whatever current endianness.
The endianness annotations can be used in any kind of fields, like offsets, arrays and structs, and will impact the storage ofintegral fields defined in them.
When endianness annotations are used in struct fields which are themselves structs, they effectively change the default endianness in the contained struct. Therefore, in the following struct type:
type Bar = struct { little struct { big int a; int b; } f; int c; }
a
is big endian, but b
is little endian.
However, note that the scope of the big
and little
annotations is lexical. Therefore, in these types:
type Foo = struct { int a; int b; }; type Bar = struct { big Foo f; int c; };
The endianness of the a
and b
fields stored in f
is the default endianness, not big
.