Using collections in Protobuf
Protobuf supports two types of collections: repeated fields and maps. Repeated fields are analogous to arrays or lists in C#. They represent a collection of singular objects. Maps are analogous to dictionaries in C#. They represent a collection of key-value pairs.
Repeated field collections can contain any data type, but you cannot use additional keywords inside of them. For example, you cannot have an equivalent of a multi-dimensional array by having a repeated
keyword inside a repeated field.
Map fields can use any data type as a value, but its key needs to be either any of the integer types or a string. It cannot be a bytes
, enum
, float
, or double
data type, or any custom message
type. Neither its key, its value, nor the whole field itself can be repeated
. Let's discuss each type further in the next subsections.
Repeated fields
Inside the greet.proto
file, add the following fields to the NestedMessage
definition:
repeated string...