From bc00484bf77225cdad8f0125ca065ee5ccc756e2 Mon Sep 17 00:00:00 2001 From: Sarah Zakarias Date: Tue, 23 Oct 2018 09:52:44 +0200 Subject: [PATCH] comments and formatting --- examples/Makefile | 1 + examples/README.md | 5 +++-- examples/add_person.dart | 11 +++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/examples/Makefile b/examples/Makefile index 41c9849770..39254bba4a 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -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 diff --git a/examples/README.md b/examples/README.md index 37372ce01e..843fdd6616 100644 --- a/examples/README.md +++ b/examples/README.md @@ -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 diff --git a/examples/add_person.dart b/examples/add_person.dart index 7aaa079191..a93ec60540 100644 --- a/examples/add_person.dart +++ b/examples/add_person.dart @@ -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 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 +}