หมายเหตุ: API นี้ยังอยู่ในระยะทดลองและอาจมีการเปลี่ยนแปลงได้ทุกเมื่อ โดยจะปิดอยู่โดยค่าเริ่มต้น แต่เปิดได้ด้วย
--experimental_platforms_api
สมาชิก
has_default_constraint_value
bool ConstraintSettingInfo.has_default_constraint_value
to_json
string ConstraintSettingInfo.to_json()
---incompatible_struct_has_no_methods ใช้ Flag นี้เพื่อยืนยันว่าโค้ดของคุณทำงานได้โดยไม่พึ่งพา API ที่กำลังจะถูกนำออก สร้างสตริง JSON จากพารามิเตอร์โครงสร้าง วิธีนี้จะใช้ได้ก็ต่อเมื่อองค์ประกอบ struct ทั้งหมด (รวมถึงที่ซ้อนอยู่) เป็นสตริง, int, บูลีน, struct อื่นๆ, รายการของชนิดข้อมูลเหล่านี้ หรือพจนานุกรมที่มีคีย์และค่าของสตริงชนิดดังกล่าว ระบบจะใช้อักขระหลีกแทนเครื่องหมายคำพูดและบรรทัดใหม่ในสตริง ตัวอย่าง
struct(key=123).to_json()
# {"key":123}
struct(key=True).to_json()
# {"key":true}
struct(key=[1, 2, 3]).to_json()
# {"key":[1,2,3]}
struct(key='text').to_json()
# {"key":"text"}
struct(key=struct(inner_key='text')).to_json()
# {"key":{"inner_key":"text"}}
struct(key=[struct(inner_key=1), struct(inner_key=2)]).to_json()
# {"key":[{"inner_key":1},{"inner_key":2}]}
struct(key=struct(inner_key=struct(inner_inner_key='text'))).to_json()
# {"key":{"inner_key":{"inner_inner_key":"text"}}}
เลิกใช้งาน: ให้ใช้ json.encode(x) หรือ json.encode_indent(x) แทน ซึ่งใช้ได้กับค่าอื่นๆ ที่ไม่ใช่ structs และไม่ทำให้เนมสเปซของฟิลด์ structs เสียหาย
to_proto
string ConstraintSettingInfo.to_proto()
---incompatible_struct_has_no_methods ใช้ Flag นี้เพื่อยืนยันว่าโค้ดของคุณทำงานได้โดยไม่พึ่งพา API ที่กำลังจะถูกนำออก สร้างข้อความจากพารามิเตอร์ struct วิธีนี้จะใช้ได้ก็ต่อเมื่อองค์ประกอบ struct ทั้งหมด (รวมถึงที่ซ้อนอยู่) เป็นสตริง, int, บูลีน, struct หรือพจนานุกรม หรือรายการอื่นๆ ที่เป็นชนิดข้อมูลเหล่านี้ ระบบจะใช้อักขระหลีกแทนเครื่องหมายคำพูดและบรรทัดใหม่ในสตริง และจะวนซ้ำคีย์ Struct ตามลำดับที่จัดเรียง ตัวอย่าง
struct(key=123).to_proto()
# key: 123
struct(key=True).to_proto()
# key: true
struct(key=[1, 2, 3]).to_proto()
# key: 1
# key: 2
# key: 3
struct(key='text').to_proto()
# key: "text"
struct(key=struct(inner_key='text')).to_proto()
# key {
#   inner_key: "text"
# }
struct(key=[struct(inner_key=1), struct(inner_key=2)]).to_proto()
# key {
#   inner_key: 1
# }
# key {
#   inner_key: 2
# }
struct(key=struct(inner_key=struct(inner_inner_key='text'))).to_proto()
# key {
#    inner_key {
#     inner_inner_key: "text"
#   }
# }
struct(foo={4: 3, 2: 1}).to_proto()
# foo: {
#   key: 4
#   value: 3
# }
# foo: {
#   key: 2
#   value: 1
# }
เลิกใช้งาน: ใช้ proto.encode_text(x) แทน