สมาชิก
encode_text
string proto.encode_text(x)แสดงผลการเข้ารหัสของ Struct อาร์กิวเมนต์เป็นข้อความโปรโตคอลรูปแบบข้อความ โครงสร้างข้อมูลต้องประกอบไปด้วยสตริง, ints, ทศนิยม หรือบูล หรือโครงสร้าง ลำดับ และคำสั่งของประเภทเหล่านี้ซ้ำๆ
ระบบแปลงโครงสร้างเป็นข้อความ มีการส่งฟิลด์ตามลำดับชื่อ ระบบจะไม่สนใจช่องโครงสร้างแต่ละช่องที่มีค่าเป็น "ไม่มี"
ลำดับ (เช่น รายการหรือ Tuple) จะถูกแปลงเป็นฟิลด์ที่ซ้ำ องค์ประกอบต้องไม่เป็นลำดับหรือการพิมพ์ตามคำบอก
ระบบจะแปลงพจนานุกรมเป็นช่องข้อความซ้ำที่มีช่องชื่อ "คีย์" และ "ค่า"
โดยรายการส่งออกไปตามลำดับ (การแทรก)
คีย์ของ Dict ต้องเป็นสตริงหรือ int และค่าต้องไม่เรียงตามลำดับหรือคำสั่ง
ตัวอย่าง
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
|
ต้องระบุ |