diff options
author | Dan O'Reilly <oreilldf@gmail.com> | 2015-08-12 23:57:46 -0400 |
---|---|---|
committer | Dan O'Reilly <oreilldf@gmail.com> | 2015-08-12 23:57:46 -0400 |
commit | e47cdd5a559f488ba52756927ce68f4cf93874fa (patch) | |
tree | 8ce2723e822808baf58e96f569c86035717ea351 /examples | |
parent | daeaa6a28b81195f24d89222e649d79c9555af8b (diff) | |
parent | 38a56ee4b19d72c2e9d81a08b018704d1addf561 (diff) | |
download | protobuf-e47cdd5a559f488ba52756927ce68f4cf93874fa.tar.gz protobuf-e47cdd5a559f488ba52756927ce68f4cf93874fa.tar.bz2 protobuf-e47cdd5a559f488ba52756927ce68f4cf93874fa.zip |
Merge remote-tracking branch 'upstream/master' into py2_py3_straddle
Conflicts:
python/google/protobuf/descriptor_pool.py
python/google/protobuf/internal/api_implementation_default_test.py
python/google/protobuf/internal/cpp_message.py
python/google/protobuf/internal/descriptor_database_test.py
python/google/protobuf/internal/descriptor_pool_test.py
python/google/protobuf/internal/descriptor_python_test.py
python/google/protobuf/internal/descriptor_test.py
python/google/protobuf/internal/generator_test.py
python/google/protobuf/internal/message_factory_python_test.py
python/google/protobuf/internal/message_factory_test.py
python/google/protobuf/internal/message_test.py
python/google/protobuf/internal/proto_builder_test.py
python/google/protobuf/internal/python_message.py
python/google/protobuf/internal/reflection_test.py
python/google/protobuf/internal/service_reflection_test.py
python/google/protobuf/internal/symbol_database_test.py
python/google/protobuf/internal/text_encoding_test.py
python/google/protobuf/internal/text_format_test.py
python/google/protobuf/internal/unknown_fields_test.py
python/google/protobuf/internal/wire_format_test.py
python/google/protobuf/pyext/descriptor_cpp2_test.py
python/google/protobuf/pyext/message_factory_cpp2_test.py
python/google/protobuf/pyext/reflection_cpp2_generated_test.py
python/setup.py
ruby/lib/google/protobuf/message_exts.rb
Diffstat (limited to 'examples')
-rw-r--r-- | examples/AddPerson.java | 4 | ||||
-rw-r--r-- | examples/ListPeople.java | 6 | ||||
-rw-r--r-- | examples/add_person.cc | 4 | ||||
-rwxr-xr-x | examples/add_person.py | 6 | ||||
-rw-r--r-- | examples/addressbook.proto | 17 | ||||
-rw-r--r-- | examples/list_people.cc | 10 | ||||
-rwxr-xr-x | examples/list_people.py | 8 |
7 files changed, 29 insertions, 26 deletions
diff --git a/examples/AddPerson.java b/examples/AddPerson.java index ca5ac273..c262ab7e 100644 --- a/examples/AddPerson.java +++ b/examples/AddPerson.java @@ -50,7 +50,7 @@ class AddPerson { stdout.println("Unknown phone type. Using default."); } - person.addPhone(phoneNumber); + person.addPhones(phoneNumber); } return person.build(); @@ -80,7 +80,7 @@ class AddPerson { } // Add an address. - addressBook.addPerson( + addressBook.addPeople( PromptForAddress(new BufferedReader(new InputStreamReader(System.in)), System.out)); diff --git a/examples/ListPeople.java b/examples/ListPeople.java index b2f153af..78924305 100644 --- a/examples/ListPeople.java +++ b/examples/ListPeople.java @@ -9,14 +9,14 @@ import java.io.PrintStream; class ListPeople { // Iterates though all people in the AddressBook and prints info about them. static void Print(AddressBook addressBook) { - for (Person person: addressBook.getPersonList()) { + for (Person person: addressBook.getPeopleList()) { System.out.println("Person ID: " + person.getId()); System.out.println(" Name: " + person.getName()); - if (person.hasEmail()) { + if (!person.getEmail().isEmpty()) { System.out.println(" E-mail address: " + person.getEmail()); } - for (Person.PhoneNumber phoneNumber : person.getPhoneList()) { + for (Person.PhoneNumber phoneNumber : person.getPhonesList()) { switch (phoneNumber.getType()) { case MOBILE: System.out.print(" Mobile phone #: "); diff --git a/examples/add_person.cc b/examples/add_person.cc index b9ca44fc..9bec4b37 100644 --- a/examples/add_person.cc +++ b/examples/add_person.cc @@ -32,7 +32,7 @@ void PromptForAddress(tutorial::Person* person) { break; } - tutorial::Person::PhoneNumber* phone_number = person->add_phone(); + tutorial::Person::PhoneNumber* phone_number = person->add_phones(); phone_number->set_number(number); cout << "Is this a mobile, home, or work phone? "; @@ -77,7 +77,7 @@ int main(int argc, char* argv[]) { } // Add an address. - PromptForAddress(address_book.add_person()); + PromptForAddress(address_book.add_people()); { // Write the new address book back to disk. diff --git a/examples/add_person.py b/examples/add_person.py index 78e56966..fd81c982 100755 --- a/examples/add_person.py +++ b/examples/add_person.py @@ -1,4 +1,4 @@ -#! /usr/bin/python +#! /usr/bin/env python # See README.txt for information and build instructions. @@ -19,7 +19,7 @@ def PromptForAddress(person): if number == "": break - phone_number = person.phone.add() + phone_number = person.phones.add() phone_number.number = number type = raw_input("Is this a mobile, home, or work phone? ") @@ -50,7 +50,7 @@ except IOError: print sys.argv[1] + ": File not found. Creating a new file." # Add an address. -PromptForAddress(address_book.person.add()) +PromptForAddress(address_book.people.add()) # Write the new address book back to disk. f = open(sys.argv[1], "wb") diff --git a/examples/addressbook.proto b/examples/addressbook.proto index b14829e9..bfdceeaf 100644 --- a/examples/addressbook.proto +++ b/examples/addressbook.proto @@ -1,14 +1,17 @@ // See README.txt for information and build instructions. +syntax = "proto3"; + package tutorial; option java_package = "com.example.tutorial"; option java_outer_classname = "AddressBookProtos"; +option csharp_namespace = "Google.Protobuf.Examples.AddressBook"; message Person { - required string name = 1; - required int32 id = 2; // Unique ID number for this person. - optional string email = 3; + string name = 1; + int32 id = 2; // Unique ID number for this person. + string email = 3; enum PhoneType { MOBILE = 0; @@ -17,14 +20,14 @@ message Person { } message PhoneNumber { - required string number = 1; - optional PhoneType type = 2 [default = HOME]; + string number = 1; + PhoneType type = 2; } - repeated PhoneNumber phone = 4; + repeated PhoneNumber phones = 4; } // Our address book file is just one of these. message AddressBook { - repeated Person person = 1; + repeated Person people = 1; } diff --git a/examples/list_people.cc b/examples/list_people.cc index 5363152e..68e5666d 100644 --- a/examples/list_people.cc +++ b/examples/list_people.cc @@ -8,17 +8,17 @@ using namespace std; // Iterates though all people in the AddressBook and prints info about them. void ListPeople(const tutorial::AddressBook& address_book) { - for (int i = 0; i < address_book.person_size(); i++) { - const tutorial::Person& person = address_book.person(i); + for (int i = 0; i < address_book.people_size(); i++) { + const tutorial::Person& person = address_book.people(i); cout << "Person ID: " << person.id() << endl; cout << " Name: " << person.name() << endl; - if (person.has_email()) { + if (person.email() != "") { cout << " E-mail address: " << person.email() << endl; } - for (int j = 0; j < person.phone_size(); j++) { - const tutorial::Person::PhoneNumber& phone_number = person.phone(j); + for (int j = 0; j < person.phones_size(); j++) { + const tutorial::Person::PhoneNumber& phone_number = person.phones(j); switch (phone_number.type()) { case tutorial::Person::MOBILE: diff --git a/examples/list_people.py b/examples/list_people.py index f9f36b96..755de901 100755 --- a/examples/list_people.py +++ b/examples/list_people.py @@ -1,4 +1,4 @@ -#! /usr/bin/python +#! /usr/bin/env python # See README.txt for information and build instructions. @@ -7,13 +7,13 @@ import sys # Iterates though all people in the AddressBook and prints info about them. def ListPeople(address_book): - for person in address_book.person: + for person in address_book.people: print "Person ID:", person.id print " Name:", person.name - if person.HasField('email'): + if person.email != "": print " E-mail address:", person.email - for phone_number in person.phone: + for phone_number in person.phones: if phone_number.type == addressbook_pb2.Person.MOBILE: print " Mobile phone #:", elif phone_number.type == addressbook_pb2.Person.HOME: |