I have an object that is something like this:
{
"colorRestrictions": {
"availableColors":[ ... ],
"excludedColors": [ ... ]
}
}
How do I translate this into a proto file considering that colorRestriction
is an object that can have either of the arrays?
The property oneof
doesn't allow for repeated
within the declaration.
I guess it's something common but I couldn't find a straight answer, any suggestions? Thanks
Fields are all optional in Protobuf 3. So just define ordinary fields.
oneof
is for mutually-exclusive fields. It doesn't require that a field is present; aoneof
can be unset.Even in Protobuf 2
repeated
fields couldn't be marked as required.repeated
fields don't have normal field presence because "empty list" is encoded identically to "unset list." When you need presence information in a repeated field (e.g., to include it in aoneof
or distinguish "empty list" from "unset list") you can wrap it in a message.