Proto

โมดูลสำหรับการประมวลผลข้อความโปรโตคอล

สำหรับสมาชิก

encode_text

string proto.encode_text(x)

แสดงผลการเข้ารหัสของอาร์กิวเมนต์ Struct เป็นข้อความโปรโตคอลรูปแบบข้อความ โครงสร้างข้อมูลต้องประกอบไปด้วยสตริง, ints, ทศนิยม หรือบูล หรือโครงสร้าง ลำดับ และคำสั่งของประเภทเหล่านี้ซ้ำๆ

โครงสร้างจะแปลงเป็นข้อความ ระบบจะส่งออกช่องตามลำดับชื่อ ระบบจะไม่สนใจช่อง Struct แต่ละช่องที่มีค่าเป็น "ไม่มี"

ระบบจะแปลงลำดับ (เช่น รายการหรือ Tuple) เป็นฟิลด์ที่ซ้ำ องค์ประกอบต้องไม่ใช่ลำดับหรือคำสั่ง

ระบบจะแปลงคำสั่ง dict เป็นช่องข้อความที่ซ้ำกันซึ่งมีช่องชื่อ "key" และ "value" ระบบจะส่งออกรายการตามลำดับการทำซ้ำ (insertion) คีย์ของ dict ต้องเป็นสตริงหรือ ints และค่าต้องไม่ใช่ลำดับหรือคำสั่ง ตัวอย่าง:

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
# }

พารามิเตอร์

พารามิเตอร์ คำอธิบาย
x ต้องระบุ