@@ -94,7 +94,7 @@ message Person {
9494
9595 message PhoneNumber {
9696 optional string number = 1;
97- optional PhoneType type = 2 [default = HOME ];
97+ optional PhoneType type = 2 [default = PHONE_TYPE_HOME ];
9898 }
9999
100100 repeated PhoneNumber phones = 4;
@@ -125,7 +125,7 @@ even define message types nested inside other messages -- as you can see, the
125125` PhoneNumber ` type is defined inside ` Person ` . You can also define ` enum ` types
126126if you want one of your fields to have one of a predefined list of values --
127127here you want to specify that a phone number can be one of the following phone
128- types: ` MOBILE ` , ` HOME ` , or ` WORK ` .
128+ types: ` PHONE_TYPE_MOBILE ` , ` PHONE_TYPE_HOME ` , or ` PHONE_TYPE_WORK ` .
129129
130130The " = 1", " = 2" markers on each element identify the unique "tag" that field
131131uses in the binary encoding. Tag numbers 1-15 require one less byte to encode
@@ -240,7 +240,7 @@ person.name = "John Doe"
240240person.email = " [email protected] " 241241phone = person.phones.add ()
242242phone.number = " 555-4321"
243- phone.type = addressbook_pb2.Person.HOME
243+ phone.type = addressbook_pb2.Person.PHONE_TYPE_HOME
244244` ` `
245245
246246Note that these assignments are not just adding arbitrary new fields to a
@@ -262,7 +262,7 @@ any particular field definition, see the
262262
263263Enums are expanded by the metaclass into a set of symbolic constants with
264264integer values. So, for example, the constant
265- `addressbook_pb2.Person.PhoneType.WORK ` has the value 2.
265+ `addressbook_pb2.Person.PhoneType.PHONE_TYPE_WORK ` has the value 2.
266266
267267### Standard Message Methods {#standard-message-methods}
268268
@@ -348,11 +348,11 @@ def PromptForAddress(person):
348348
349349 phone_type = input("Is this a mobile, home, or work phone? ")
350350 if phone_type == "mobile":
351- phone_number.type = addressbook_pb2.Person.PhoneType.MOBILE
351+ phone_number.type = addressbook_pb2.Person.PhoneType.PHONE_TYPE_MOBILE
352352 elif phone_type == "home":
353- phone_number.type = addressbook_pb2.Person.PhoneType.HOME
353+ phone_number.type = addressbook_pb2.Person.PhoneType.PHONE_TYPE_HOME
354354 elif phone_type == "work":
355- phone_number.type = addressbook_pb2.Person.PhoneType.WORK
355+ phone_number.type = addressbook_pb2.Person.PhoneType.PHONE_TYPE_WORK
356356 else:
357357 print("Unknown phone type; leaving as default value.")
358358
@@ -401,11 +401,11 @@ def ListPeople(address_book):
401401 print(" E-mail address:", person.email)
402402
403403 for phone_number in person.phones:
404- if phone_number.type == addressbook_pb2.Person.PhoneType.MOBILE :
404+ if phone_number.type == addressbook_pb2.Person.PhoneType.PHONE_TYPE_MOBILE :
405405 print(" Mobile phone #: ", end="")
406- elif phone_number.type == addressbook_pb2.Person.PhoneType.HOME :
406+ elif phone_number.type == addressbook_pb2.Person.PhoneType.PHONE_TYPE_HOME :
407407 print(" Home phone #: ", end="")
408- elif phone_number.type == addressbook_pb2.Person.PhoneType.WORK :
408+ elif phone_number.type == addressbook_pb2.Person.PhoneType.PHONE_TYPE_WORK :
409409 print(" Work phone #: ", end="")
410410 print(phone_number.number)
411411
0 commit comments