gpt4 book ai didi

configuration - 纹理 protobuf 中的评论?

转载 作者:行者123 更新时间:2023-12-04 07:09:05 29 4
gpt4 key购买 nike

我正在使用文本 protobuf 文件进行系统配置。
我遇到的一个问题是序列化的 protobuf 格式不支持注释。
有没有办法解决?
我说的是文本序列化数据格式,而不是方案定义。
这个问题是有人在某处解决的吗?

最佳答案

文本 PROTOBUF 格式的编辑答案

文本 Protobuf 格式支持使用 # 语法的注释。我在任何在线文档中都找不到相同的引用,但在过去的项目中使用过相同的引用,所以我整理了一个可以测试的小示例:

示例消息描述 - [SampleProtoSchema.proto]

message SampleProtoSchema {
optional int32 first_val = 1; // This supports C/C++ style comments
optional int32 second_val = 2;
}

示例文本消息 - [SampleTextualProto.prototxt]
# This is how textual protobuf format supports comments
first_val: 12 # can also be inline comments
# This is another comment
second_val: 23

编译和测试 -
> protoc --python_out=. SampleProtoSchema.proto
>
> ipython
[1]: import SampleProtoSchema_pb2
[2]: sps = SampleProtoSchema_pb2.SampleProtoSchema()
[3]: from google.protobuf import text_format
[4]: with open('SampleTextualProto.prototxt', 'r') as f:
text_format.Merge(f.read(), sps)
[5]: sps.first_val
[5]> 12
[6]: sps.second_val
[6]> 23

旧答案

Protobuf 消息描述格式支持使用//语法的 C/C++ 风格的注释。

在此处检查添加评论部分: https://developers.google.com/protocol-buffers/docs/proto

这可能是一个较新的补充,因为当提出问题时,但这是在 Google 搜索中显示的第一个链接之一,答案没有帮助。

关于configuration - 纹理 protobuf 中的评论?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7317137/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com