Source release 15.2.0

This commit is contained in:
John W. Bruce
2019-06-28 16:02:52 -07:00
parent 2b26dee09c
commit 2990f23065
1236 changed files with 166886 additions and 142315 deletions

View File

@@ -119,6 +119,26 @@ 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.
### Dart
First, follow the instructions in [../README.md](../README.md) to install the Protocol Buffer Compiler (protoc).
Then, install the Dart Protocol Buffer plugin as described [here](https://github.com/dart-lang/dart-protoc-plugin#how-to-build-and-use).
Note, the executable `bin/protoc-gen-dart` must be in your `PATH` for `protoc` to find it.
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
if it does not exist. The second displays the data in the file.

View File

@@ -1,9 +1,11 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# This com_google_protobuf repository is required for proto_library rule.
# It provides the protocol compiler binary (i.e., protoc).
http_archive(
name = "com_google_protobuf",
strip_prefix = "protobuf-master",
urls = ["https://github.com/google/protobuf/archive/master.zip"],
urls = ["https://github.com/protocolbuffers/protobuf/archive/master.zip"],
)
# This com_google_protobuf_cc repository is required for cc_proto_library
@@ -13,14 +15,14 @@ http_archive(
http_archive(
name = "com_google_protobuf_cc",
strip_prefix = "protobuf-master",
urls = ["https://github.com/google/protobuf/archive/master.zip"],
urls = ["https://github.com/protocolbuffers/protobuf/archive/master.zip"],
)
# Similar to com_google_protobuf_cc but for Java (i.e., java_proto_library).
http_archive(
name = "com_google_protobuf_java",
strip_prefix = "protobuf-master",
urls = ["https://github.com/google/protobuf/archive/master.zip"],
urls = ["https://github.com/protocolbuffers/protobuf/archive/master.zip"],
)
# Similar to com_google_protobuf_cc but for Java lite. If you are building
@@ -29,7 +31,7 @@ http_archive(
http_archive(
name = "com_google_protobuf_javalite",
strip_prefix = "protobuf-javalite",
urls = ["https://github.com/google/protobuf/archive/javalite.zip"],
urls = ["https://github.com/protocolbuffers/protobuf/archive/javalite.zip"],
)
http_archive(
@@ -39,5 +41,10 @@ http_archive(
urls = ["https://github.com/bazelbuild/bazel-skylib/archive/2169ae1c374aab4a09aa90e65efe1a3aad4e279b.tar.gz"],
)
load("@bazel_skylib//:lib.bzl", "versions")
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
protobuf_deps()
load("@bazel_skylib//lib:versions.bzl", "versions")
versions.check(minimum_bazel_version = "0.5.4")

View File

@@ -0,0 +1,70 @@
import 'dart:io';
import 'dart_tutorial/addressbook.pb.dart';
// This function fills in a Person message based on user input.
Person promptForAddress() {
Person person = Person();
print('Enter person ID: ');
String input = stdin.readLineSync();
person.id = int.parse(input);
print('Enter name');
person.name = stdin.readLineSync();
print('Enter email address (blank for none) : ');
String email = stdin.readLineSync();
if (email.isNotEmpty) {
person.email = email;
}
while (true) {
print('Enter a phone number (or leave blank to finish): ');
String number = stdin.readLineSync();
if (number.isEmpty) break;
Person_PhoneNumber phoneNumber = Person_PhoneNumber();
phoneNumber.number = number;
print('Is this a mobile, home, or work phone? ');
String type = stdin.readLineSync();
switch (type) {
case 'mobile':
phoneNumber.type = Person_PhoneType.MOBILE;
break;
case 'home':
phoneNumber.type = Person_PhoneType.HOME;
break;
case 'work':
phoneNumber.type = Person_PhoneType.WORK;
break;
default:
print('Unknown phone type. Using default.');
}
person.phones.add(phoneNumber);
}
return person;
}
// Reads the entire address book from a file, adds one person based
// on user input, then writes it back out to the same file.
main(List<String> arguments) {
if (arguments.length != 1) {
print('Usage: add_person ADDRESS_BOOK_FILE');
exit(-1);
}
File file = File(arguments.first);
AddressBook addressBook;
if (!file.existsSync()) {
print('File not found. Creating new file.');
addressBook = AddressBook();
} else {
addressBook = AddressBook.fromBuffer(file.readAsBytesSync());
}
addressBook.people.add(promptForAddress());
file.writeAsBytes(addressBook.writeToBuffer());
}

View File

@@ -10,7 +10,7 @@ import (
"strings"
"github.com/golang/protobuf/proto"
pb "github.com/google/protobuf/examples/tutorial"
pb "github.com/protocolbuffers/protobuf/examples/tutorial"
)
func promptForAddress(r io.Reader) (*pb.Person, error) {

View File

@@ -5,7 +5,7 @@ import (
"testing"
"github.com/golang/protobuf/proto"
pb "github.com/google/protobuf/examples/tutorial"
pb "github.com/protocolbuffers/protobuf/examples/tutorial"
)
func TestPromptForAddressReturnsAddress(t *testing.T) {

View File

@@ -0,0 +1,47 @@
import 'dart:io';
import 'dart_tutorial/addressbook.pb.dart';
import 'dart_tutorial/addressbook.pbenum.dart';
// Iterates though all people in the AddressBook and prints info about them.
void printAddressBook(AddressBook addressBook) {
for (Person person in addressBook.people) {
print('Person ID: ${person.id}');
print(' Name: ${person.name}');
if (person.hasEmail()) {
print(' E-mail address:${person.email}');
}
for (Person_PhoneNumber phoneNumber in person.phones) {
switch (phoneNumber.type) {
case Person_PhoneType.MOBILE:
print(' Mobile phone #: ');
break;
case Person_PhoneType.HOME:
print(' Home phone #: ');
break;
case Person_PhoneType.WORK:
print(' Work phone #: ');
break;
default:
print(' Unknown phone #: ');
break;
}
print(phoneNumber.number);
}
}
}
// Reads the entire address book from a file and prints all
// the information inside.
main(List<String> arguments) {
if (arguments.length != 1) {
print('Usage: list_person ADDRESS_BOOK_FILE');
exit(-1);
}
// Read the existing address book.
File file = new File(arguments.first);
AddressBook addressBook = new AddressBook.fromBuffer(file.readAsBytesSync());
printAddressBook(addressBook);
}

View File

@@ -8,7 +8,7 @@ import (
"os"
"github.com/golang/protobuf/proto"
pb "github.com/google/protobuf/examples/tutorial"
pb "github.com/protocolbuffers/protobuf/examples/tutorial"
)
func writePerson(w io.Writer, p *pb.Person) {

View File

@@ -5,7 +5,7 @@ import (
"strings"
"testing"
pb "github.com/google/protobuf/examples/tutorial"
pb "github.com/protocolbuffers/protobuf/examples/tutorial"
)
func TestWritePersonWritesPerson(t *testing.T) {
@@ -34,7 +34,7 @@ func TestWritePersonWritesPerson(t *testing.T) {
func TestListPeopleWritesList(t *testing.T) {
buf := new(bytes.Buffer)
in := pb.AddressBook{People: []*pb.Person {
in := pb.AddressBook{People: []*pb.Person{
{
Name: "John Doe",
Id: 101,

View File

@@ -0,0 +1,5 @@
name: addressbook
description: dartlang.org example code.
dependencies:
protobuf:

View File

@@ -0,0 +1,60 @@
package(default_visibility = ["//visibility:public"])
licenses(["notice"]) # BSD/MIT-like license (for zlib)
_ZLIB_HEADERS = [
"crc32.h",
"deflate.h",
"gzguts.h",
"inffast.h",
"inffixed.h",
"inflate.h",
"inftrees.h",
"trees.h",
"zconf.h",
"zlib.h",
"zutil.h",
]
_ZLIB_PREFIXED_HEADERS = ["zlib/include/" + hdr for hdr in _ZLIB_HEADERS]
# In order to limit the damage from the `includes` propagation
# via `:zlib`, copy the public headers to a subdirectory and
# expose those.
genrule(
name = "copy_public_headers",
srcs = _ZLIB_HEADERS,
outs = _ZLIB_PREFIXED_HEADERS,
cmd = "cp $(SRCS) $(@D)/zlib/include/",
visibility = ["//visibility:private"],
)
cc_library(
name = "zlib",
srcs = [
"adler32.c",
"compress.c",
"crc32.c",
"deflate.c",
"gzclose.c",
"gzlib.c",
"gzread.c",
"gzwrite.c",
"infback.c",
"inffast.c",
"inflate.c",
"inftrees.c",
"trees.c",
"uncompr.c",
"zutil.c",
# Include the un-prefixed headers in srcs to work
# around the fact that zlib isn't consistent in its
# choice of <> or "" delimiter when including itself.
] + _ZLIB_HEADERS,
hdrs = _ZLIB_PREFIXED_HEADERS,
copts = [
"-Wno-unused-variable",
"-Wno-implicit-function-declaration",
],
includes = ["zlib/include/"],
)