【问题标题】:regex as protobuf message field name?正则表达式作为 protobuf 消息字段名称?
【发布时间】:2022-12-15 17:28:38
【问题描述】:

我们可以在 protobuf 字段名称中定义正则表达式吗?我将请求作为 client.py 文件中的字典列表发送

"cur_cur_bin" : [{"cur_cur_bin1_bin3_bin1" : 4,"cur_cur_bin3_bin5_bin8" : 6} ]

我定义了 .proto 文件,

    int32 cur_cur_bin1_bin3_bin1 = 1;
}
message Message{
    repeated cur_cur_BIN cur_cur_bin = 1;
}```

any one can explain how to define this type of field in .proto file dynamically. because 
(bin1) having some range like (1 - [1-8]) same for (bin3) like (3 -[8-11]) like this.  

【问题讨论】:

    标签: protocol-buffers prototype protobuf-python


    【解决方案1】:

    不,据我所知protoc 中没有自动或动态生成字段名称的机制。

    您可以通过 python-protobuf reflection API 动态创建消息,但这对您的用例可能没有意义。

    相反,定义一个合理的.proto 格式,然后编写一些自定义 Python 代码将您的 JSON 数据转换为该格式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-30
      • 2021-11-12
      • 2011-05-11
      • 2019-08-09
      • 2010-09-21
      • 2023-04-09
      相关资源
      最近更新 更多