Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
353b7a99
Commit
353b7a99
authored
Jul 21, 2015
by
Jan Tattermusch
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #627 from jtattermusch/addressbook_proto3
Update addressbook.proto and examples code to proto3
parents
d119a275
b0e5ba69
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
26 additions
and
26 deletions
+26
-26
AddPerson.java
examples/AddPerson.java
+2
-2
ListPeople.java
examples/ListPeople.java
+3
-3
add_person.cc
examples/add_person.cc
+2
-2
add_person.py
examples/add_person.py
+2
-2
addressbook.proto
examples/addressbook.proto
+9
-9
list_people.cc
examples/list_people.cc
+5
-5
list_people.py
examples/list_people.py
+3
-3
No files found.
examples/AddPerson.java
View file @
353b7a99
...
...
@@ -50,7 +50,7 @@ class AddPerson {
stdout
.
println
(
"Unknown phone type. Using default."
);
}
person
.
addPhone
(
phoneNumber
);
person
.
addPhone
s
(
phoneNumber
);
}
return
person
.
build
();
...
...
@@ -80,7 +80,7 @@ class AddPerson {
}
// Add an address.
addressBook
.
addPe
rson
(
addressBook
.
addPe
ople
(
PromptForAddress
(
new
BufferedReader
(
new
InputStreamReader
(
System
.
in
)),
System
.
out
));
...
...
examples/ListPeople.java
View file @
353b7a99
...
...
@@ -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
.
getPe
rson
List
())
{
for
(
Person
person:
addressBook
.
getPe
ople
List
())
{
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
.
getPhone
s
List
())
{
switch
(
phoneNumber
.
getType
())
{
case
MOBILE:
System
.
out
.
print
(
" Mobile phone #: "
);
...
...
examples/add_person.cc
View file @
353b7a99
...
...
@@ -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_phone
s
();
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_pe
rson
());
PromptForAddress
(
address_book
.
add_pe
ople
());
{
// Write the new address book back to disk.
...
...
examples/add_person.py
View file @
353b7a99
...
...
@@ -19,7 +19,7 @@ def PromptForAddress(person):
if
number
==
""
:
break
phone_number
=
person
.
phone
.
add
()
phone_number
=
person
.
phone
s
.
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
.
pe
rson
.
add
())
PromptForAddress
(
address_book
.
pe
ople
.
add
())
# Write the new address book back to disk.
f
=
open
(
sys
.
argv
[
1
],
"wb"
)
...
...
examples/addressbook.proto
View file @
353b7a99
// See README.txt for information and build instructions.
syntax
=
"proto
2
"
;
syntax
=
"proto
3
"
;
package
tutorial
;
option
java_package
=
"com.example.tutorial"
;
option
java_outer_classname
=
"AddressBookProtos"
;
option
csharp_namespace
=
"Google.Proto
colBuffers
.Examples.AddressBook"
;
option
csharp_namespace
=
"Google.Proto
buf
.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
phone
s
=
4
;
}
// Our address book file is just one of these.
message
AddressBook
{
repeated
Person
pe
rson
=
1
;
repeated
Person
pe
ople
=
1
;
}
examples/list_people.cc
View file @
353b7a99
...
...
@@ -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
.
pe
rson
_size
();
i
++
)
{
const
tutorial
::
Person
&
person
=
address_book
.
pe
rson
(
i
);
for
(
int
i
=
0
;
i
<
address_book
.
pe
ople
_size
();
i
++
)
{
const
tutorial
::
Person
&
person
=
address_book
.
pe
ople
(
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
.
phone
s
_size
();
j
++
)
{
const
tutorial
::
Person
::
PhoneNumber
&
phone_number
=
person
.
phone
s
(
j
);
switch
(
phone_number
.
type
())
{
case
tutorial
:
:
Person
::
MOBILE
:
...
...
examples/list_people.py
View file @
353b7a99
...
...
@@ -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
.
pe
rson
:
for
person
in
address_book
.
pe
ople
:
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
.
phone
s
:
if
phone_number
.
type
==
addressbook_pb2
.
Person
.
MOBILE
:
print
" Mobile phone #:"
,
elif
phone_number
.
type
==
addressbook_pb2
.
Person
.
HOME
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment