Maps and oneof are features of the schema language. Neither adds anything to the wire format: both are written with the ordinary fields described on the other pages, so a reader without the schema sees no sign of them.
Maps
A map field, map<K, V> m = N;, is written exactly as if it were
repeated MapEntry m = N;, where MapEntry is a message with
two fields:
| Field | Name | Type | Meaning |
|---|---|---|---|
| 1 | key | K | The key: an integer type, bool or string. |
| 2 | value | V | The value: any type except another map. |
Each entry is one LEN field holding such a message. The order of the entries is not
defined. A missing key or value takes its default. TensorFlow’s schemas use maps, for
example a node’s attributes (map<string, AttrValue> attr = 5): one
attribute named T with the type DT_FLOAT (1) is:
| Bytes | Meaning |
|---|---|
2A 07 | Field 5, LEN 7: one map entry. |
0A 01 54 | Inside: field 1, the key T. |
12 02 | Inside: field 2, LEN 2, the value, an AttrValue message. |
30 01 | Inside the value: field 6 (type), VARINT 1. |
This example was built for this page. ONNX’s schema, written to work as proto2 and
proto3, uses no maps: it has lists of StringStringEntryProto messages
instead, which have the same shape, a key as field 1 and a value as field 2.
Oneof
A oneof is a set of fields of which at most one is set. Its members are
written like ordinary fields, each with its own number, and nothing in the bytes
marks them as belonging together. When a parser sees more than one member of the same
oneof, “only the last member seen is used”.
TensorFlow’s AttrValue is a oneof: field 2 is bytes, 3 an integer, 4 a
float, 6 a type and so on, and an attribute holds just one of them. ONNX’s
TypeProto is another: a tensor type in field 1, a sequence type in field
4, a map type in field 5.