成员
encode_text
string ProtoModule.encode_text(x)
结构体转换为消息。字段按名称顺序发出。
序列(例如列表或元组)将转换为重复字段。 它的元素不得为序列或词典。
字典转换为消息的重复字段,其中包含字段名为“key”和“value”的值
条目按迭代(插入)顺序发出。
字典的键必须是字符串、整数或布尔值,而值不能是序列或字典。
示例:
struct(field=123).to_proto()
# field: 123
struct(field=True).to_proto()
# field: true
struct(field=[1, 2, 3]).to_proto()
# field: 1
# field: 2
# field: 3
struct(field='text').to_proto()
# field: "text"
struct(field=struct(inner_field='text')).to_proto()
# field {
# inner_field: "text"
# }
struct(field=[struct(inner_field=1), struct(inner_field=2)]).to_proto()
# field {
# inner_field: 1
# }
# field {
# inner_field: 2
# }
struct(field=struct(inner_field=struct(inner_inner_field='text'))).to_proto()
# field {
# inner_field {
# inner_inner_field: "text"
# }
# }
struct(foo={4: 3, 2: 1}).to_proto()
# foo: {
# key: 4
# value: 3
# }
# foo: {
# key: 2
# value: 1
# }
参数
| 参数 | 说明 |
|---|---|
x
|
必需 |