protobuf 中的字符串限制
我可以在 protobuf 枚举中表示此 XSDSchema 枚举/字符串限制吗?
<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=">" />
<s:enumeration value="<" />
<s:enumeration value="=>" />
</s:restriction>
</s:simpleType>
</s:element>
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=">" />
<s:enumeration value="<" />
<s:enumeration value="=>" />
</s:restriction>
</s:simpleType>
</s:element>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
.proto 枚举被命名为整数,但请注意最后几个名称会让人呕吐。您需要调整 .proto / DTO 层中的名称,但必须消除
"EQ"
和"="
,之间的歧义会很痛苦“LE”
和“<”
但当然,您可以在 .proto 中映射类似的内容。
如果您存储一个可以工作的字符串,但会占用更多字节。不多了(1 个字节用于字符串长度加上 1-4 个字节用于字符数据,而 1 个字节用于枚举)。
.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).