โมดูลสำหรับการประมวลผลข้อความโปรโตคอล
สมาชิก
encode_text
string proto.encode_text(x)
ระบบจะแปลงโครงสร้างเป็นข้อความ ระบบจะส่งฟิลด์ตามลำดับชื่อ ระบบจะไม่สนใจฟิลด์ 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;
required |