|Did you know ...||Search Documentation:|
It is possible to specify homogeneous vectors of things (e.g. lists
of numbers) using the
repeated attribute. You specify a
repeated field as follows:
repeated(22, float([1,2,3,4])), repeated(23, enum(tank_state([empty, half_full, full]))).
The first clause above will cause all four items in the list to be encoded in the wire-stream as IEEE-754 32-bit floating point numbers, all with tag 22. The decoder will aggregate all items in the wire-stream with tag 22 into a list as above. Likewise, all the items listed in the second clause will be encoded in the wire-stream according to the mapping defined in an enumeration (described below) tank_state/2, each with tag 23.
Beware that there is no explicit means to encode an empty set. The
protobuf specification provides that a
repeated field may
match a tag zero or more times. The empty set, while legal, produces no
output on encode. While decoding a
repeated term, failure
to match the specified tag will yield an empty set of the specified host
optional field is handled the same way as a
field with an empty set.
The protobuf grammar provides a variant of the
field known as "packed." This is represented similar to
packed(22, float([1,2,3,4])), packed(23, enum(tank_state([empty, half_full, full]))).