【问题标题】:how to write text for a protobuf file which with include other protobuf如何为包含其他 protobuf 的 protobuf 文件编写文本
【发布时间】:2018-12-26 04:05:40
【问题描述】:

我是 protobuf 的新手,我正在尝试编写一个 .proto 文件,其中包含从文本文件中读取的初始参数解析。

这是我的 test.proto

syntax = "proto2";
import "params_common.proto";
message TestConfig {
    required bool enable = 1 [default = true];
    required common.Common common = 2;
}

然后,我不知道如何为参数common 编写test.text 文件

text_format.Parse 好像不支持一次输入多个文本

这里是params_common.common

syntax = "proto2";
package common;
message Common {
    required int element = 1 [default = 1];
}

提前感谢

【问题讨论】:

    标签: python c++ proto


    【解决方案1】:

    我想通了

    在你的 Python 代码中

    fc = open('params_common.txt', 'r')
    f = open('test.txt', 'r')
    config = text_format.Parse(f.read()+fc.read(), test_config)
    

    test.txt

    enable: true
    

    params_common.txt

    common {
    element : 2
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-17
      • 2021-12-15
      • 1970-01-01
      相关资源
      最近更新 更多