带冒号的 Protobuf 语法
Protobuf syntax with colons
以下是 protobuf 语法的三个示例。
-
item {
name: "/m/01g317"
id: 1
display_name: "person"
}
item {
name: "/m/0199g"
id: 2
display_name: "bicycle"
}
...
-
anotherfield {
foo: 123
bar: 456
}
anotherfield {
foo: 222
bar: 333
}
-
syntax = "proto3";
message SearchRequest {
string query = 1;
int32 page_number = 2;
int32 result_per_page = 3;
}
官方(#3)示例明显不同于#1和#2。我是否错过了官方文档中的一段说明可以使用冒号代替等号?
官方文档描述了一个 JSON Mapping,但没有一个示例看起来像 #1 和 #2。此外,#1 和 #2 也不是有效的 JSON(键周围缺少引号,缺少逗号)。
Q: #1 和#2 语法从何而来?
Link 更好的(比官方文档)语法描述表示赞赏。
感谢 Marc 的 Gravell 回复,我找到了答案。
#3是schema,proto语法,想想XSD(XML Schema Definition)。
#1,#2 是实际数据(负载)的文本转储,textproto 语法,*.pbtxt 文件扩展名, 认为 XML 或 JSON.
相关问题:What does the protobuf text format look like?
相关链接:
https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.text_format
C++ API 用于以人类可读的基于文本的格式打印和解析协议消息。
https://googleapis.dev/python/protobuf/latest/google/protobuf/text_format.html
Python API
https://developers.google.com/protocol-buffers/docs/reference/proto3-spec
协议缓冲区版本 3 语言规范
https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/text_format.cc#L288
文本格式 ASCII 表示解析器的源代码 (C++)。
https://medium.com/@nathantnorth/protocol-buffers-text-format-14e0584f70a5
协议缓冲区:文本格式(2019-10-11,Nathan North)
There are a couple different ways to structure the data (instead of using brackets, you could use <>) but unfortunately nothing in this realm is terribly well documented so it’s more of a game of try it and see if it works.
https://gist.github.com/henridf/704c1c812f04a502c1c26f77a739090b
使用 protoc --encode
编码 protobuf(语法示例)。
仍然缺少 protobuf 文本格式 的清晰语法文档。
以下是 protobuf 语法的三个示例。
-
item { name: "/m/01g317" id: 1 display_name: "person" } item { name: "/m/0199g" id: 2 display_name: "bicycle" } ...
-
anotherfield { foo: 123 bar: 456 } anotherfield { foo: 222 bar: 333 }
-
syntax = "proto3"; message SearchRequest { string query = 1; int32 page_number = 2; int32 result_per_page = 3; }
官方(#3)示例明显不同于#1和#2。我是否错过了官方文档中的一段说明可以使用冒号代替等号?
官方文档描述了一个 JSON Mapping,但没有一个示例看起来像 #1 和 #2。此外,#1 和 #2 也不是有效的 JSON(键周围缺少引号,缺少逗号)。
Q: #1 和#2 语法从何而来?
Link 更好的(比官方文档)语法描述表示赞赏。
感谢 Marc 的 Gravell 回复,我找到了答案。
#3是schema,proto语法,想想XSD(XML Schema Definition)。
#1,#2 是实际数据(负载)的文本转储,textproto 语法,*.pbtxt 文件扩展名, 认为 XML 或 JSON.
相关问题:What does the protobuf text format look like?
相关链接:
https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.text_format
C++ API 用于以人类可读的基于文本的格式打印和解析协议消息。
https://googleapis.dev/python/protobuf/latest/google/protobuf/text_format.html
Python API
https://developers.google.com/protocol-buffers/docs/reference/proto3-spec
协议缓冲区版本 3 语言规范
https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/text_format.cc#L288
文本格式 ASCII 表示解析器的源代码 (C++)。
https://medium.com/@nathantnorth/protocol-buffers-text-format-14e0584f70a5
协议缓冲区:文本格式(2019-10-11,Nathan North)
There are a couple different ways to structure the data (instead of using brackets, you could use <>) but unfortunately nothing in this realm is terribly well documented so it’s more of a game of try it and see if it works.
https://gist.github.com/henridf/704c1c812f04a502c1c26f77a739090b
使用
protoc --encode
编码 protobuf(语法示例)。
仍然缺少 protobuf 文本格式 的清晰语法文档。