Proto

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

สมาชิก

encode_text

string proto.encode_text(x)

แสดงผลการเข้ารหัสของอาร์กิวเมนต์ Struct เป็นข้อความโปรโตคอลในรูปแบบข้อความ โครงสร้างข้อมูลต้องประกอบด้วยสตริง, int, float หรือ bool หรือ struct, ลำดับ และพจนานุกรมของประเภทเหล่านี้แบบเรียกซ้ำ

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

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

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

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 structure หรือ NativeInfo ต้องระบุ