From 9d9d0b70de43e4c397bbd583a6712d3f4cdf7043 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sat, 11 Apr 2015 20:23:45 -0700 Subject: Don't hard-code the python path --- examples/add_person.py | 2 +- examples/list_people.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/add_person.py b/examples/add_person.py index 78e56966..5a7b968e 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. diff --git a/examples/list_people.py b/examples/list_people.py index f9f36b96..d470349a 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. -- cgit v1.2.3 From 734393d0f9e1f746f4bd228f709c5b1142faa16d Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Thu, 14 May 2015 09:11:57 +0100 Subject: Make generate_protos.sh Windows-friendly. To my surprise, executing generate_protos.sh used the version of Bash installed with Git for Windows by default. After a few modifications to detect the most appropriate protoc to use, this worked pretty simply. This change also: - adds generation of the address book tutorial proto, - fixes the addressbook.proto to specify proto2 explicitly (to avoid a warning from protoc; I don't think we want warnings...) - fixes the addressbook.proto C# namespace (which I thought I'd done before, but apparently hadn't) - includes the regenerated UnittestCustomOptions.cs apart from the DescriptorProtoFIle => Descriptor change --- csharp/generate_protos.sh | 22 ++++++++++++++++++++-- .../TestProtos/UnittestCustomOptions.cs | 6 ------ examples/addressbook.proto | 3 +++ 3 files changed, 23 insertions(+), 8 deletions(-) (limited to 'examples') diff --git a/csharp/generate_protos.sh b/csharp/generate_protos.sh index 9cd3eb58..8c066cbe 100755 --- a/csharp/generate_protos.sh +++ b/csharp/generate_protos.sh @@ -8,8 +8,22 @@ set -ex # cd to repository root cd $(dirname $0)/.. -# protocol buffer compiler to use -PROTOC=src/protoc +# Protocol buffer compiler to use. If the PROTOC variable is set, +# use that. Otherwise, probe for expected locations under both +# Windows and Unix. +if [ -z "$PROTOC" ]; then + # TODO(jonskeet): Use an array and a for loop instead? + if [ -x vsprojects/Debug/protoc.exe ]; then + PROTOC=vsprojects/Debug/protoc.exe + elif [ -x vsprojects/Release/protoc.exe ]; then + PROTOC=vsprojects/Release/protoc.exe + elif [ -x src/protoc ]; then + PROTOC=src/protoc + else + echo "Unable to find protocol buffer compiler." + exit 1 + fi +fi # Descriptor proto #TODO(jtattermusch): generate descriptor.proto @@ -48,3 +62,7 @@ $PROTOC -Isrc --csharp_out=csharp/src/ProtocolBuffersLite.Test/TestProtos \ $PROTOC -Icsharp/protos/extest --csharp_out=csharp/src/ProtocolBuffersLite.Test/TestProtos \ csharp/protos/extest/unittest_extras_full.proto \ csharp/protos/extest/unittest_extras_lite.proto + +# AddressBook sample protos +$PROTOC -Iexamples --csharp_out=csharp/src/AddressBook \ + examples/addressbook.proto diff --git a/csharp/src/ProtocolBuffers.Test/TestProtos/UnittestCustomOptions.cs b/csharp/src/ProtocolBuffers.Test/TestProtos/UnittestCustomOptions.cs index 29ba8607..4334bfed 100644 --- a/csharp/src/ProtocolBuffers.Test/TestProtos/UnittestCustomOptions.cs +++ b/csharp/src/ProtocolBuffers.Test/TestProtos/UnittestCustomOptions.cs @@ -62,12 +62,10 @@ namespace Google.ProtocolBuffers.TestProtos { #endregion #region Extensions public const int FileOpt1FieldNumber = 7736974; - [global::System.CLSCompliant(false)] public static pb::GeneratedExtensionBase FileOpt1; public const int MessageOpt1FieldNumber = 7739036; public static pb::GeneratedExtensionBase MessageOpt1; public const int FieldOpt1FieldNumber = 7740936; - [global::System.CLSCompliant(false)] public static pb::GeneratedExtensionBase FieldOpt1; public const int FieldOpt2FieldNumber = 7753913; public static pb::GeneratedExtensionBase FieldOpt2; @@ -86,20 +84,16 @@ namespace Google.ProtocolBuffers.TestProtos { public const int Int64OptFieldNumber = 7705542; public static pb::GeneratedExtensionBase Int64Opt; public const int Uint32OptFieldNumber = 7704880; - [global::System.CLSCompliant(false)] public static pb::GeneratedExtensionBase Uint32Opt; public const int Uint64OptFieldNumber = 7702367; - [global::System.CLSCompliant(false)] public static pb::GeneratedExtensionBase Uint64Opt; public const int Sint32OptFieldNumber = 7701568; public static pb::GeneratedExtensionBase Sint32Opt; public const int Sint64OptFieldNumber = 7700863; public static pb::GeneratedExtensionBase Sint64Opt; public const int Fixed32OptFieldNumber = 7700307; - [global::System.CLSCompliant(false)] public static pb::GeneratedExtensionBase Fixed32Opt; public const int Fixed64OptFieldNumber = 7700194; - [global::System.CLSCompliant(false)] public static pb::GeneratedExtensionBase Fixed64Opt; public const int Sfixed32OptFieldNumber = 7698645; public static pb::GeneratedExtensionBase Sfixed32Opt; diff --git a/examples/addressbook.proto b/examples/addressbook.proto index b14829e9..91c9ffc4 100644 --- a/examples/addressbook.proto +++ b/examples/addressbook.proto @@ -1,9 +1,12 @@ // See README.txt for information and build instructions. +syntax = "proto2"; + package tutorial; option java_package = "com.example.tutorial"; option java_outer_classname = "AddressBookProtos"; +option csharp_namespace = "Google.ProtocolBuffers.Examples.AddressBook"; message Person { required string name = 1; -- cgit v1.2.3 From 69c14071ad58b1dad9e5e52c33140ece139577d0 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 20 Jul 2015 14:32:57 -0700 Subject: update addressbook.proto to proto3 --- examples/addressbook.proto | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'examples') diff --git a/examples/addressbook.proto b/examples/addressbook.proto index 91c9ffc4..bbcb0c54 100644 --- a/examples/addressbook.proto +++ b/examples/addressbook.proto @@ -1,6 +1,6 @@ // See README.txt for information and build instructions. -syntax = "proto2"; +syntax = "proto3"; package tutorial; @@ -9,9 +9,9 @@ option java_outer_classname = "AddressBookProtos"; option csharp_namespace = "Google.ProtocolBuffers.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; @@ -20,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 persons = 1; } -- cgit v1.2.3 From 78709f20fb7255c3209e7126f404935bcf73e8dc Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 20 Jul 2015 14:33:36 -0700 Subject: fix C++ example --- examples/add_person.cc | 4 ++-- examples/list_people.cc | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'examples') diff --git a/examples/add_person.cc b/examples/add_person.cc index b9ca44fc..e71d3844 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_persons()); { // Write the new address book back to disk. diff --git a/examples/list_people.cc b/examples/list_people.cc index 5363152e..3daa3159 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.persons_size(); i++) { + const tutorial::Person& person = address_book.persons(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: -- cgit v1.2.3 From b95670f5fb91ec49735510a5202e9c031d8f43f1 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 20 Jul 2015 14:34:27 -0700 Subject: fix python example --- examples/add_person.py | 4 ++-- examples/list_people.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'examples') diff --git a/examples/add_person.py b/examples/add_person.py index 5a7b968e..919a1a17 100755 --- a/examples/add_person.py +++ b/examples/add_person.py @@ -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.persons.add()) # Write the new address book back to disk. f = open(sys.argv[1], "wb") diff --git a/examples/list_people.py b/examples/list_people.py index d470349a..e0658493 100755 --- a/examples/list_people.py +++ b/examples/list_people.py @@ -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.persons: 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: -- cgit v1.2.3 From 4d86c2b495a359e31af082098aacc3e7ce3b9ee7 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 20 Jul 2015 14:51:09 -0700 Subject: fixed java example --- examples/AddPerson.java | 4 ++-- examples/ListPeople.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'examples') diff --git a/examples/AddPerson.java b/examples/AddPerson.java index ca5ac273..259cfb7b 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.addPersons( PromptForAddress(new BufferedReader(new InputStreamReader(System.in)), System.out)); diff --git a/examples/ListPeople.java b/examples/ListPeople.java index b2f153af..0294fb7a 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.getPersonsList()) { 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 #: "); -- cgit v1.2.3 From 359d32d4f711b7f8f774a1ceaa3ad55aa13167cf Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 20 Jul 2015 15:12:56 -0700 Subject: use Google.Protobuf namespace for C# --- examples/addressbook.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/addressbook.proto b/examples/addressbook.proto index bbcb0c54..64cb7acf 100644 --- a/examples/addressbook.proto +++ b/examples/addressbook.proto @@ -6,7 +6,7 @@ package tutorial; option java_package = "com.example.tutorial"; option java_outer_classname = "AddressBookProtos"; -option csharp_namespace = "Google.ProtocolBuffers.Examples.AddressBook"; +option csharp_namespace = "Google.Protobuf.Examples.AddressBook"; message Person { string name = 1; -- cgit v1.2.3 From b0e5ba697eb281b4ea9e53e1dc9f5ebeccf28f9a Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 20 Jul 2015 15:24:08 -0700 Subject: rename persons to people --- examples/AddPerson.java | 2 +- examples/ListPeople.java | 2 +- examples/add_person.cc | 2 +- examples/add_person.py | 2 +- examples/addressbook.proto | 2 +- examples/list_people.cc | 4 ++-- examples/list_people.py | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) (limited to 'examples') diff --git a/examples/AddPerson.java b/examples/AddPerson.java index 259cfb7b..c262ab7e 100644 --- a/examples/AddPerson.java +++ b/examples/AddPerson.java @@ -80,7 +80,7 @@ class AddPerson { } // Add an address. - addressBook.addPersons( + addressBook.addPeople( PromptForAddress(new BufferedReader(new InputStreamReader(System.in)), System.out)); diff --git a/examples/ListPeople.java b/examples/ListPeople.java index 0294fb7a..78924305 100644 --- a/examples/ListPeople.java +++ b/examples/ListPeople.java @@ -9,7 +9,7 @@ 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.getPersonsList()) { + for (Person person: addressBook.getPeopleList()) { System.out.println("Person ID: " + person.getId()); System.out.println(" Name: " + person.getName()); if (!person.getEmail().isEmpty()) { diff --git a/examples/add_person.cc b/examples/add_person.cc index e71d3844..9bec4b37 100644 --- a/examples/add_person.cc +++ b/examples/add_person.cc @@ -77,7 +77,7 @@ int main(int argc, char* argv[]) { } // Add an address. - PromptForAddress(address_book.add_persons()); + 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 919a1a17..fd81c982 100755 --- a/examples/add_person.py +++ b/examples/add_person.py @@ -50,7 +50,7 @@ except IOError: print sys.argv[1] + ": File not found. Creating a new file." # Add an address. -PromptForAddress(address_book.persons.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 64cb7acf..bfdceeaf 100644 --- a/examples/addressbook.proto +++ b/examples/addressbook.proto @@ -29,5 +29,5 @@ message Person { // Our address book file is just one of these. message AddressBook { - repeated Person persons = 1; + repeated Person people = 1; } diff --git a/examples/list_people.cc b/examples/list_people.cc index 3daa3159..68e5666d 100644 --- a/examples/list_people.cc +++ b/examples/list_people.cc @@ -8,8 +8,8 @@ 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.persons_size(); i++) { - const tutorial::Person& person = address_book.persons(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; diff --git a/examples/list_people.py b/examples/list_people.py index e0658493..755de901 100755 --- a/examples/list_people.py +++ b/examples/list_people.py @@ -7,7 +7,7 @@ import sys # Iterates though all people in the AddressBook and prints info about them. def ListPeople(address_book): - for person in address_book.persons: + for person in address_book.people: print "Person ID:", person.id print " Name:", person.name if person.email != "": -- cgit v1.2.3