【问题标题】:Parsing string to protobuf enum with no case-sensitivy将字符串解析为不区分大小写的 protobuf 枚举
【发布时间】:2019-10-23 22:24:53
【问题描述】:

使用 C++ API,Enum_Parse() 似乎区分大小写,有没有办法让它忽略大小写?使用底部的枚举定义,Enum_Parse 接受“Http”,但拒绝“http”。我在下面的链接中搜索了与枚举相关的选项,但没有找到与此相关的选项。

https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/descriptor.proto

enum MyEnum
{
    Tcp = 0;
    Http = 1;
    Https = 2;
}

【问题讨论】:

    标签: c++ parsing enums protocol-buffers


    【解决方案1】:

    如果您可以像这样将枚举重命名为小写 -

    enum MyEnum
    {
        tcp = 0;
        http = 1;
        https = 2;
    }
    

    然后你可以先将输入字符串转换为小写,然后使用 Enum_Parse()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-18
      • 2015-10-27
      • 1970-01-01
      • 2010-09-26
      • 2016-11-18
      • 1970-01-01
      • 1970-01-01
      • 2021-08-16
      相关资源
      最近更新 更多