成員
encode_text
string ProtoModule.encode_text(x)
結構體會轉換為訊息。系統會按照名稱順序發出欄位。
序列 (例如清單或元組) 會轉換為重複欄位。 其中的元素不得為序列或字典。
系統會將字典轉換為訊息的重複欄位,欄位中名稱為「key」「value」和「value」。
報名資料會按照疊代 (插入) 順序發出。
字典的鍵必須是字串、 int 或 bools,而且其值不可以是序列或字典。
範例:
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
|
必要 |