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
bc00484b
Commit
bc00484b
authored
6 years ago
by
Sarah Zakarias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
comments and formatting
parent
969397b7
No related merge requests found
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
9 deletions
+9
-9
Makefile
examples/Makefile
+1
-0
README.md
examples/README.md
+3
-2
add_person.dart
examples/add_person.dart
+5
-7
No files found.
examples/Makefile
View file @
bc00484b
...
...
@@ -36,6 +36,7 @@ protoc_middleman_go: addressbook.proto
protoc_middleman_dart
:
addressbook.proto
mkdir
-p
dart_tutorial
# make directory for the dart package
protoc
$$
PROTO_PATH
--dart_out
=
dart_tutorial addressbook.proto
protoc
-I
../src/
--dart_out
=
dart_tutorial ../src/google/protobuf/timestamp.proto
pub get
@
touch
protoc_middleman_dart
...
...
This diff is collapsed.
Click to expand it.
examples/README.md
View file @
bc00484b
...
...
@@ -119,7 +119,7 @@ is created if it does not exist. To view the data, run:
./list_people_go addressbook.data
Observe that the C++, Python,
and Java
examples in this directory run in a
Observe that the C++, Python,
Java, and Dart
examples in this directory run in a
similar way and can view/modify files created by the Go example and vice
versa.
...
...
@@ -134,9 +134,10 @@ Build the Dart samples in this directory with `make dart`.
To run the examples:
```
sh
$
dart add_person.dart addessbook.data
$
dart list_people.dart addressbook.data
```
The two programs take a protocol buffer encoded file as their parameter.
The first can be used to add a person to the file. The file is created
...
...
This diff is collapsed.
Click to expand it.
examples/add_person.dart
View file @
bc00484b
...
...
@@ -4,7 +4,6 @@ import 'dart_tutorial/addressbook.pb.dart';
// This function fills in a Person message based on user input.
Person
promtForAddress
(
)
{
Person
person
=
Person
();
print
(
'Enter person ID: '
);
...
...
@@ -20,9 +19,9 @@ Person promtForAddress() {
person
.
email
=
email
;
}
while
(
true
)
{
while
(
true
)
{
print
(
'Enter a phone number (or leave blank to finish): '
);
String
number
=
stdin
.
readLineSync
();
String
number
=
stdin
.
readLineSync
();
if
(
number
.
isEmpty
)
break
;
Person_PhoneNumber
phoneNumber
=
Person_PhoneNumber
();
...
...
@@ -31,7 +30,7 @@ Person promtForAddress() {
print
(
'Is this a mobile, home, or work phone? '
);
String
type
=
stdin
.
readLineSync
();
switch
(
type
)
{
switch
(
type
)
{
case
'mobile'
:
phoneNumber
.
type
=
Person_PhoneType
.
MOBILE
;
break
;
...
...
@@ -62,10 +61,10 @@ main(List<String> arguments) {
AddressBook
addressBook
;
if
(!
file
.
existsSync
())
{
print
(
'File not found. Creating new file.'
);
addressBook
=
AddressBook
();
addressBook
=
AddressBook
();
}
else
{
addressBook
=
AddressBook
.
fromBuffer
(
file
.
readAsBytesSync
());
}
addressBook
.
people
.
add
(
promtForAddress
());
file
.
writeAsBytes
(
addressBook
.
writeToBuffer
());
}
\ No newline at end of file
}
This diff is collapsed.
Click to expand it.
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