oluies
oluies

Reputation: 17831

String restriction within protobuf

Can I represent this XSDSchema enumeration/String restriction within a protobuf enum?

<s:element maxOccurs="1" minOccurs="1" name="Condition">
    <s:simpleType>
     <s:restriction base="s:string">
      <s:enumeration value="EQ" />
      <s:enumeration value="NE" />
      <s:enumeration value="GT" />
      <s:enumeration value="LT" />
      <s:enumeration value="GE" />
      <s:enumeration value="LE" />
      <s:enumeration value="LK" />
      <s:enumeration value="=" />
      <s:enumeration value="!=" />
      <s:enumeration value="&gt;" />
      <s:enumeration value="&lt;" />
      <s:enumeration value="=&gt;" />
     </s:restriction>
    </s:simpleType>
</s:element>

Upvotes: 1

Views: 754

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1063964

.proto enums are named integers, but note that the last few names will barf. You would need to tweak the names in your .proto / DTO layer, but it would a pain to have to disambiguate between "EQ" and "=", "LE" and "<"

But you could map something similar in .proto, sure.

If you store a string that would work, but will be more bytes. Not many more (1 byte for the string length plus 1-4 bytes for the char-data, versus 1 byte for the enums).

Upvotes: 2

Related Questions