protobuf 中的字符串限制

发布于 2024-10-06 22:12:40 字数 788 浏览 0 评论 0原文

我可以在 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="&gt;" />
      <s:enumeration value="&lt;" />
      <s:enumeration value="=&gt;" />
     </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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

要走就滚别墨迹 2024-10-13 22:12:40

.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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文