Here is the definition of the proto description file
Message person {
Required String name = 1;
Required Int32 id = 2;
Optional String email = 3;
Enum Phonetype {
MOBILE = 0;
HOME = 1;
Work = 2;
}
Message PhoneNumber {
Required String number = 1;
Optional Phonetype type = 2 [default = HOME];
}
Repeated PhoneNumber phone = 4;
}
Message AddressBook {
Repeated person person = 1;
}
When using GOOGLE.PROTOBUF serialized data for communication in Python, you must encounter how repeated data is created
Here I share with you:
Import ADDRESSBOOK_PB2
person = addressbook_pb2. Person ()
Person.id = 1234
Person.name = "John Doe"
Person.email = ""
Phone = Person.phone.add ()
Phone.number = "555-4321"
Phone.type = Addressbook_pb2. Person.home Person.no_such_field = 1 person.id = "1234"
Note the red Line of code, which is the point, if you want to add another word Phone2 = Person.phone.add (), and then assign a value to Phone2
Python protobuf serialization repeated application