Một mô-đun để xử lý thông báo giao thức.
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ộ giá trị) được chuyển đổi thành một trường lặp lại. Các phần tử của nó không được là chuỗi hoặc từ điển.
Một dict đượ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ên là "key" và "value".
Các mục được phát theo thứ tự lặp lại (chèn).
Khoá của dict phải là chuỗi hoặc số nguyên và giá trị của khoá không được là chuỗi hoặc dict.
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 # }
Thông số
Thông số | Mô tả |
---|---|
x
|
structure; bắt buộc |