如何自动解析代码中使用的Protobuf(trade.proto)字段?
从给定代码中提取Protobuf字段的方法
直接通过代码里的getter方法反向对应Protobuf字段即可——Protobuf生成代码时会把proto里的下划线命名转成驼峰式的getter方法,对应规则如下:
- 代码中的
trade.getPartitionTime,对应proto文件里的partition_time字段 - 代码中的
trade.getProductInfo.getOtherFieldList,对应proto里嵌套的product_info.other_field字段(因为该字段是repeated类型,生成的方法会带List后缀)
最终提取出的代码用到的Protobuf字段:
partition_time product_info.other_field
内容的提问来源于stack exchange,提问作者Birkety
相关产品推荐
相关产品推荐

