Hội viên
encode_text
string proto.encode_text(x)
Một cấu trúc được chuyển đổi thành một thông báo. Các trường được phát theo thứ tự tên. Mỗi trường cấu trúc có giá trị là None đều bị bỏ qua.
Một chuỗi (chẳng hạn như danh sách hoặc bộ) được chuyển đổi thành một trường lặp lại. Các phần tử của chuỗi không được là chuỗi hoặc từ điển.
Một từ điển được chuyển đổi thành một trường lặp lại của các thông báo có các trường được đặt tên là "key" và "value".
Các mục được phát theo thứ tự lặp lại (chèn).
Khoá của từ điển phải là chuỗi hoặc số nguyên và giá trị của từ điển không được là chuỗi hoặc từ điển.
Ví dụ:
proto.encode_text(struct(field=123))
# field: 123
proto.encode_text(struct(field=True))
# field: true
proto.encode_text(struct(field=[1, 2, 3]))
# field: 1
# field: 2
# field: 3
proto.encode_text(struct(field='text', ignored_field=None))
# field: "text"
proto.encode_text(struct(field=struct(inner_field='text', ignored_field=None)))
# field {
# inner_field: "text"
# }
proto.encode_text(struct(field=[struct(inner_field=1), struct(inner_field=2)]))
# field {
# inner_field: 1
# }
# field {
# inner_field: 2
# }
proto.encode_text(struct(field=struct(inner_field=struct(inner_inner_field='text'))))
# field {
# inner_field {
# inner_inner_field: "text"
# }
# }
proto.encode_text(struct(foo={4: 3, 2: 1}))
# foo: {
# key: 4
# value: 3
# }
# foo: {
# key: 2
# value: 1
# }
Tham số
| Tham số | Mô tả |
|---|---|
x
|
cấu trúc; hoặc NativeInfo;
bắt buộc |