สมาชิก
encode_text
string ProtoModule.encode_text(x)
โครงสร้างจะแปลงเป็นข้อความ ระบบจะส่งออกช่องตามลำดับชื่อ
ระบบจะแปลงลำดับ (เช่น รายการหรือ Tuple) เป็นฟิลด์ที่ซ้ำ องค์ประกอบต้องไม่ใช่ลำดับหรือคำสั่ง
ระบบจะแปลงคำสั่ง dict เป็นช่องข้อความที่ซ้ำกันซึ่งมีช่องที่ชื่อว่า "key" และ "value"
ระบบจะส่งออกรายการตามลำดับการทำซ้ำ (insertion)
คีย์ของ dict ต้องเป็นสตริง, ints หรือ bools และค่าจะต้องไม่ใช่ลำดับหรือ dict
ตัวอย่าง:
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
|
ต้องระบุ |