diff --git a/.gitmodules b/.gitmodules
index 434d01b3d5f..2d0c0097607 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -8,10 +8,10 @@
[submodule "third_party/protobuf"]
path = third_party/protobuf
url = https://github.com/google/protobuf.git
- branch = v3.0.0-alpha-3
+ branch = v3.0.0-beta-1
[submodule "third_party/gflags"]
path = third_party/gflags
url = https://github.com/gflags/gflags.git
[submodule "third_party/googletest"]
path = third_party/googletest
- url = git://github.com/google/googletest
+ url = https://github.com/google/googletest.git
diff --git a/BUILD b/BUILD
index 30721952515..e399daa38f1 100644
--- a/BUILD
+++ b/BUILD
@@ -51,6 +51,7 @@ cc_library(
"src/core/support/string.h",
"src/core/support/string_win32.h",
"src/core/support/thd_internal.h",
+ "src/core/support/time_precise.h",
"src/core/support/alloc.c",
"src/core/support/cmdline.c",
"src/core/support/cpu_iphone.c",
@@ -208,7 +209,6 @@ cc_library(
"src/core/json/json_reader.h",
"src/core/json/json_writer.h",
"src/core/profiling/timers.h",
- "src/core/profiling/timers_preciseclock.h",
"src/core/statistics/census_interface.h",
"src/core/statistics/census_rpc_stats.h",
"src/core/surface/byte_buffer_queue.h",
@@ -476,7 +476,6 @@ cc_library(
"src/core/json/json_reader.h",
"src/core/json/json_writer.h",
"src/core/profiling/timers.h",
- "src/core/profiling/timers_preciseclock.h",
"src/core/statistics/census_interface.h",
"src/core/statistics/census_rpc_stats.h",
"src/core/surface/byte_buffer_queue.h",
@@ -990,6 +989,7 @@ objc_library(
"src/core/support/string.h",
"src/core/support/string_win32.h",
"src/core/support/thd_internal.h",
+ "src/core/support/time_precise.h",
],
includes = [
"include",
@@ -1229,7 +1229,6 @@ objc_library(
"src/core/json/json_reader.h",
"src/core/json/json_writer.h",
"src/core/profiling/timers.h",
- "src/core/profiling/timers_preciseclock.h",
"src/core/statistics/census_interface.h",
"src/core/statistics/census_rpc_stats.h",
"src/core/surface/byte_buffer_queue.h",
diff --git a/Makefile b/Makefile
index 620508c19a4..ff4d51041a9 100644
--- a/Makefile
+++ b/Makefile
@@ -791,6 +791,7 @@ fling_server: $(BINDIR)/$(CONFIG)/fling_server
fling_stream_test: $(BINDIR)/$(CONFIG)/fling_stream_test
fling_test: $(BINDIR)/$(CONFIG)/fling_test
gen_hpack_tables: $(BINDIR)/$(CONFIG)/gen_hpack_tables
+gen_legal_metadata_characters: $(BINDIR)/$(CONFIG)/gen_legal_metadata_characters
gpr_cmdline_test: $(BINDIR)/$(CONFIG)/gpr_cmdline_test
gpr_env_test: $(BINDIR)/$(CONFIG)/gpr_env_test
gpr_file_test: $(BINDIR)/$(CONFIG)/gpr_file_test
@@ -874,9 +875,6 @@ interop_client: $(BINDIR)/$(CONFIG)/interop_client
interop_server: $(BINDIR)/$(CONFIG)/interop_server
interop_test: $(BINDIR)/$(CONFIG)/interop_test
mock_test: $(BINDIR)/$(CONFIG)/mock_test
-pubsub_client: $(BINDIR)/$(CONFIG)/pubsub_client
-pubsub_publisher_test: $(BINDIR)/$(CONFIG)/pubsub_publisher_test
-pubsub_subscriber_test: $(BINDIR)/$(CONFIG)/pubsub_subscriber_test
qps_driver: $(BINDIR)/$(CONFIG)/qps_driver
qps_interarrival_test: $(BINDIR)/$(CONFIG)/qps_interarrival_test
qps_openloop_test: $(BINDIR)/$(CONFIG)/qps_openloop_test
@@ -1650,8 +1648,8 @@ else
$(Q)(cd third_party/openssl ; CC="$(CC) $(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_EXTRA)" ./config no-asm $(OPENSSL_CONFIG_$(CONFIG)))
endif
endif
- $(Q)$(MAKE) -C third_party/openssl clean
- $(Q)(unset CPPFLAGS; $(MAKE) -C third_party/openssl build_crypto build_ssl)
+ $(Q)$(MAKE) -j 1 -C third_party/openssl clean
+ $(Q)(unset CPPFLAGS; $(MAKE) -j 1 -C third_party/openssl build_crypto build_ssl)
$(Q)mkdir -p $(LIBDIR)/$(CONFIG)/openssl
$(Q)cp third_party/openssl/libssl.a third_party/openssl/libcrypto.a $(LIBDIR)/$(CONFIG)/openssl
@@ -3384,7 +3382,7 @@ test_python: static_c
tools: tools_c tools_cxx
-tools_c: privatelibs_c $(BINDIR)/$(CONFIG)/gen_hpack_tables $(BINDIR)/$(CONFIG)/grpc_create_jwt $(BINDIR)/$(CONFIG)/grpc_fetch_oauth2 $(BINDIR)/$(CONFIG)/grpc_print_google_default_creds_token $(BINDIR)/$(CONFIG)/grpc_verify_jwt
+tools_c: privatelibs_c $(BINDIR)/$(CONFIG)/gen_hpack_tables $(BINDIR)/$(CONFIG)/gen_legal_metadata_characters $(BINDIR)/$(CONFIG)/grpc_create_jwt $(BINDIR)/$(CONFIG)/grpc_fetch_oauth2 $(BINDIR)/$(CONFIG)/grpc_print_google_default_creds_token $(BINDIR)/$(CONFIG)/grpc_verify_jwt
tools_cxx: privatelibs_cxx
@@ -3487,51 +3485,6 @@ $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc:
$(Q) mkdir -p $(@D)
$(Q) echo "$(GRPCXX_UNSECURE_PC_FILE)" | tr , '\n' >$@
-ifeq ($(NO_PROTOC),true)
-$(GENDIR)/examples/pubsub/empty.pb.cc: protoc_dep_error
-$(GENDIR)/examples/pubsub/empty.grpc.pb.cc: protoc_dep_error
-else
-$(GENDIR)/examples/pubsub/empty.pb.cc: examples/pubsub/empty.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS)
- $(E) "[PROTOC] Generating protobuf CC file from $<"
- $(Q) mkdir -p `dirname $@`
- $(Q) $(PROTOC) --cpp_out=$(GENDIR) $<
-
-$(GENDIR)/examples/pubsub/empty.grpc.pb.cc: examples/pubsub/empty.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS)
- $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<"
- $(Q) mkdir -p `dirname $@`
- $(Q) $(PROTOC) --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(BINDIR)/$(CONFIG)/grpc_cpp_plugin $<
-endif
-
-ifeq ($(NO_PROTOC),true)
-$(GENDIR)/examples/pubsub/label.pb.cc: protoc_dep_error
-$(GENDIR)/examples/pubsub/label.grpc.pb.cc: protoc_dep_error
-else
-$(GENDIR)/examples/pubsub/label.pb.cc: examples/pubsub/label.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS)
- $(E) "[PROTOC] Generating protobuf CC file from $<"
- $(Q) mkdir -p `dirname $@`
- $(Q) $(PROTOC) --cpp_out=$(GENDIR) $<
-
-$(GENDIR)/examples/pubsub/label.grpc.pb.cc: examples/pubsub/label.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS)
- $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<"
- $(Q) mkdir -p `dirname $@`
- $(Q) $(PROTOC) --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(BINDIR)/$(CONFIG)/grpc_cpp_plugin $<
-endif
-
-ifeq ($(NO_PROTOC),true)
-$(GENDIR)/examples/pubsub/pubsub.pb.cc: protoc_dep_error
-$(GENDIR)/examples/pubsub/pubsub.grpc.pb.cc: protoc_dep_error
-else
-$(GENDIR)/examples/pubsub/pubsub.pb.cc: examples/pubsub/pubsub.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS)
- $(E) "[PROTOC] Generating protobuf CC file from $<"
- $(Q) mkdir -p `dirname $@`
- $(Q) $(PROTOC) --cpp_out=$(GENDIR) $<
-
-$(GENDIR)/examples/pubsub/pubsub.grpc.pb.cc: examples/pubsub/pubsub.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS)
- $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<"
- $(Q) mkdir -p `dirname $@`
- $(Q) $(PROTOC) --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(BINDIR)/$(CONFIG)/grpc_cpp_plugin $<
-endif
-
ifeq ($(NO_PROTOC),true)
$(GENDIR)/test/cpp/qps/perf_db.pb.cc: protoc_dep_error
$(GENDIR)/test/cpp/qps/perf_db.grpc.pb.cc: protoc_dep_error
@@ -4791,6 +4744,7 @@ LIBGRPC++_TEST_UTIL_SRC = \
$(GENDIR)/test/cpp/util/echo_duplicate.pb.cc $(GENDIR)/test/cpp/util/echo_duplicate.grpc.pb.cc \
test/cpp/util/cli_call.cc \
test/cpp/util/create_test_channel.cc \
+ test/cpp/util/string_ref_helper.cc \
test/cpp/util/subprocess.cc \
@@ -4837,6 +4791,7 @@ endif
endif
$(OBJDIR)/$(CONFIG)/test/cpp/util/cli_call.o: $(GENDIR)/test/cpp/util/messages.pb.cc $(GENDIR)/test/cpp/util/messages.grpc.pb.cc $(GENDIR)/test/cpp/util/echo.pb.cc $(GENDIR)/test/cpp/util/echo.grpc.pb.cc $(GENDIR)/test/cpp/util/echo_duplicate.pb.cc $(GENDIR)/test/cpp/util/echo_duplicate.grpc.pb.cc
$(OBJDIR)/$(CONFIG)/test/cpp/util/create_test_channel.o: $(GENDIR)/test/cpp/util/messages.pb.cc $(GENDIR)/test/cpp/util/messages.grpc.pb.cc $(GENDIR)/test/cpp/util/echo.pb.cc $(GENDIR)/test/cpp/util/echo.grpc.pb.cc $(GENDIR)/test/cpp/util/echo_duplicate.pb.cc $(GENDIR)/test/cpp/util/echo_duplicate.grpc.pb.cc
+$(OBJDIR)/$(CONFIG)/test/cpp/util/string_ref_helper.o: $(GENDIR)/test/cpp/util/messages.pb.cc $(GENDIR)/test/cpp/util/messages.grpc.pb.cc $(GENDIR)/test/cpp/util/echo.pb.cc $(GENDIR)/test/cpp/util/echo.grpc.pb.cc $(GENDIR)/test/cpp/util/echo_duplicate.pb.cc $(GENDIR)/test/cpp/util/echo_duplicate.grpc.pb.cc
$(OBJDIR)/$(CONFIG)/test/cpp/util/subprocess.o: $(GENDIR)/test/cpp/util/messages.pb.cc $(GENDIR)/test/cpp/util/messages.grpc.pb.cc $(GENDIR)/test/cpp/util/echo.pb.cc $(GENDIR)/test/cpp/util/echo.grpc.pb.cc $(GENDIR)/test/cpp/util/echo_duplicate.pb.cc $(GENDIR)/test/cpp/util/echo_duplicate.grpc.pb.cc
@@ -5200,59 +5155,6 @@ endif
$(OBJDIR)/$(CONFIG)/test/cpp/interop/server.o: $(GENDIR)/test/proto/empty.pb.cc $(GENDIR)/test/proto/empty.grpc.pb.cc $(GENDIR)/test/proto/messages.pb.cc $(GENDIR)/test/proto/messages.grpc.pb.cc $(GENDIR)/test/proto/test.pb.cc $(GENDIR)/test/proto/test.grpc.pb.cc
-LIBPUBSUB_CLIENT_LIB_SRC = \
- $(GENDIR)/examples/pubsub/label.pb.cc $(GENDIR)/examples/pubsub/label.grpc.pb.cc \
- $(GENDIR)/examples/pubsub/empty.pb.cc $(GENDIR)/examples/pubsub/empty.grpc.pb.cc \
- $(GENDIR)/examples/pubsub/pubsub.pb.cc $(GENDIR)/examples/pubsub/pubsub.grpc.pb.cc \
- examples/pubsub/publisher.cc \
- examples/pubsub/subscriber.cc \
-
-
-LIBPUBSUB_CLIENT_LIB_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBPUBSUB_CLIENT_LIB_SRC))))
-
-ifeq ($(NO_SECURE),true)
-
-# You can't build secure libraries if you don't have OpenSSL.
-
-$(LIBDIR)/$(CONFIG)/libpubsub_client_lib.a: openssl_dep_error
-
-
-else
-
-ifeq ($(NO_PROTOBUF),true)
-
-# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
-
-$(LIBDIR)/$(CONFIG)/libpubsub_client_lib.a: protobuf_dep_error
-
-
-else
-
-$(LIBDIR)/$(CONFIG)/libpubsub_client_lib.a: $(ZLIB_DEP) $(OPENSSL_DEP) $(PROTOBUF_DEP) $(LIBPUBSUB_CLIENT_LIB_OBJS)
- $(E) "[AR] Creating $@"
- $(Q) mkdir -p `dirname $@`
- $(Q) rm -f $(LIBDIR)/$(CONFIG)/libpubsub_client_lib.a
- $(Q) $(AR) rcs $(LIBDIR)/$(CONFIG)/libpubsub_client_lib.a $(LIBPUBSUB_CLIENT_LIB_OBJS)
-ifeq ($(SYSTEM),Darwin)
- $(Q) ranlib $(LIBDIR)/$(CONFIG)/libpubsub_client_lib.a
-endif
-
-
-
-
-endif
-
-endif
-
-ifneq ($(NO_SECURE),true)
-ifneq ($(NO_DEPS),true)
--include $(LIBPUBSUB_CLIENT_LIB_OBJS:.o=.dep)
-endif
-endif
-$(OBJDIR)/$(CONFIG)/examples/pubsub/publisher.o: $(GENDIR)/examples/pubsub/label.pb.cc $(GENDIR)/examples/pubsub/label.grpc.pb.cc $(GENDIR)/examples/pubsub/empty.pb.cc $(GENDIR)/examples/pubsub/empty.grpc.pb.cc $(GENDIR)/examples/pubsub/pubsub.pb.cc $(GENDIR)/examples/pubsub/pubsub.grpc.pb.cc
-$(OBJDIR)/$(CONFIG)/examples/pubsub/subscriber.o: $(GENDIR)/examples/pubsub/label.pb.cc $(GENDIR)/examples/pubsub/label.grpc.pb.cc $(GENDIR)/examples/pubsub/empty.pb.cc $(GENDIR)/examples/pubsub/empty.grpc.pb.cc $(GENDIR)/examples/pubsub/pubsub.pb.cc $(GENDIR)/examples/pubsub/pubsub.grpc.pb.cc
-
-
LIBQPS_SRC = \
$(GENDIR)/test/cpp/qps/qpstest.pb.cc $(GENDIR)/test/cpp/qps/qpstest.grpc.pb.cc \
$(GENDIR)/test/cpp/qps/perf_db.pb.cc $(GENDIR)/test/cpp/qps/perf_db.grpc.pb.cc \
@@ -7118,6 +7020,35 @@ endif
endif
+GEN_LEGAL_METADATA_CHARACTERS_SRC = \
+ tools/codegen/core/gen_legal_metadata_characters.c \
+
+GEN_LEGAL_METADATA_CHARACTERS_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(GEN_LEGAL_METADATA_CHARACTERS_SRC))))
+ifeq ($(NO_SECURE),true)
+
+# You can't build secure targets if you don't have OpenSSL.
+
+$(BINDIR)/$(CONFIG)/gen_legal_metadata_characters: openssl_dep_error
+
+else
+
+$(BINDIR)/$(CONFIG)/gen_legal_metadata_characters: $(GEN_LEGAL_METADATA_CHARACTERS_OBJS)
+ $(E) "[LD] Linking $@"
+ $(Q) mkdir -p `dirname $@`
+ $(Q) $(LD) $(LDFLAGS) $(GEN_LEGAL_METADATA_CHARACTERS_OBJS) $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/gen_legal_metadata_characters
+
+endif
+
+$(OBJDIR)/$(CONFIG)/tools/codegen/core/gen_legal_metadata_characters.o:
+deps_gen_legal_metadata_characters: $(GEN_LEGAL_METADATA_CHARACTERS_OBJS:.o=.dep)
+
+ifneq ($(NO_SECURE),true)
+ifneq ($(NO_DEPS),true)
+-include $(GEN_LEGAL_METADATA_CHARACTERS_OBJS:.o=.dep)
+endif
+endif
+
+
GPR_CMDLINE_TEST_SRC = \
test/core/support/cmdline_test.c \
@@ -8941,16 +8872,16 @@ $(BINDIR)/$(CONFIG)/auth_property_iterator_test: protobuf_dep_error
else
-$(BINDIR)/$(CONFIG)/auth_property_iterator_test: $(PROTOBUF_DEP) $(AUTH_PROPERTY_ITERATOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
+$(BINDIR)/$(CONFIG)/auth_property_iterator_test: $(PROTOBUF_DEP) $(AUTH_PROPERTY_ITERATOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
$(E) "[LD] Linking $@"
$(Q) mkdir -p `dirname $@`
- $(Q) $(LDXX) $(LDFLAGS) $(AUTH_PROPERTY_ITERATOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/auth_property_iterator_test
+ $(Q) $(LDXX) $(LDFLAGS) $(AUTH_PROPERTY_ITERATOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/auth_property_iterator_test
endif
endif
-$(OBJDIR)/$(CONFIG)/test/cpp/common/auth_property_iterator_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
+$(OBJDIR)/$(CONFIG)/test/cpp/common/auth_property_iterator_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
deps_auth_property_iterator_test: $(AUTH_PROPERTY_ITERATOR_TEST_OBJS:.o=.dep)
ifneq ($(NO_SECURE),true)
@@ -9718,126 +9649,6 @@ endif
endif
-PUBSUB_CLIENT_SRC = \
- examples/pubsub/main.cc \
-
-PUBSUB_CLIENT_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(PUBSUB_CLIENT_SRC))))
-ifeq ($(NO_SECURE),true)
-
-# You can't build secure targets if you don't have OpenSSL.
-
-$(BINDIR)/$(CONFIG)/pubsub_client: openssl_dep_error
-
-else
-
-
-ifeq ($(NO_PROTOBUF),true)
-
-# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+.
-
-$(BINDIR)/$(CONFIG)/pubsub_client: protobuf_dep_error
-
-else
-
-$(BINDIR)/$(CONFIG)/pubsub_client: $(PROTOBUF_DEP) $(PUBSUB_CLIENT_OBJS) $(LIBDIR)/$(CONFIG)/libpubsub_client_lib.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a
- $(E) "[LD] Linking $@"
- $(Q) mkdir -p `dirname $@`
- $(Q) $(LDXX) $(LDFLAGS) $(PUBSUB_CLIENT_OBJS) $(LIBDIR)/$(CONFIG)/libpubsub_client_lib.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/pubsub_client
-
-endif
-
-endif
-
-$(OBJDIR)/$(CONFIG)/examples/pubsub/main.o: $(LIBDIR)/$(CONFIG)/libpubsub_client_lib.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a
-deps_pubsub_client: $(PUBSUB_CLIENT_OBJS:.o=.dep)
-
-ifneq ($(NO_SECURE),true)
-ifneq ($(NO_DEPS),true)
--include $(PUBSUB_CLIENT_OBJS:.o=.dep)
-endif
-endif
-
-
-PUBSUB_PUBLISHER_TEST_SRC = \
- examples/pubsub/publisher_test.cc \
-
-PUBSUB_PUBLISHER_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(PUBSUB_PUBLISHER_TEST_SRC))))
-ifeq ($(NO_SECURE),true)
-
-# You can't build secure targets if you don't have OpenSSL.
-
-$(BINDIR)/$(CONFIG)/pubsub_publisher_test: openssl_dep_error
-
-else
-
-
-ifeq ($(NO_PROTOBUF),true)
-
-# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+.
-
-$(BINDIR)/$(CONFIG)/pubsub_publisher_test: protobuf_dep_error
-
-else
-
-$(BINDIR)/$(CONFIG)/pubsub_publisher_test: $(PROTOBUF_DEP) $(PUBSUB_PUBLISHER_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libpubsub_client_lib.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
- $(E) "[LD] Linking $@"
- $(Q) mkdir -p `dirname $@`
- $(Q) $(LDXX) $(LDFLAGS) $(PUBSUB_PUBLISHER_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libpubsub_client_lib.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/pubsub_publisher_test
-
-endif
-
-endif
-
-$(OBJDIR)/$(CONFIG)/examples/pubsub/publisher_test.o: $(LIBDIR)/$(CONFIG)/libpubsub_client_lib.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
-deps_pubsub_publisher_test: $(PUBSUB_PUBLISHER_TEST_OBJS:.o=.dep)
-
-ifneq ($(NO_SECURE),true)
-ifneq ($(NO_DEPS),true)
--include $(PUBSUB_PUBLISHER_TEST_OBJS:.o=.dep)
-endif
-endif
-
-
-PUBSUB_SUBSCRIBER_TEST_SRC = \
- examples/pubsub/subscriber_test.cc \
-
-PUBSUB_SUBSCRIBER_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(PUBSUB_SUBSCRIBER_TEST_SRC))))
-ifeq ($(NO_SECURE),true)
-
-# You can't build secure targets if you don't have OpenSSL.
-
-$(BINDIR)/$(CONFIG)/pubsub_subscriber_test: openssl_dep_error
-
-else
-
-
-ifeq ($(NO_PROTOBUF),true)
-
-# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+.
-
-$(BINDIR)/$(CONFIG)/pubsub_subscriber_test: protobuf_dep_error
-
-else
-
-$(BINDIR)/$(CONFIG)/pubsub_subscriber_test: $(PROTOBUF_DEP) $(PUBSUB_SUBSCRIBER_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libpubsub_client_lib.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
- $(E) "[LD] Linking $@"
- $(Q) mkdir -p `dirname $@`
- $(Q) $(LDXX) $(LDFLAGS) $(PUBSUB_SUBSCRIBER_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libpubsub_client_lib.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/pubsub_subscriber_test
-
-endif
-
-endif
-
-$(OBJDIR)/$(CONFIG)/examples/pubsub/subscriber_test.o: $(LIBDIR)/$(CONFIG)/libpubsub_client_lib.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
-deps_pubsub_subscriber_test: $(PUBSUB_SUBSCRIBER_TEST_OBJS:.o=.dep)
-
-ifneq ($(NO_SECURE),true)
-ifneq ($(NO_DEPS),true)
--include $(PUBSUB_SUBSCRIBER_TEST_OBJS:.o=.dep)
-endif
-endif
-
-
QPS_DRIVER_SRC = \
test/cpp/qps/qps_driver.cc \
@@ -10151,16 +9962,16 @@ $(BINDIR)/$(CONFIG)/secure_auth_context_test: protobuf_dep_error
else
-$(BINDIR)/$(CONFIG)/secure_auth_context_test: $(PROTOBUF_DEP) $(SECURE_AUTH_CONTEXT_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
+$(BINDIR)/$(CONFIG)/secure_auth_context_test: $(PROTOBUF_DEP) $(SECURE_AUTH_CONTEXT_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
$(E) "[LD] Linking $@"
$(Q) mkdir -p `dirname $@`
- $(Q) $(LDXX) $(LDFLAGS) $(SECURE_AUTH_CONTEXT_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/secure_auth_context_test
+ $(Q) $(LDXX) $(LDFLAGS) $(SECURE_AUTH_CONTEXT_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/secure_auth_context_test
endif
endif
-$(OBJDIR)/$(CONFIG)/test/cpp/common/secure_auth_context_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
+$(OBJDIR)/$(CONFIG)/test/cpp/common/secure_auth_context_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
deps_secure_auth_context_test: $(SECURE_AUTH_CONTEXT_TEST_OBJS:.o=.dep)
ifneq ($(NO_SECURE),true)
@@ -20612,8 +20423,6 @@ ifneq ($(OPENSSL_DEP),)
# This is to ensure the embedded OpenSSL is built beforehand, properly
# installing headers to their final destination on the drive. We need this
# otherwise parallel compilation will fail if a source is compiled first.
-examples/pubsub/publisher.cc: $(OPENSSL_DEP)
-examples/pubsub/subscriber.cc: $(OPENSSL_DEP)
src/core/httpcli/httpcli_security_connector.c: $(OPENSSL_DEP)
src/core/security/base64.c: $(OPENSSL_DEP)
src/core/security/client_auth_filter.c: $(OPENSSL_DEP)
@@ -20670,6 +20479,7 @@ test/cpp/qps/timer.cc: $(OPENSSL_DEP)
test/cpp/util/benchmark_config.cc: $(OPENSSL_DEP)
test/cpp/util/cli_call.cc: $(OPENSSL_DEP)
test/cpp/util/create_test_channel.cc: $(OPENSSL_DEP)
+test/cpp/util/string_ref_helper.cc: $(OPENSSL_DEP)
test/cpp/util/subprocess.cc: $(OPENSSL_DEP)
test/cpp/util/test_config.cc: $(OPENSSL_DEP)
endif
diff --git a/README.md b/README.md
index f8306298162..ab1004f9d5a 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@ Copyright 2015 Google Inc.
#Documentation
-You can find more detailed documentation and examples in the [grpc-common repository](http://github.com/grpc/grpc-common).
+You can find more detailed documentation and examples in the [doc](doc) and [examples](examples) directories respectively.
#Installation
@@ -95,7 +95,7 @@ messages are delivered in the order they were sent.
#Protocol
-The [gRPC protocol](https://github.com/grpc/grpc-common/blob/master/PROTOCOL-HTTP2.md) specifies the abstract requirements for communication between
+The [gRPC protocol](doc/PROTOCOL-HTTP2.md) specifies the abstract requirements for communication between
clients and servers. A concrete embedding over HTTP/2 completes the picture by
fleshing out the details of each of the required operations.
diff --git a/build.json b/build.json
index 02cee31d082..693b825ef0e 100644
--- a/build.json
+++ b/build.json
@@ -180,7 +180,6 @@
"src/core/json/json_reader.h",
"src/core/json/json_writer.h",
"src/core/profiling/timers.h",
- "src/core/profiling/timers_preciseclock.h",
"src/core/statistics/census_interface.h",
"src/core/statistics/census_rpc_stats.h",
"src/core/surface/byte_buffer_queue.h",
@@ -403,7 +402,8 @@
"src/core/support/stack_lockfree.h",
"src/core/support/string.h",
"src/core/support/string_win32.h",
- "src/core/support/thd_internal.h"
+ "src/core/support/thd_internal.h",
+ "src/core/support/time_precise.h"
],
"src": [
"src/core/support/alloc.c",
@@ -662,6 +662,7 @@
"headers": [
"test/cpp/util/cli_call.h",
"test/cpp/util/create_test_channel.h",
+ "test/cpp/util/string_ref_helper.h",
"test/cpp/util/subprocess.h"
],
"src": [
@@ -670,6 +671,7 @@
"test/cpp/util/echo_duplicate.proto",
"test/cpp/util/cli_call.cc",
"test/cpp/util/create_test_channel.cc",
+ "test/cpp/util/string_ref_helper.cc",
"test/cpp/util/subprocess.cc"
],
"deps": [
@@ -810,27 +812,6 @@
"grpc++_test_config"
]
},
- {
- "name": "pubsub_client_lib",
- "build": "do_not_build",
- "language": "c++",
- "headers": [
- "examples/pubsub/publisher.h",
- "examples/pubsub/subscriber.h"
- ],
- "src": [
- "examples/pubsub/label.proto",
- "examples/pubsub/empty.proto",
- "examples/pubsub/pubsub.proto",
- "examples/pubsub/publisher.cc",
- "examples/pubsub/subscriber.cc"
- ],
- "deps": [
- "grpc++",
- "grpc",
- "gpr"
- ]
- },
{
"name": "qps",
"build": "private",
@@ -1147,6 +1128,15 @@
"grpc"
]
},
+ {
+ "name": "gen_legal_metadata_characters",
+ "build": "tool",
+ "language": "c",
+ "src": [
+ "tools/codegen/core/gen_legal_metadata_characters.c"
+ ],
+ "deps": []
+ },
{
"name": "gpr_cmdline_test",
"build": "test",
@@ -2017,8 +2007,11 @@
"test/cpp/common/auth_property_iterator_test.cc"
],
"deps": [
+ "grpc++_test_util",
+ "grpc_test_util",
"grpc++",
"grpc",
+ "gpr_test_util",
"gpr"
]
},
@@ -2354,58 +2347,6 @@
"gpr"
]
},
- {
- "name": "pubsub_client",
- "build": "do_not_build",
- "run": false,
- "language": "c++",
- "src": [
- "examples/pubsub/main.cc"
- ],
- "deps": [
- "pubsub_client_lib",
- "grpc_test_util",
- "grpc++",
- "grpc",
- "gpr_test_util",
- "gpr",
- "grpc++_test_config"
- ]
- },
- {
- "name": "pubsub_publisher_test",
- "build": "do_not_build",
- "language": "c++",
- "src": [
- "examples/pubsub/publisher_test.cc"
- ],
- "deps": [
- "pubsub_client_lib",
- "grpc++_test_util",
- "grpc_test_util",
- "grpc++",
- "grpc",
- "gpr_test_util",
- "gpr"
- ]
- },
- {
- "name": "pubsub_subscriber_test",
- "build": "do_not_build",
- "language": "c++",
- "src": [
- "examples/pubsub/subscriber_test.cc"
- ],
- "deps": [
- "pubsub_client_lib",
- "grpc++_test_util",
- "grpc_test_util",
- "grpc++",
- "grpc",
- "gpr_test_util",
- "gpr"
- ]
- },
{
"name": "qps_driver",
"build": "benchmark",
@@ -2569,8 +2510,11 @@
"test/cpp/common/secure_auth_context_test.cc"
],
"deps": [
+ "grpc++_test_util",
+ "grpc_test_util",
"grpc++",
"grpc",
+ "gpr_test_util",
"gpr"
]
},
diff --git a/doc/PROTOCOL-HTTP2.md b/doc/PROTOCOL-HTTP2.md
new file mode 100644
index 00000000000..d3fbb60d603
--- /dev/null
+++ b/doc/PROTOCOL-HTTP2.md
@@ -0,0 +1,192 @@
+# gRPC over HTTP2
+
+## Introduction
+This document serves as a detailed description for an implementation of gRPC carried over HTTP2 draft 17 framing. It assumes familiarity with the HTTP2 specification.
+
+## Protocol
+Production rules are using ABNF syntax.
+
+### Outline
+
+The following is the general sequence of message atoms in a GRPC request & response message stream
+
+* Request → Request-Headers *Delimited-Message EOS
+* Response → (Response-Headers *Delimited-Message Trailers) / Trailers-Only
+
+
+### Requests
+
+* Request → Request-Headers *Delimited-Message EOS
+
+Request-Headers are delivered as HTTP2 headers in HEADERS + CONTINUATION frames.
+
+* **Request-Headers** → Call-Definition *Custom-Metadata
+* **Call-Definition** → Method Scheme Path TE [Authority] [Timeout] [Content-Type] [Message-Type] [Message-Encoding] [Message-Accept-Encoding] [User-Agent]
+* **Method** → “:method POST”
+* **Scheme** → “:scheme ” (“http” / “https”)
+* **Path** → “:path” {_path identifying method within exposed API_}
+* **Authority** → “:authority” {_virtual host name of authority_}
+* **TE** → “te” “trailers” # Used to detect incompatible proxies
+* **Timeout** → “grpc-timeout” TimeoutValue TimeoutUnit
+* **TimeoutValue** → {_positive integer as ASCII string of at most 8 digits_}
+* **TimeoutUnit** → Hour / Minute / Second / Millisecond / Microsecond / Nanosecond
+* **Hour** → “H”
+* **Minute** → “M”
+* **Second** → “S”
+* **Millisecond** → “m”
+* **Microsecond** → “u”
+* **Nanosecond** → “n”
+* **Content-Type** → “content-type” “application/grpc” [(“+proto” / “+json” / {_custom_})]
+* **Content-Coding** → “gzip” / “deflate” / “snappy” / {_custom_}
+* **Message-Encoding** → “grpc-encoding” Content-Coding
+* **Message-Accept-Encoding** → “grpc-accept-encoding” Content-Coding *("," Content-Coding)
+* **User-Agent** → “user-agent” {_structured user-agent string_}
+* **Message-Type** → “grpc-message-type” {_type name for message schema_}
+* **Custom-Metadata** → Binary-Header / ASCII-Header
+* **Binary-Header** → {lowercase ASCII header name ending in “-bin” } {_base64 encoded value_}
+* **ASCII-Header** → {lowercase ASCII header name} {_value_}
+
+
+HTTP2 requires that reserved headers, ones starting with “:” appear before all other headers. Additionally implementations should send **Timeout** immediately after the reserved headers and they should send the **Call-Definition** headers before sending **Custom-Metadata**.
+
+If **Timeout** is omitted a server should assume an infinite timeout. Client implementations are free to send a default minimum timeout based on their deployment requirements.
+
+**Custom-Metadata** is an arbitrary set of key-value pairs defined by the application layer. Aside from transport limits on the total length of HTTP2 HEADERS the only other constraint is that header names starting with “grpc-” are reserved for future use.
+
+Note that HTTP2 does not allow arbitrary octet sequences for header values so binary header values must be encoded using Base64 as per https://tools.ietf.org/html/rfc4648#section-4. Implementations MUST accept padded and un-padded values and should emit un-padded values. Applications define binary headers by having their names end with “-bin”. Runtime libraries use this suffix to detect binary headers and properly apply base64 encoding & decoding as headers are sent and received.
+
+The repeated sequence of **Delimited-Message** items is delivered in DATA frames
+
+* **Delimited-Message** → Compressed-Flag Message-Length Message
+* **Compressed-Flag** → 0 / 1 # encoded as 1 byte unsigned integer
+* **Message-Length** → {_length of Message_} # encoded as 4 byte unsigned integer
+* **Message** → *{binary octet}
+
+A **Compressed-Flag** value of 1 indicates that the binary octet sequence of **Message** is compressed using the mechanism declared by the **Message-Encoding** header. A value of 0 indicates that no encoding of **Message** bytes has occurred. Compression contexts are NOT maintained over message boundaries, implementations must create a new context for each message in the stream. If the **Message-Encoding** header is omitted then the **Compressed-Flag** must be 0.
+
+For requests, **EOS** (end-of-stream) is indicated by the presence of the END_STREAM flag on the last received DATA frame. In scenarios where the **Request** stream needs to be closed but no data remains to be sent implementations MUST send an empty DATA frame with this flag set.
+
+###Responses
+
+* **Response** → (Response-Headers *Delimited-Message Trailers) / Trailers-Only
+* **Response-Headers** → HTTP-Status [Message-Encoding] [Message-Accept-Encoding] Content-Type *Custom-Metadata
+* **Trailers-Only** → HTTP-Status Content-Type Trailers
+* **Trailers** → Status [Status-Message] *Custom-Metadata
+* **HTTP-Status** → “:status 200”
+* **Status** → “grpc-status”
+* **Status-Message** → “grpc-message”
+
+**Response-Headers** & **Trailers-Only** are each delivered in a single HTTP2 HEADERS frame block. Most responses are expected to have both headers and trailers but **Trailers-Only** is permitted for calls that produce an immediate error. Status must be sent in **Trailers** even if the status code is OK.
+
+For responses end-of-stream is indicated by the presence of the END_STREAM flag on the last received HEADERS frame that carries **Trailers**.
+
+Implementations should expect broken deployments to send non-200 HTTP status codes in responses as well as a variety of non-GRPC content-types and to omit **Status** & **Status-Message**. Implementations must synthesize a **Status** & **Status-Message** to propagate to the application layer when this occurs.
+
+####Example
+
+Sample unary-call showing HTTP2 framing sequence
+
+**Request**
+
+```
+HEADERS (flags = END_HEADERS)
+:method = POST
+:scheme = http
+:path = /google.pubsub.v2.PublisherService/CreateTopic
+:authority = pubsub.googleapis.com
+grpc-timeout = 1S
+content-type = application/grpc+proto
+grpc-encoding = gzip
+authorization = Bearer y235.wef315yfh138vh31hv93hv8h3v
+
+DATA (flags = END_STREAM)
+
+```
+**Response**
+```
+HEADERS (flags = END_HEADERS)
+:status = 200
+grpc-encoding = gzip
+
+DATA
+
+
+HEADERS (flags = END_STREAM, END_HEADERS)
+grpc-status = 0 # OK
+trace-proto-bin = jher831yy13JHy3hc
+```
+####User Agents
+
+While the protocol does not require a user-agent to function it is recommended that clients provide a structured user-agent string that provides a basic description of the calling library, version & platform to facilitate issue diagnosis in heterogeneous environments. The following structure is recommended to library developers
+```
+User-Agent → “grpc-” Language ?(“-” Variant) “/” Version ?( “ (“ *(AdditionalProperty “;”) “)” )
+```
+E.g.
+
+```
+grpc-java/1.2.3
+grpc-ruby/1.2.3
+grpc-ruby-jruby/1.3.4
+grpc-java-android/0.9.1 (gingerbread/1.2.4; nexus5; tmobile)
+```
+####HTTP2 Transport Mapping
+
+#####Stream Identification
+All GRPC calls need to specify an internal ID. We will use HTTP2 stream-ids as call identifiers in this scheme. NOTE: These id’s are contextual to an open HTTP2 session and will not be unique within a given process that is handling more than one HTTP2 session nor can they be used as GUIDs.
+
+#####Data Frames
+DATA frame boundaries have no relation to **Delimited-Message** boundaries and implementations should make no assumptions about their alignment.
+
+#####Errors
+
+When an application or runtime error occurs during an RPC a **Status** and **Status-Message** are delivered in **Trailers**.
+
+In some cases it is possible that the framing of the message stream has become corrupt and the RPC runtime will choose to use an **RST_STREAM** frame to indicate this state to its peer. RPC runtime implementations should interpret RST_STREAM as immediate full-closure of the stream and should propagate an error up to the calling application layer.
+
+The following mapping from RST_STREAM error codes to GRPC error codes is applied.
+
+HTTP2 Code|GRPC Code
+----------|-----------
+NO_ERROR(0)|INTERNAL - An explicit GRPC status of OK should have been sent but this might be used to aggressively lameduck in some scenarios.
+PROTOCOL_ERROR(1)|INTERNAL
+INTERNAL_ERROR(2)|INTERNAL
+FLOW_CONTROL_ERROR(3)|INTERNAL
+SETTINGS_TIMEOUT(4)|INTERNAL
+STREAM_CLOSED|No mapping as there is no open stream to propagate to. Implementations should log.
+FRAME_SIZE_ERROR|INTERNAL
+REFUSED_STREAM|UNAVAILABLE - Indicates that no processing occurred and the request can be retried, possibly elsewhere.
+CANCEL(8)|Mapped to call cancellation when sent by a client.Mapped to CANCELLED when sent by a server. Note that servers should only use this mechanism when they need to cancel a call but the payload byte sequence is incomplete.
+COMPRESSION_ERROR|INTERNAL
+CONNECT_ERROR|INTERNAL
+ENHANCE_YOUR_CALM|RESOURCE_EXHAUSTED ...with additional error detail provided by runtime to indicate that the exhausted resource is bandwidth.
+INADEQUATE_SECURITY| PERMISSION_DENIED … with additional detail indicating that permission was denied as protocol is not secure enough for call.
+
+
+#####Security
+
+The HTTP2 specification mandates the use of TLS 1.2 or higher when TLS is used with HTTP2. It also places some additional constraints on the allowed ciphers in deployments to avoid known-problems as well as requiring SNI support. It is also expected that HTTP2 will be used in conjunction with proprietary transport security mechanisms about which the specification can make no meaningful recommendations.
+
+#####Connection Management
+######GOAWAY Frame
+Sent by servers to clients to indicate that they will no longer accept any new streams on the associated connections. This frame includes the id of the last successfully accepted stream by the server. Clients should consider any stream initiated after the last successfully accepted stream as UNAVAILABLE and retry the call elsewhere. Clients are free to continue working with the already accepted streams until they complete or the connection is terminated.
+
+Servers should send GOAWAY before terminating a connection to reliably inform clients which work has been accepted by the server and is being executed.
+
+######PING Frame
+Both clients and servers can send a PING frame that the peer must respond to by precisely echoing what they received. This is used to assert that the connection is still live as well as providing a means to estimate end-to-end latency. If a server initiated PING does not receive a response within the deadline expected by the runtime all outstanding calls on the server will be closed with a CANCELLED status. An expired client initiated PING will cause all calls to be closed with an UNAVAILABLE status. Note that the frequency of PINGs is highly dependent on the network environment, implementations are free to adjust PING frequency based on network and application requirements.
+
+######Connection failure
+If a detectable connection failure occurs on the client all calls will be closed with an UNAVAILABLE status. For servers open calls will be closed with a CANCELLED status.
+
+
+### Appendix A - GRPC for Protobuf
+
+The service interfaces declared by protobuf are easily mapped onto GRPC by code generation extensions to protoc. The following defines the mapping to be used
+
+
+* **Path** → / Service-Name / {_method name_}
+* **Service-Name** → ?( {_proto package name_} "." ) {_service name_}
+* **Message-Type** → {_fully qualified proto message name_}
+* **Content-Type** → "application/grpc+proto"
+
+
diff --git a/doc/grpc-auth-support.md b/doc/grpc-auth-support.md
new file mode 100644
index 00000000000..800fbedd80c
--- /dev/null
+++ b/doc/grpc-auth-support.md
@@ -0,0 +1,289 @@
+#gRPC Authentication support
+
+gRPC is designed to plug-in a number of authentication mechanisms. This document
+provides a quick overview of the various auth mechanisms supported, discusses
+the API with some examples, and concludes with a discussion of extensibility.
+More documentation and examples are coming soon!
+
+## Supported auth mechanisms
+
+###SSL/TLS
+gRPC has SSL/TLS integration and promotes the use of SSL/TLS to authenticate the
+server, and encrypt all the data exchanged between the client and the server.
+Optional mechanisms are available for clients to provide certificates to
+accomplish mutual authentication.
+
+###OAuth 2.0
+gRPC provides a generic mechanism (described below) to attach metadata to
+requests and responses. This mechanism can be used to attach OAuth 2.0 Access
+Tokens to RPCs being made at a client. Additional support for acquiring Access
+Tokens while accessing Google APIs through gRPC is provided for certain auth
+flows, demonstrated through code examples below.
+
+## API
+To reduce complexity and minimize API clutter, gRPC works with a unified concept
+of a Credentials object. Users construct gRPC credentials using corresponding
+bootstrap credentials (e.g., SSL client certs or Service Account Keys), and use
+the credentials while creating a gRPC channel to any server. Depending on the
+type of credential supplied, the channel uses the credentials during the initial
+SSL/TLS handshake with the server, or uses the credential to generate and
+attach Access Tokens to each request being made on the channel.
+
+###SSL/TLS for server authentication and encryption
+This is the simplest authentication scenario, where a client just wants to
+authenticate the server and encrypt all data.
+
+```cpp
+SslCredentialsOptions ssl_opts; // Options to override SSL params, empty by default
+// Create the credentials object by providing service account key in constructor
+std::unique_ptr creds = CredentialsFactory::SslCredentials(ssl_opts);
+// Create a channel using the credentials created in the previous step
+std::shared_ptr channel = CreateChannel(server_name, creds, channel_args);
+// Create a stub on the channel
+std::unique_ptr stub(Greeter::NewStub(channel));
+// Make actual RPC calls on the stub.
+grpc::Status s = stub->sayHello(&context, *request, response);
+```
+
+For advanced use cases such as modifying the root CA or using client certs,
+the corresponding options can be set in the SslCredentialsOptions parameter
+passed to the factory method.
+
+
+###Authenticating with Google
+
+gRPC applications can use a simple API to create a credential that works in various deployment scenarios.
+
+```cpp
+std::unique_ptr creds = CredentialsFactory::GoogleDefaultCredentials();
+// Create a channel, stub and make RPC calls (same as in the previous example)
+std::shared_ptr channel = CreateChannel(server_name, creds, channel_args);
+std::unique_ptr stub(Greeter::NewStub(channel));
+grpc::Status s = stub->sayHello(&context, *request, response);
+```
+
+This credential works for applications using Service Accounts as well as for
+applications running in [Google Compute Engine (GCE)](https://cloud.google.com/compute/). In the former case, the
+service account’s private keys are loaded from the file named in the environment
+variable `GOOGLE_APPLICATION_CREDENTIALS`. The
+keys are used to generate bearer tokens that are attached to each outgoing RPC
+on the corresponding channel.
+
+For applications running in GCE, a default service account and corresponding
+OAuth scopes can be configured during VM setup. At run-time, this credential
+handles communication with the authentication systems to obtain OAuth2 access
+tokens and attaches them to each outgoing RPC on the corresponding channel.
+Extending gRPC to support other authentication mechanisms
+The gRPC protocol is designed with a general mechanism for sending metadata
+associated with RPC. Clients can send metadata at the beginning of an RPC and
+servers can send back metadata at the beginning and end of the RPC. This
+provides a natural mechanism to support OAuth2 and other authentication
+mechanisms that need attach bearer tokens to individual request.
+
+In the simplest case, there is a single line of code required on the client
+to add a specific token as metadata to an RPC and a corresponding access on
+the server to retrieve this piece of metadata. The generation of the token
+on the client side and its verification at the server can be done separately.
+
+A deeper integration can be achieved by plugging in a gRPC credentials implementation for any custom authentication mechanism that needs to attach per-request tokens. gRPC internals also allow switching out SSL/TLS with other encryption mechanisms.
+
+## Examples
+
+These authentication mechanisms will be available in all gRPC's supported languages.
+The following sections demonstrate how authentication and authorization features described above appear in each language: more languages are coming soon.
+
+###SSL/TLS for server authentication and encryption (Ruby)
+```ruby
+# Base case - No encryption
+stub = Helloworld::Greeter::Stub.new('localhost:50051')
+...
+
+# With server authentication SSL/TLS
+creds = GRPC::Core::Credentials.new(load_certs) # load_certs typically loads a CA roots file
+stub = Helloworld::Greeter::Stub.new('localhost:50051', creds: creds)
+```
+
+###SSL/TLS for server authentication and encryption (C#)
+```csharp
+// Base case - No encryption
+var channel = new Channel("localhost:50051");
+var client = new Greeter.GreeterClient(channel);
+...
+
+// With server authentication SSL/TLS
+var credentials = new SslCredentials(File.ReadAllText("ca.pem")); // Load a CA file
+var channel = new Channel("localhost:50051", credentials);
+var client = new Greeter.GreeterClient(channel);
+```
+
+###SSL/TLS for server authentication and encryption (Objective-C)
+
+The default for Objective-C is to use SSL/TLS, as that's the most common use case when accessing
+remote APIs.
+
+```objective-c
+// Base case - With server authentication SSL/TLS
+HLWGreeter *client = [[HLWGreeter alloc] initWithHost:@"localhost:50051"];
+// Same as using @"https://localhost:50051".
+...
+
+// No encryption
+HLWGreeter *client = [[HLWGreeter alloc] initWithHost:@"http://localhost:50051"];
+// Specifying the HTTP scheme explicitly forces no encryption.
+```
+
+###SSL/TLS for server authentication and encryption (Python)
+```python
+# Base case - No encryption
+stub = early_adopter_create_GreeterService_stub('localhost', 50051)
+...
+
+# With server authentication SSL/TLS
+stub = early_adopter_create_GreeterService_stub(
+ 'localhost', 50051, secure=True, root_certificates=open('ca.pem').read())
+...
+```
+n.b.: the beta API will look different
+
+###Authenticating with Google (Ruby)
+```ruby
+# Base case - No encryption/authorization
+stub = Helloworld::Greeter::Stub.new('localhost:50051')
+...
+
+# Authenticating with Google
+require 'googleauth' # from http://www.rubydoc.info/gems/googleauth/0.1.0
+...
+creds = GRPC::Core::Credentials.new(load_certs) # load_certs typically loads a CA roots file
+scope = 'https://www.googleapis.com/auth/grpc-testing'
+authorization = Google::Auth.get_application_default(scope)
+stub = Helloworld::Greeter::Stub.new('localhost:50051',
+ creds: creds,
+ update_metadata: authorization.updater_proc)
+```
+
+###Authenticating with Google (Node.js)
+
+```node
+// Base case - No encryption/authorization
+var stub = new helloworld.Greeter('localhost:50051');
+...
+// Authenticating with Google
+var GoogleAuth = require('google-auth-library'); // from https://www.npmjs.com/package/google-auth-library
+...
+var creds = grpc.Credentials.createSsl(load_certs); // load_certs typically loads a CA roots file
+var scope = 'https://www.googleapis.com/auth/grpc-testing';
+(new GoogleAuth()).getApplicationDefault(function(err, auth) {
+ if (auth.createScopeRequired()) {
+ auth = auth.createScoped(scope);
+ }
+ var stub = new helloworld.Greeter('localhost:50051',
+ {credentials: creds},
+ grpc.getGoogleAuthDelegate(auth));
+});
+```
+
+###Authenticating with Google (C#)
+```csharp
+// Base case - No encryption/authorization
+var channel = new Channel("localhost:50051");
+var client = new Greeter.GreeterClient(channel);
+...
+
+// Authenticating with Google
+using Grpc.Auth; // from Grpc.Auth NuGet package
+...
+var credentials = new SslCredentials(File.ReadAllText("ca.pem")); // Load a CA file
+var channel = new Channel("localhost:50051", credentials);
+
+string scope = "https://www.googleapis.com/auth/grpc-testing";
+var authorization = GoogleCredential.GetApplicationDefault();
+if (authorization.IsCreateScopedRequired)
+{
+ authorization = credential.CreateScoped(new[] { scope });
+}
+var client = new Greeter.GreeterClient(channel,
+ new StubConfiguration(OAuth2InterceptorFactory.Create(credential)));
+```
+
+###Authenticating with Google (PHP)
+```php
+// Base case - No encryption/authorization
+$client = new helloworld\GreeterClient(
+ new Grpc\BaseStub('localhost:50051', []));
+...
+
+// Authenticating with Google
+// the environment variable "GOOGLE_APPLICATION_CREDENTIALS" needs to be set
+$scope = "https://www.googleapis.com/auth/grpc-testing";
+$auth = Google\Auth\ApplicationDefaultCredentials::getCredentials($scope);
+$opts = [
+ 'credentials' => Grpc\Credentials::createSsl(file_get_contents('ca.pem'));
+ 'update_metadata' => $auth->getUpdateMetadataFunc(),
+];
+
+$client = new helloworld\GreeterClient(
+ new Grpc\BaseStub('localhost:50051', $opts));
+
+```
+
+###Authenticating with Google (Objective-C)
+
+This example uses the [Google iOS Sign-In library](https://developers.google.com/identity/sign-in/ios/),
+but it's easily extrapolated to any other OAuth2 library.
+
+```objective-c
+// Base case - No authentication
+[client sayHelloWithRequest:request handler:^(HLWHelloReply *response, NSError *error) {
+ ...
+}];
+
+...
+
+// Authenticating with Google
+
+// When signing the user in, ask her for the relevant scopes.
+GIDSignIn.sharedInstance.scopes = @[@"https://www.googleapis.com/auth/grpc-testing"];
+
+...
+
+#import
+
+// Create a not-yet-started RPC. We want to set the request headers on this object before starting
+// it.
+ProtoRPC *call =
+ [client RPCToSayHelloWithRequest:request handler:^(HLWHelloReply *response, NSError *error) {
+ ...
+ }];
+
+// Set the access token to be used.
+NSString *accessToken = GIDSignIn.sharedInstance.currentUser.authentication.accessToken;
+call.requestMetadata[@"Authorization"] = [@"Bearer " stringByAppendingString:accessToken]}];
+
+// Start the RPC.
+[call start];
+```
+
+You can see a working example app, with a more detailed explanation, [here](examples/objective-c/auth_sample).
+
+### Authenticating with Google (Python)
+```python
+# Base case - No encryption
+stub = early_adopter_create_GreeterService_stub('localhost', 50051)
+...
+
+# With server authentication SSL/TLS
+import oauth2client.client
+credentials = oauth2client.GoogleCredentials.get_application_default()
+scope = 'https://www.googleapis.com/auth/grpc-testing'
+scoped_credentials = credentials.create_scoped([scope])
+access_token = scoped_credentials.get_access_token().access_token
+metadata_transformer = (
+ lambda x: [('Authorization', 'Bearer {}'.format(access_token))])
+
+stub = early_adopter_create_GreeterService_stub(
+ 'localhost', 50051, secure=True, root_certificates=open('ca.pem').read(),
+ metadata_transformer=metadata_transformer)
+...
+```
+n.b.: the beta API will look different
diff --git a/doc/interop-test-descriptions.md b/doc/interop-test-descriptions.md
index 84ceaa3081a..98cd5ab4fc3 100644
--- a/doc/interop-test-descriptions.md
+++ b/doc/interop-test-descriptions.md
@@ -4,7 +4,7 @@ Interoperability Test Case Descriptions
Client and server use
[test.proto](https://github.com/grpc/grpc/blob/master/test/proto/test.proto)
and the [gRPC over HTTP/2 v2
-protocol](https://github.com/grpc/grpc-common/blob/master/PROTOCOL-HTTP2.md).
+protocol](doc/PROTOCOL-HTTP2.md).
Client
------
@@ -91,6 +91,87 @@ Client asserts:
* clients are free to assert that the response payload body contents are zero
and comparing the entire response message against a golden response
+### large_compressed_unary
+
+This test verifies compressed unary calls succeed in sending messages. It
+sends one unary request for every combination of compression algorithm and
+payload type.
+
+In all scenarios, whether compression was actually performed is determined by
+the compression bit in the response's message flags. The response's compression
+value indicates which algorithm was used if said compression bit is set.
+
+
+Server features:
+* [UnaryCall][]
+* [Compressable Payload][]
+* [Uncompressable Payload][]
+* [Random Payload][]
+
+Procedure:
+ 1. Client calls UnaryCall with:
+
+ ```
+ {
+ response_compression:
+ response_type: COMPRESSABLE
+ response_size: 314159
+ payload:{
+ body: 271828 bytes of zeros
+ }
+ }
+ ```
+ Client asserts:
+ * call was successful
+ * response payload type is COMPRESSABLE
+ * response compression is consistent with the requested one.
+ * if `response_compression == NONE`, the response MUST NOT have the
+ compressed message flag set.
+ * if `response_compression != NONE`, the response MUST have the compressed
+ message flag set.
+ * response payload body is 314159 bytes in size
+ * clients are free to assert that the response payload body contents are
+ zero and comparing the entire response message against a golden response
+
+
+ 2. Client calls UnaryCall with:
+ ```
+ {
+ response_compression:
+ response_type: UNCOMPRESSABLE
+ response_size: 314159
+ payload:{
+ body: 271828 bytes of zeros
+ }
+ }
+ ```
+ Client asserts:
+ * call was successful
+ * response payload type is UNCOMPRESSABLE
+ * response compression is consistent with the requested one.
+ * the response MUST NOT have the compressed message flag set.
+ * response payload body is 314159 bytes in size
+ * clients are free to assert that the response payload body contents are
+ identical to the golden uncompressable data at `test/cpp/interop/rnd.dat`.
+
+
+ 3. Client calls UnaryCall with:
+ ```
+ {
+ response_compression:
+ response_type: RANDOM
+ response_size: 314159
+ payload:{
+ body: 271828 bytes of zeros
+ }
+ }
+ ```
+ Client asserts:
+ * call was successful
+ * response payload type is either COMPRESSABLE or UNCOMPRESSABLE
+ * the behavior is consistent with the randomly chosen incoming payload type,
+ as described in their respective sections.
+
### client_streaming
This test verifies that client-only streaming succeeds.
@@ -184,6 +265,112 @@ Client asserts:
* clients are free to assert that the response payload body contents are zero
and comparing the entire response messages against golden responses
+### server_compressed_streaming
+
+This test verifies that server-only compressed streaming succeeds.
+
+Server features:
+* [StreamingOutputCall][]
+* [Compressable Payload][]
+* [Uncompressable Payload][]
+* [Random Payload][]
+
+
+Procedure:
+ 1. Client calls StreamingOutputCall with:
+
+ ```
+ {
+ response_compression:
+ response_type:COMPRESSABLE
+ response_parameters:{
+ size: 31415
+ }
+ response_parameters:{
+ size: 9
+ }
+ response_parameters:{
+ size: 2653
+ }
+ response_parameters:{
+ size: 58979
+ }
+ }
+ ```
+
+ Client asserts:
+ * call was successful
+ * exactly four responses
+ * response payloads are COMPRESSABLE
+ * response compression is consistent with the requested one.
+ * if `response_compression == NONE`, the response MUST NOT have the
+ compressed message flag set.
+ * if `response_compression != NONE`, the response MUST have the compressed
+ message flag set.
+ * response payload bodies are sized (in order): 31415, 9, 2653, 58979
+ * clients are free to assert that the response payload body contents are
+ zero and comparing the entire response messages against golden responses
+
+
+ 2. Client calls StreamingOutputCall with:
+
+ ```
+ {
+ response_compression:
+ response_type:UNCOMPRESSABLE
+ response_parameters:{
+ size: 31415
+ }
+ response_parameters:{
+ size: 9
+ }
+ response_parameters:{
+ size: 2653
+ }
+ response_parameters:{
+ size: 58979
+ }
+ }
+ ```
+
+ Client asserts:
+ * call was successful
+ * exactly four responses
+ * response payloads are UNCOMPRESSABLE
+ * response compressions are consistent with the requested one.
+ * the responses MUST NOT have the compressed message flag set.
+ * response payload bodies are sized (in order): 31415, 9, 2653, 58979
+ * clients are free to assert that the body of the responses are identical to
+ the golden uncompressable data at `test/cpp/interop/rnd.dat`.
+
+
+ 3. Client calls StreamingOutputCall with:
+
+ ```
+ {
+ response_compression:
+ response_type:RANDOM
+ response_parameters:{
+ size: 31415
+ }
+ response_parameters:{
+ size: 9
+ }
+ response_parameters:{
+ size: 2653
+ }
+ response_parameters:{
+ size: 58979
+ }
+ }
+ ```
+
+ Client asserts:
+ * call was successful
+ * response payload type is either COMPRESSABLE or UNCOMPRESSABLE
+ * the behavior is consistent with the randomly chosen incoming payload type,
+ as described in their respective sections.
+
### ping_pong
This test verifies that full duplex bidi is supported.
@@ -825,6 +1012,21 @@ When the client requests COMPRESSABLE payload, the response includes a payload
of the size requested containing all zeros and the payload type is
COMPRESSABLE.
+### Uncompressable Payload
+[Uncompressable Payload]: #uncompressable-payload
+
+When the client requests UNCOMPRESSABLE payload, the response includes a payload
+of the size requested containing uncompressable data and the payload type is
+UNCOMPRESSABLE. A 512 kB dump from /dev/urandom is the current golden data,
+stored at `test/cpp/interop/rnd.dat`
+
+### Random Payload
+[Random Payload]: #random-payload
+
+When the client requests RANDOM payload, the response includes either a randomly
+chosen COMPRESSABLE or UNCOMPRESSABLE payload. The data and the payload type
+will be consistent with this choice.
+
### Echo Status
[Echo Status]: #echo-status
When the client sends a response_status in the request payload, the server closes
diff --git a/examples/README.md b/examples/README.md
new file mode 100644
index 00000000000..6465115e185
--- /dev/null
+++ b/examples/README.md
@@ -0,0 +1,450 @@
+
+# Getting started
+
+Welcome to the developer documentation for gRPC, a language-neutral,
+platform-neutral remote procedure call (RPC) system developed at Google.
+
+This document introduces you to gRPC with a quick overview and a simple
+Hello World example. You'll find more tutorials and reference docs in this repository - more documentation is coming soon!
+
+
+## Quick start
+You can find quick start guides for each language, including installation instructions, examples, and tutorials here:
+* [C++](examples/cpp)
+* [Java](https://github.com/grpc/grpc-java/tree/master/examples)
+* [Go](https://github.com/grpc/grpc-go/tree/master/examples)
+* [Ruby](examples/ruby)
+* [Node.js](examples/node)
+* [Android Java](examples/java/android)
+* [Python](examples/python/helloworld)
+* [C#](examples/csharp)
+* [Objective-C](examples/objective-c/route_guide)
+* [PHP](examples/php)
+
+## What's in this repository?
+
+The `examples` directory contains documentation, resources, and examples
+for all gRPC users. You can find examples and instructions specific to your
+favourite language in the relevant subdirectory.
+
+You can find out about the gRPC source code repositories in
+[`grpc`](https://github.com/grpc/grpc). Each repository provides instructions
+for building the appropriate libraries for your language.
+
+
+## What is gRPC?
+
+In gRPC a *client* application can directly call
+methods on a *server* application on a different machine as if it was a
+local object, making it easier for you to create distributed applications and
+services. As in many RPC systems, gRPC is based around the idea of defining
+a *service*, specifying the methods that can be called remotely with their
+parameters and return types. On the server side, the server implements this
+interface and runs a gRPC server to handle client calls. On the client side,
+the client has a *stub* that provides exactly the same methods as the server.
+
+
+
+gRPC clients and servers can run and talk to each other in a variety of
+environments - from servers inside Google to your own desktop - and can
+be written in any of gRPC's [supported languages](#quickstart). So, for
+example, you can easily create a gRPC server in Java with clients in Go,
+Python, or Ruby. In addition, the latest Google APIs will have gRPC versions
+of their interfaces, letting you easily build Google functionality into
+your applications.
+
+
+### Working with protocol buffers
+
+By default gRPC uses *protocol buffers*, Google’s
+mature open source mechanism for serializing structured data (although it
+can be used with other data formats such as JSON). As you'll
+see in our example below, you define gRPC services using *proto files*,
+with method parameters and return types specified as protocol buffer message
+types. You
+can find out lots more about protocol buffers in the [Protocol Buffers
+documentation](https://developers.google.com/protocol-buffers/docs/overview).
+
+#### Protocol buffer versions
+
+While protocol buffers have been available for open source users for some
+time, our examples use a new flavour of protocol buffers called proto3,
+which has a slightly simplified syntax, some useful new features, and supports
+lots more languages. This is currently available as an alpha release in
+Java, C++, Java_nano (Android Java), Python, and Ruby from [the protocol buffers Github
+repo](https://github.com/google/protobuf/releases), as well as a Go language
+generator from [the golang/protobuf Github repo](https://github.com/golang/protobuf), with more languages in development. You can find out more in the [proto3 language guide](https://developers.google.com/protocol-buffers/docs/proto3), and see
+the major differences from the current default version in the [release notes](https://github.com/google/protobuf/releases). More proto3 documentation is coming soon.
+
+In general, while you *can* use proto2 (the current default protocol buffers version), we recommend that you use proto3 with gRPC as it lets you use the full range of gRPC-supported languages, as well as avoiding compatibility
+issues with proto2 clients talking to proto3 servers and vice versa.
+
+
+## Hello gRPC!
+
+Now that you know a bit more about gRPC, the easiest way to see how it
+works is to look at a simple example. Our Hello World walks you through the
+construction of a simple gRPC client-server application, showing you how to:
+
+- Create a protocol buffers schema that defines a simple RPC service with
+a single
+Hello World method.
+- Create a Java server that implements this interface.
+- Create a Java client that accesses the Java server.
+- Create a Go client that accesses
+the same Java server.
+
+The complete code for the example is available in the `examples`
+directory. We use the Git versioning system for source code management:
+however, you don't need to know anything about Git to follow along other
+than how to install and run a few git commands.
+
+This is an introductory example rather than a comprehensive tutorial, so
+don't worry if you're not a Go or
+Java developer - the concepts are similar for all languages, and you can
+find more implementations of our Hello World example in other languages (and full tutorials where available) in
+the [language-specific folders](#quickstart) in this repository. Complete tutorials and
+reference documentation for all gRPC languages are coming soon.
+
+
+### Setup
+
+This section explains how to set up your local machine to work with
+the example code. If you just want to read the example, you can go straight
+to the [next step](#servicedef).
+
+#### Install Git
+
+You can download and install Git from http://git-scm.com/download. Once
+installed you should have access to the git command line tool. The main
+commands that you will need to use are:
+
+- git clone ... : clone a remote repository onto your local machine
+- git checkout ... : check out a particular branch or a tagged version of
+the code to hack on
+
+#### Install gRPC
+
+To build and install gRPC plugins and related tools:
+- For Java, see the [Java quick start](https://github.com/grpc/grpc-java).
+- For Go, see the [Go quick start](https://github.com/grpc/grpc-go).
+
+#### Get the source code
+
+The example code for our Java example lives in the `grpc-java`
+GitHub repository. Clone this repository to your local machine by running the
+following command:
+
+
+```
+git clone https://github.com/grpc/grpc-java.git
+```
+
+Change your current directory to grpc-java/examples
+
+```
+cd grpc-java/examples
+```
+
+
+
+
+### Defining a service
+
+The first step in creating our example is to define a *service*: an RPC
+service specifies the methods that can be called remotely with their parameters
+and return types. As you saw in the
+[overview](#protocolbuffers) above, gRPC does this using [protocol
+buffers](https://developers.google.com/protocol-buffers/docs/overview). We
+use the protocol buffers interface definition language (IDL) to define our
+service methods, and define the parameters and return
+types as protocol buffer message types. Both the client and the
+server use interface code generated from the service definition.
+
+Here's our example service definition, defined using protocol buffers IDL in
+[helloworld.proto](https://github.com/grpc/grpc-java/tree/master/examples/src/main/proto). The `Greeter`
+service has one method, `SayHello`, that lets the server receive a single
+`HelloRequest`
+message from the remote client containing the user's name, then send back
+a greeting in a single `HelloReply`. This is the simplest type of RPC you
+can specify in gRPC - you can find out about other types in the tutorial for your chosen language.
+
+```proto
+syntax = "proto3";
+
+option java_package = "io.grpc.examples";
+
+package helloworld;
+
+// The greeter service definition.
+service Greeter {
+ // Sends a greeting
+ rpc SayHello (HelloRequest) returns (HelloReply) {}
+}
+
+// The request message containing the user's name.
+message HelloRequest {
+ string name = 1;
+}
+
+// The response message containing the greetings
+message HelloReply {
+ string message = 1;
+}
+
+```
+
+
+### Generating gRPC code
+
+Once we've defined our service, we use the protocol buffer compiler
+`protoc` to generate the special client and server code we need to create
+our application - right now we're going to generate Java code, though you
+can generate gRPC code in any gRPC-supported language (as you'll see later
+in this example). The generated code contains both stub code for clients to
+use and an abstract interface for servers to implement, both with the method
+defined in our `Greeter` service.
+
+(If you didn't install the gRPC plugins and protoc on your system and are just reading along with
+the example, you can skip this step and move
+onto the next one where we examine the generated code.)
+
+For simplicity, we've provided a [Gradle build file](https://github.com/grpc/grpc-java/blob/master/examples/build.gradle) with our Java examples that runs `protoc` for you with the appropriate plugin, input, and output:
+
+```shell
+../gradlew build
+```
+
+This generates the following classes from our .proto, which contain all the generated code
+we need to create our example:
+
+- `Helloworld.java`, which
+has all the protocol buffer code to populate, serialize, and retrieve our
+`HelloRequest` and `HelloReply` message types
+- `GreeterGrpc.java`, which contains (along with some other useful code):
+ - an interface for `Greeter` servers to implement
+
+ ```java
+ public static interface Greeter {
+ public void sayHello(io.grpc.examples.Helloworld.HelloRequest request,
+ io.grpc.stub.StreamObserver responseObserver);
+ }
+ ```
+
+ - _stub_ classes that clients can use to talk to a `Greeter` server. As you can see, they also implement the `Greeter` interface.
+
+ ```java
+ public static class GreeterStub extends
+ io.grpc.stub.AbstractStub
+ implements Greeter {
+ ...
+ }
+ ```
+
+
+### Writing a server
+
+Now let's write some code! First we'll create a server application to implement
+our service. Note that we're not going to go into a lot of detail about how
+to create a server in this section. More detailed information will be in the
+tutorial for your chosen language: check if there's one available yet in the relevant [quick start](#quickstart).
+
+Our server application has two classes:
+
+- a main server class that hosts the service implementation and allows access over the
+network: [HelloWorldServer.java](https://github.com/grpc/grpc-java/blob/master/examples/src/main/java/io/grpc/examples/helloworld/HelloWorldServer.java).
+
+
+- a simple service implementation class [GreeterImpl.java](https://github.com/grpc/grpc-java/blob/master/examples/src/main/java/io/grpc/examples/helloworld/HelloWorldServer.java#L51).
+
+
+#### Service implementation
+
+[GreeterImpl.java](https://github.com/grpc/grpc-java/blob/master/examples/src/main/java/io/grpc/examples/helloworld/HelloWorldServer.java#L51)
+actually implements our `Greeter` service's required behaviour.
+
+As you can see, the class `GreeterImpl` implements the interface
+`GreeterGrpc.Greeter` that we [generated](#generating) from our proto
+[IDL](https://github.com/grpc/grpc-java/tree/master/examples/src/main/proto) by implementing the method `sayHello`:
+
+```java
+ @Override
+ public void sayHello(HelloRequest req, StreamObserver responseObserver) {
+ HelloReply reply = HelloReply.newBuilder().setMessage("Hello " + req.getName()).build();
+ responseObserver.onValue(reply);
+ responseObserver.onCompleted();
+ }
+```
+- `sayHello` takes two parameters:
+ - `HelloRequest`: the request
+ - `StreamObserver`: a response observer, which is
+ a special interface for the server to call with its response
+
+To return our response to the client and complete the call:
+
+1. We construct and populate a `HelloReply` response object with our exciting
+message, as specified in our interface definition.
+2. We return the `HelloReply` to the client and then specify that we've finished dealing with the RPC.
+
+
+#### Server implementation
+
+[HelloWorldServer.java](https://github.com/grpc/grpc-java/blob/master/examples/src/main/java/io/grpc/examples/helloworld/HelloWorldServer.java)
+shows the other main feature required to provide a gRPC service; making the service
+implementation available from the network.
+
+```java
+ /* The port on which the server should run */
+ private int port = 50051;
+ private ServerImpl server;
+
+ private void start() throws Exception {
+ server = NettyServerBuilder.forPort(port)
+ .addService(GreeterGrpc.bindService(new GreeterImpl()))
+ .build().start();
+ logger.info("Server started, listening on " + port);
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ @Override
+ public void run() {
+ // Use stderr here since the logger may have been reset by its JVM shutdown hook.
+ System.err.println("*** shutting down gRPC server since JVM is shutting down");
+ HelloWorldServer.this.stop();
+ System.err.println("*** server shut down");
+ }
+ });
+ }
+
+```
+
+Here we create an appropriate gRPC server, binding the `Greeter` service
+implementation that we created to a port. Then we start the server running: the server is now ready to receive
+requests from `Greeter` service clients on our specified port. We'll cover
+how all this works in a bit more detail in our language-specific documentation.
+
+
+### Writing a client
+
+Client-side gRPC is pretty simple. In this step, we'll use the generated code
+to write a simple client that can access the `Greeter` server we created
+in the [previous section](#server). You can see the complete client code in
+[HelloWorldClient.java](https://github.com/grpc/grpc-java/blob/master/examples/src/main/java/io/grpc/examples/helloworld/HelloWorldClient.java).
+
+Again, we're not going to go into much detail about how to implement a client;
+we'll leave that for the tutorial.
+
+#### Connecting to the service
+
+First let's look at how we connect to the `Greeter` server. First we need
+to create a gRPC channel, specifying the hostname and port of the server we
+want to connect to. Then we use the channel to construct the stub instance.
+
+
+```java
+ private final ChannelImpl channel;
+ private final GreeterGrpc.GreeterBlockingStub blockingStub;
+
+ public HelloWorldClient(String host, int port) {
+ channel =
+ NettyChannelBuilder.forAddress(host, port).negotiationType(NegotiationType.PLAINTEXT)
+ .build();
+ blockingStub = GreeterGrpc.newBlockingStub(channel);
+ }
+
+```
+
+In this case, we create a blocking stub. This means that the RPC call waits
+for the server to respond, and will either return a response or raise an
+exception. gRPC Java has other kinds of stubs that make non-blocking calls
+to the server, where the response is returned asynchronously.
+
+#### Calling an RPC
+
+Now we can contact the service and obtain a greeting:
+
+1. We construct and fill in a `HelloRequest` to send to the service.
+2. We call the stub's `hello()` RPC with our request and get a `HelloReply`
+back, from which we can get our greeting.
+
+
+```java
+ HelloRequest req = HelloRequest.newBuilder().setName(name).build();
+ HelloReply reply = blockingStub.sayHello(req);
+
+```
+
+
+### Try it out!
+
+Our [Gradle build file](https://github.com/grpc/grpc-java/blob/master/examples/build.gradle) simplifies building and running the examples.
+
+You can build and run the server from the `grpc-java` root folder with:
+
+```sh
+$ ./gradlew :grpc-examples:helloWorldServer
+```
+
+and in another terminal window confirm that it receives a message.
+
+```sh
+$ ./gradlew :grpc-examples:helloWorldClient
+```
+
+### Adding another client
+
+Finally, let's look at one of gRPC's most useful features - interoperability
+between code in different languages. So far, we've just looked at Java code
+generated from and implementing our `Greeter` service definition. However,
+as you'll see if you look at the language-specific subdirectories
+in this repository, we've also generated and implemented `Greeter`
+in some of gRPC's other supported languages. Each service
+and client uses interface code generated from the same proto
+that we used for the Java example.
+
+So, for example, if we visit the [`go` example
+directory](https://github.com/grpc/grpc-go/tree/master/examples) and look at the
+[`greeter_client`](https://github.com/grpc/grpc-go/blob/master/examples/greeter_client/main.go),
+we can see that like the Java client, it connects to a `Greeter` service
+at `localhost:50051` and uses a stub to call the `SayHello` method with a
+`HelloRequest`:
+
+```go
+const (
+ address = "localhost:50051"
+ defaultName = "world"
+)
+
+func main() {
+ // Set up a connection to the server.
+ conn, err := grpc.Dial(address)
+ if err != nil {
+ log.Fatalf("did not connect: %v", err)
+ }
+ defer conn.Close()
+ c := pb.NewGreeterClient(conn)
+
+ // Contact the server and print out its response.
+ name := defaultName
+ if len(os.Args) > 1 {
+ name = os.Args[1]
+ }
+ r, err := c.SayHello(context.Background(), &pb.HelloRequest{Name:
+ name})
+ if err != nil {
+ log.Fatalf("could not greet: %v", err)
+ }
+ log.Printf("Greeting: %s", r.Message)
+}
+```
+
+
+If we run the Java server from earlier in another terminal window, we can
+run the Go client and connect to it just like the Java client, even though
+it's written in a different language.
+
+```
+$ greeter_client
+```
+## Read more!
+
+- You can find links to language-specific tutorials, examples, and other docs in each language's [quick start](#quickstart).
+- [gRPC Authentication Support](doc/grpc-auth-support.md) introduces authentication support in gRPC with supported mechanisms and examples.
diff --git a/examples/cpp/README.md b/examples/cpp/README.md
new file mode 100644
index 00000000000..70418b44253
--- /dev/null
+++ b/examples/cpp/README.md
@@ -0,0 +1,65 @@
+#gRPC in 3 minutes (C++)
+
+## Installation
+
+To install gRPC on your system, follow the instructions here:
+[https://github.com/grpc/grpc/blob/master/INSTALL](https://github.com/grpc/grpc/blob/master/INSTALL).
+
+## Hello C++ gRPC!
+
+Here's how to build and run the C++ implementation of the [Hello World](examples/protos/helloworld.proto) example used in [Getting started](https://github.com/grpc/grpc/tree/master/examples).
+
+The example code for this and our other examples lives in the `examples`
+directory. Clone this repository to your local machine by running the
+following command:
+
+
+```sh
+$ git clone https://github.com/grpc/grpc.git
+```
+
+Change your current directory to examples/cpp/helloworld
+
+```sh
+$ cd examples/cpp/helloworld/
+```
+
+
+### Generating gRPC code
+
+To generate the client and server side interfaces:
+
+```sh
+$ make helloworld.grpc.pb.cc helloworld.pb.cc
+```
+Which internally invokes the proto-compiler as:
+
+```sh
+$ protoc -I ../../protos/ --grpc_out=. --plugin=protoc-gen-grpc=grpc_cpp_plugin ../../protos/helloworld.proto
+$ protoc -I ../../protos/ --cpp_out=. ../../protos/helloworld.proto
+```
+
+### Client and server implementations
+
+The client implementation is at [greeter_client.cc](examples/cpp/helloworld/greeter_client.cc).
+
+The server implementation is at [greeter_server.cc](examples/cpp/helloworld/greeter_server.cc).
+
+### Try it!
+Build client and server:
+```sh
+$ make
+```
+Run the server, which will listen on port 50051:
+```sh
+$ ./greeter_server
+```
+Run the client (in a different terminal):
+```sh
+$ ./greeter_client
+```
+If things go smoothly, you will see the "Greeter received: Hello world" in the client side output.
+
+## Tutorial
+
+You can find a more detailed tutorial in [gRPC Basics: C++](examples/cpp/cpptutorial.md)
diff --git a/examples/cpp/cpptutorial.md b/examples/cpp/cpptutorial.md
new file mode 100644
index 00000000000..22be42d500d
--- /dev/null
+++ b/examples/cpp/cpptutorial.md
@@ -0,0 +1,365 @@
+#gRPC Basics: C++
+
+This tutorial provides a basic C++ programmer's introduction to working with gRPC. By walking through this example you'll learn how to:
+
+- Define a service in a .proto file.
+- Generate server and client code using the protocol buffer compiler.
+- Use the C++ gRPC API to write a simple client and server for your service.
+
+It assumes that you have read the [Getting started](https://github.com/grpc/grpc/tree/master/examples) guide and are familiar with [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). Note that the example in this tutorial uses the proto3 version of the protocol buffers language, which is currently in alpha release: you can find out more in the [proto3 language guide](https://developers.google.com/protocol-buffers/docs/proto3) and see the [release notes](https://github.com/google/protobuf/releases) for the new version in the protocol buffers Github repository.
+
+This isn't a comprehensive guide to using gRPC in C++: more reference documentation is coming soon.
+
+## Why use gRPC?
+
+Our example is a simple route mapping application that lets clients get information about features on their route, create a summary of their route, and exchange route information such as traffic updates with the server and other clients.
+
+With gRPC we can define our service once in a .proto file and implement clients and servers in any of gRPC's supported languages, which in turn can be run in environments ranging from servers inside Google to your own tablet - all the complexity of communication between different languages and environments is handled for you by gRPC. We also get all the advantages of working with protocol buffers, including efficient serialization, a simple IDL, and easy interface updating.
+
+## Example code and setup
+
+The example code for our tutorial is in [examples/cpp/route_guide](examples/cpp/route_guide). To download the example, clone this repository by running the following command:
+```shell
+$ git clone https://github.com/grpc/grpc.git
+```
+
+Then change your current directory to `examples/cpp/route_guide`:
+```shell
+$ cd examples/cpp/route_guide
+```
+
+You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [the C++ quick start guide](examples/cpp).
+
+
+## Defining the service
+
+Our first step (as you'll know from [Getting started](examples/) is to define the gRPC *service* and the method *request* and *response* types using [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). You can see the complete .proto file in [`examples/protos/route_guide.proto`](examples/protos/route_guide.proto).
+
+To define a service, you specify a named `service` in your .proto file:
+
+```
+service RouteGuide {
+ ...
+}
+```
+
+Then you define `rpc` methods inside your service definition, specifying their request and response types. gRPC lets you define four kinds of service method, all of which are used in the `RouteGuide` service:
+
+- A *simple RPC* where the client sends a request to the server using the stub and waits for a response to come back, just like a normal function call.
+```
+ // Obtains the feature at a given position.
+ rpc GetFeature(Point) returns (Feature) {}
+```
+
+- A *server-side streaming RPC* where the client sends a request to the server and gets a stream to read a sequence of messages back. The client reads from the returned stream until there are no more messages. As you can see in our example, you specify a server-side streaming method by placing the `stream` keyword before the *response* type.
+```
+ // Obtains the Features available within the given Rectangle. Results are
+ // streamed rather than returned at once (e.g. in a response message with a
+ // repeated field), as the rectangle may cover a large area and contain a
+ // huge number of features.
+ rpc ListFeatures(Rectangle) returns (stream Feature) {}
+```
+
+- A *client-side streaming RPC* where the client writes a sequence of messages and sends them to the server, again using a provided stream. Once the client has finished writing the messages, it waits for the server to read them all and return its response. You specify a client-side streaming method by placing the `stream` keyword before the *request* type.
+```
+ // Accepts a stream of Points on a route being traversed, returning a
+ // RouteSummary when traversal is completed.
+ rpc RecordRoute(stream Point) returns (RouteSummary) {}
+```
+
+- A *bidirectional streaming RPC* where both sides send a sequence of messages using a read-write stream. The two streams operate independently, so clients and servers can read and write in whatever order they like: for example, the server could wait to receive all the client messages before writing its responses, or it could alternately read a message then write a message, or some other combination of reads and writes. The order of messages in each stream is preserved. You specify this type of method by placing the `stream` keyword before both the request and the response.
+```
+ // Accepts a stream of RouteNotes sent while a route is being traversed,
+ // while receiving other RouteNotes (e.g. from other users).
+ rpc RouteChat(stream RouteNote) returns (stream RouteNote) {}
+```
+
+Our .proto file also contains protocol buffer message type definitions for all the request and response types used in our service methods - for example, here's the `Point` message type:
+```
+// Points are represented as latitude-longitude pairs in the E7 representation
+// (degrees multiplied by 10**7 and rounded to the nearest integer).
+// Latitudes should be in the range +/- 90 degrees and longitude should be in
+// the range +/- 180 degrees (inclusive).
+message Point {
+ int32 latitude = 1;
+ int32 longitude = 2;
+}
+```
+
+
+## Generating client and server code
+
+Next we need to generate the gRPC client and server interfaces from our .proto service definition. We do this using the protocol buffer compiler `protoc` with a special gRPC C++ plugin.
+
+For simplicity, we've provided a [makefile](examples/cpp/route_guide/Makefile) that runs `protoc` for you with the appropriate plugin, input, and output (if you want to run this yourself, make sure you've installed protoc and followed the gRPC code [installation instructions](https://github.com/grpc/grpc/blob/master/INSTALL) first):
+
+```shell
+$ make route_guide.grpc.pb.cc route_guide.pb.cc
+```
+
+which actually runs:
+
+```shell
+$ protoc -I ../../protos --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` ../../protos/route_guide.proto
+$ protoc -I ../../protos --cpp_out=. ../../protos/route_guide.proto
+```
+
+Running this command generates the following files in your current directory:
+- `route_guide.pb.h`, the header which declares your generated message classes
+- `route_guide.pb.cc`, which contains the implementation of your message classes
+- `route_guide.grpc.pb.h`, the header which declares your generated service classes
+- `route_guide.grpc.pb.cc`, which contains the implementation of your service classes
+
+These contain:
+- All the protocol buffer code to populate, serialize, and retrieve our request and response message types
+- A class called `RouteGuide` that contains
+ - a remote interface type (or *stub*) for clients to call with the methods defined in the `RouteGuide` service.
+ - two abstract interfaces for servers to implement, also with the methods defined in the `RouteGuide` service.
+
+
+
+## Creating the server
+
+First let's look at how we create a `RouteGuide` server. If you're only interested in creating gRPC clients, you can skip this section and go straight to [Creating the client](#client) (though you might find it interesting anyway!).
+
+There are two parts to making our `RouteGuide` service do its job:
+- Implementing the service interface generated from our service definition: doing the actual "work" of our service.
+- Running a gRPC server to listen for requests from clients and return the service responses.
+
+You can find our example `RouteGuide` server in [examples/cpp/route_guide/route_guide_server.cc](examples/cpp/route_guide/route_guide_server.cc). Let's take a closer look at how it works.
+
+### Implementing RouteGuide
+
+As you can see, our server has a `RouteGuideImpl` class that implements the generated `RouteGuide::Service` interface:
+
+```cpp
+class RouteGuideImpl final : public RouteGuide::Service {
+...
+}
+```
+In this case we're implementing the *synchronous* version of `RouteGuide`, which provides our default gRPC server behaviour. It's also possible to implement an asynchronous interface, `RouteGuide::AsyncService`, which allows you to further customize your server's threading behaviour, though we won't look at this in this tutorial.
+
+`RouteGuideImpl` implements all our service methods. Let's look at the simplest type first, `GetFeature`, which just gets a `Point` from the client and returns the corresponding feature information from its database in a `Feature`.
+
+```cpp
+ Status GetFeature(ServerContext* context, const Point* point,
+ Feature* feature) override {
+ feature->set_name(GetFeatureName(*point, feature_list_));
+ feature->mutable_location()->CopyFrom(*point);
+ return Status::OK;
+ }
+```
+
+The method is passed a context object for the RPC, the client's `Point` protocol buffer request, and a `Feature` protocol buffer to fill in with the response information. In the method we populate the `Feature` with the appropriate information, and then `return` with an `OK` status to tell gRPC that we've finished dealing with the RPC and that the `Feature` can be returned to the client.
+
+Now let's look at something a bit more complicated - a streaming RPC. `ListFeatures` is a server-side streaming RPC, so we need to send back multiple `Feature`s to our client.
+
+```cpp
+ Status ListFeatures(ServerContext* context, const Rectangle* rectangle,
+ ServerWriter* writer) override {
+ auto lo = rectangle->lo();
+ auto hi = rectangle->hi();
+ long left = std::min(lo.longitude(), hi.longitude());
+ long right = std::max(lo.longitude(), hi.longitude());
+ long top = std::max(lo.latitude(), hi.latitude());
+ long bottom = std::min(lo.latitude(), hi.latitude());
+ for (const Feature& f : feature_list_) {
+ if (f.location().longitude() >= left &&
+ f.location().longitude() <= right &&
+ f.location().latitude() >= bottom &&
+ f.location().latitude() <= top) {
+ writer->Write(f);
+ }
+ }
+ return Status::OK;
+ }
+```
+
+As you can see, instead of getting simple request and response objects in our method parameters, this time we get a request object (the `Rectangle` in which our client wants to find `Feature`s) and a special `ServerWriter` object. In the method, we populate as many `Feature` objects as we need to return, writing them to the `ServerWriter` using its `Write()` method. Finally, as in our simple RPC, we `return Status::OK` to tell gRPC that we've finished writing responses.
+
+If you look at the client-side streaming method `RecordRoute` you'll see it's quite similar, except this time we get a `ServerReader` instead of a request object and a single response. We use the `ServerReader`s `Read()` method to repeatedly read in our client's requests to a request object (in this case a `Point`) until there are no more messages: the server needs to check the return value of `Read()` after each call. If `true`, the stream is still good and it can continue reading; if `false` the message stream has ended.
+
+```cpp
+while (stream->Read(&point)) {
+ ...//process client input
+}
+```
+Finally, let's look at our bidirectional streaming RPC `RouteChat()`.
+
+```cpp
+ Status RouteChat(ServerContext* context,
+ ServerReaderWriter* stream) override {
+ std::vector received_notes;
+ RouteNote note;
+ while (stream->Read(¬e)) {
+ for (const RouteNote& n : received_notes) {
+ if (n.location().latitude() == note.location().latitude() &&
+ n.location().longitude() == note.location().longitude()) {
+ stream->Write(n);
+ }
+ }
+ received_notes.push_back(note);
+ }
+
+ return Status::OK;
+ }
+```
+
+This time we get a `ServerReaderWriter` that can be used to read *and* write messages. The syntax for reading and writing here is exactly the same as for our client-streaming and server-streaming methods. Although each side will always get the other's messages in the order they were written, both the client and server can read and write in any order — the streams operate completely independently.
+
+### Starting the server
+
+Once we've implemented all our methods, we also need to start up a gRPC server so that clients can actually use our service. The following snippet shows how we do this for our `RouteGuide` service:
+
+```cpp
+void RunServer(const std::string& db_path) {
+ std::string server_address("0.0.0.0:50051");
+ RouteGuideImpl service(db_path);
+
+ ServerBuilder builder;
+ builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
+ builder.RegisterService(&service);
+ std::unique_ptr server(builder.BuildAndStart());
+ std::cout << "Server listening on " << server_address << std::endl;
+ server->Wait();
+}
+```
+As you can see, we build and start our server using a `ServerBuilder`. To do this, we:
+
+1. Create an instance of our service implementation class `RouteGuideImpl`.
+2. Create an instance of the factory `ServerBuilder` class.
+3. Specify the address and port we want to use to listen for client requests using the builder's `AddListeningPort()` method.
+4. Register our service implementation with the builder.
+5. Call `BuildAndStart()` on the builder to create and start an RPC server for our service.
+5. Call `Wait()` on the server to do a blocking wait until process is killed or `Shutdown()` is called.
+
+
+## Creating the client
+
+In this section, we'll look at creating a C++ client for our `RouteGuide` service. You can see our complete example client code in [examples/cpp/route_guide/route_guide_client.cc](examples/cpp/route_guide/route_guide_client.cc).
+
+### Creating a stub
+
+To call service methods, we first need to create a *stub*.
+
+First we need to create a gRPC *channel* for our stub, specifying the server address and port we want to connect to and any special channel arguments - in our case we'll use the default `ChannelArguments` and no SSL:
+
+```cpp
+grpc::CreateChannel("localhost:50051", grpc::InsecureCredentials(), ChannelArguments());
+```
+
+Now we can use the channel to create our stub using the `NewStub` method provided in the `RouteGuide` class we generated from our .proto.
+
+```cpp
+ public:
+ RouteGuideClient(std::shared_ptr channel, const std::string& db)
+ : stub_(RouteGuide::NewStub(channel)) {
+ ...
+ }
+```
+
+### Calling service methods
+
+Now let's look at how we call our service methods. Note that in this tutorial we're calling the *blocking/synchronous* versions of each method: this means that the RPC call waits for the server to respond, and will either return a response or raise an exception.
+
+#### Simple RPC
+
+Calling the simple RPC `GetFeature` is nearly as straightforward as calling a local method.
+
+```cpp
+ Point point;
+ Feature feature;
+ point = MakePoint(409146138, -746188906);
+ GetOneFeature(point, &feature);
+
+...
+
+ bool GetOneFeature(const Point& point, Feature* feature) {
+ ClientContext context;
+ Status status = stub_->GetFeature(&context, point, feature);
+ ...
+ }
+```
+
+As you can see, we create and populate a request protocol buffer object (in our case `Point`), and create a response protocol buffer object for the server to fill in. We also create a `ClientContext` object for our call - you can optionally set RPC configuration values on this object, such as deadlines, though for now we'll use the default settings. Note that you cannot reuse this object between calls. Finally, we call the method on the stub, passing it the context, request, and response. If the method returns `OK`, then we can read the response information from the server from our response object.
+
+```cpp
+ std::cout << "Found feature called " << feature->name() << " at "
+ << feature->location().latitude()/kCoordFactor_ << ", "
+ << feature->location().longitude()/kCoordFactor_ << std::endl;
+```
+
+#### Streaming RPCs
+
+Now let's look at our streaming methods. If you've already read [Creating the server](#server) some of this may look very familiar - streaming RPCs are implemented in a similar way on both sides. Here's where we call the server-side streaming method `ListFeatures`, which returns a stream of geographical `Feature`s:
+
+```cpp
+ std::unique_ptr > reader(
+ stub_->ListFeatures(&context, rect));
+ while (reader->Read(&feature)) {
+ std::cout << "Found feature called "
+ << feature.name() << " at "
+ << feature.location().latitude()/kCoordFactor_ << ", "
+ << feature.location().longitude()/kCoordFactor_ << std::endl;
+ }
+ Status status = reader->Finish();
+```
+
+Instead of passing the method a context, request, and response, we pass it a context and request and get a `ClientReader` object back. The client can use the `ClientReader` to read the server's responses. We use the `ClientReader`s `Read()` method to repeatedly read in the server's responses to a response protocol buffer object (in this case a `Feature`) until there are no more messages: the client needs to check the return value of `Read()` after each call. If `true`, the stream is still good and it can continue reading; if `false` the message stream has ended. Finally, we call `Finish()` on the stream to complete the call and get our RPC status.
+
+The client-side streaming method `RecordRoute` is similar, except there we pass the method a context and response object and get back a `ClientWriter`.
+
+```cpp
+ std::unique_ptr > writer(
+ stub_->RecordRoute(&context, &stats));
+ for (int i = 0; i < kPoints; i++) {
+ const Feature& f = feature_list_[feature_distribution(generator)];
+ std::cout << "Visiting point "
+ << f.location().latitude()/kCoordFactor_ << ", "
+ << f.location().longitude()/kCoordFactor_ << std::endl;
+ if (!writer->Write(f.location())) {
+ // Broken stream.
+ break;
+ }
+ std::this_thread::sleep_for(std::chrono::milliseconds(
+ delay_distribution(generator)));
+ }
+ writer->WritesDone();
+ Status status = writer->Finish();
+ if (status.IsOk()) {
+ std::cout << "Finished trip with " << stats.point_count() << " points\n"
+ << "Passed " << stats.feature_count() << " features\n"
+ << "Travelled " << stats.distance() << " meters\n"
+ << "It took " << stats.elapsed_time() << " seconds"
+ << std::endl;
+ } else {
+ std::cout << "RecordRoute rpc failed." << std::endl;
+ }
+```
+
+Once we've finished writing our client's requests to the stream using `Write()`, we need to call `WritesDone()` on the stream to let gRPC know that we've finished writing, then `Finish()` to complete the call and get our RPC status. If the status is `OK`, our response object that we initially passed to `RecordRoute()` will be populated with the server's response.
+
+Finally, let's look at our bidirectional streaming RPC `RouteChat()`. In this case, we just pass a context to the method and get back a `ClientReaderWriter`, which we can use to both write and read messages.
+
+```cpp
+ std::shared_ptr > stream(
+ stub_->RouteChat(&context));
+```
+
+The syntax for reading and writing here is exactly the same as for our client-streaming and server-streaming methods. Although each side will always get the other's messages in the order they were written, both the client and server can read and write in any order — the streams operate completely independently.
+
+## Try it out!
+
+Build client and server:
+```shell
+$ make
+```
+Run the server, which will listen on port 50051:
+```shell
+$ ./route_guide_server
+```
+Run the client (in a different terminal):
+```shell
+$ ./route_guide_client
+```
+
diff --git a/examples/cpp/helloworld/Makefile b/examples/cpp/helloworld/Makefile
new file mode 100644
index 00000000000..f2093afa055
--- /dev/null
+++ b/examples/cpp/helloworld/Makefile
@@ -0,0 +1,119 @@
+#
+# Copyright 2015, Google Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+CXX = g++
+CPPFLAGS += -I/usr/local/include -pthread
+CXXFLAGS += -std=c++11
+LDFLAGS += -L/usr/local/lib -lgrpc++_unsecure -lgrpc -lgpr -lprotobuf -lpthread -ldl
+PROTOC = protoc
+GRPC_CPP_PLUGIN = grpc_cpp_plugin
+GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)`
+
+PROTOS_PATH = ../../protos
+
+vpath %.proto $(PROTOS_PATH)
+
+all: system-check greeter_client greeter_server greeter_async_client greeter_async_server
+
+greeter_client: helloworld.pb.o helloworld.grpc.pb.o greeter_client.o
+ $(CXX) $^ $(LDFLAGS) -o $@
+
+greeter_server: helloworld.pb.o helloworld.grpc.pb.o greeter_server.o
+ $(CXX) $^ $(LDFLAGS) -o $@
+
+greeter_async_client: helloworld.pb.o helloworld.grpc.pb.o greeter_async_client.o
+ $(CXX) $^ $(LDFLAGS) -o $@
+
+greeter_async_server: helloworld.pb.o helloworld.grpc.pb.o greeter_async_server.o
+ $(CXX) $^ $(LDFLAGS) -o $@
+
+%.grpc.pb.cc: %.proto
+ $(PROTOC) -I $(PROTOS_PATH) --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $<
+
+%.pb.cc: %.proto
+ $(PROTOC) -I $(PROTOS_PATH) --cpp_out=. $<
+
+clean:
+ rm -f *.o *.pb.cc *.pb.h greeter_client greeter_server greeter_async_client greeter_async_server
+
+
+# The following is to test your system and ensure a smoother experience.
+# They are by no means necessary to actually compile a grpc-enabled software.
+
+PROTOC_CMD = which $(PROTOC)
+PROTOC_CHECK_CMD = $(PROTOC) --version | grep -q libprotoc.3
+PLUGIN_CHECK_CMD = which $(GRPC_CPP_PLUGIN)
+HAS_PROTOC = $(shell $(PROTOC_CMD) > /dev/null && echo true || echo false)
+ifeq ($(HAS_PROTOC),true)
+HAS_VALID_PROTOC = $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
+endif
+HAS_PLUGIN = $(shell $(PLUGIN_CHECK_CMD) > /dev/null && echo true || echo false)
+
+SYSTEM_OK = false
+ifeq ($(HAS_VALID_PROTOC),true)
+ifeq ($(HAS_PLUGIN),true)
+SYSTEM_OK = true
+endif
+endif
+
+system-check:
+ifneq ($(HAS_VALID_PROTOC),true)
+ @echo " DEPENDENCY ERROR"
+ @echo
+ @echo "You don't have protoc 3.0.0 installed in your path."
+ @echo "Please install Google protocol buffers 3.0.0 and its compiler."
+ @echo "You can find it here:"
+ @echo
+ @echo " https://github.com/google/protobuf/releases/tag/v3.0.0-alpha-1"
+ @echo
+ @echo "Here is what I get when trying to evaluate your version of protoc:"
+ @echo
+ -$(PROTOC) --version
+ @echo
+ @echo
+endif
+ifneq ($(HAS_PLUGIN),true)
+ @echo " DEPENDENCY ERROR"
+ @echo
+ @echo "You don't have the grpc c++ protobuf plugin installed in your path."
+ @echo "Please install grpc. You can find it here:"
+ @echo
+ @echo " https://github.com/grpc/grpc"
+ @echo
+ @echo "Here is what I get when trying to detect if you have the plugin:"
+ @echo
+ -which $(GRPC_CPP_PLUGIN)
+ @echo
+ @echo
+endif
+ifneq ($(SYSTEM_OK),true)
+ @false
+endif
diff --git a/examples/cpp/helloworld/README.md b/examples/cpp/helloworld/README.md
new file mode 100644
index 00000000000..641aadd52d3
--- /dev/null
+++ b/examples/cpp/helloworld/README.md
@@ -0,0 +1,260 @@
+# gRPC C++ Hello World Tutorial
+
+### Install gRPC
+Make sure you have installed gRPC on your system. Follow the instructions here:
+[https://github.com/grpc/grpc/blob/master/INSTALL](https://github.com/grpc/grpc/blob/master/INSTALL).
+
+### Get the tutorial source code
+
+The example code for this and our other examples lives in the `examples`
+directory. Clone this repository to your local machine by running the
+following command:
+
+
+```sh
+$ git clone https://github.com/grpc/grpc.git
+```
+
+Change your current directory to examples/cpp/helloworld
+
+```sh
+$ cd examples/cpp/helloworld/
+```
+
+### Defining a service
+
+The first step in creating our example is to define a *service*: an RPC
+service specifies the methods that can be called remotely with their parameters
+and return types. As you saw in the
+[overview](#protocolbuffers) above, gRPC does this using [protocol
+buffers](https://developers.google.com/protocol-buffers/docs/overview). We
+use the protocol buffers interface definition language (IDL) to define our
+service methods, and define the parameters and return
+types as protocol buffer message types. Both the client and the
+server use interface code generated from the service definition.
+
+Here's our example service definition, defined using protocol buffers IDL in
+[helloworld.proto](examples/protos/helloworld.proto). The `Greeting`
+service has one method, `hello`, that lets the server receive a single
+`HelloRequest`
+message from the remote client containing the user's name, then send back
+a greeting in a single `HelloReply`. This is the simplest type of RPC you
+can specify in gRPC - we'll look at some other types later in this document.
+
+```
+syntax = "proto3";
+
+option java_package = "ex.grpc";
+
+package helloworld;
+
+// The greeting service definition.
+service Greeter {
+ // Sends a greeting
+ rpc SayHello (HelloRequest) returns (HelloReply) {}
+}
+
+// The request message containing the user's name.
+message HelloRequest {
+ string name = 1;
+}
+
+// The response message containing the greetings
+message HelloReply {
+ string message = 1;
+}
+
+```
+
+
+### Generating gRPC code
+
+Once we've defined our service, we use the protocol buffer compiler
+`protoc` to generate the special client and server code we need to create
+our application. The generated code contains both stub code for clients to
+use and an abstract interface for servers to implement, both with the method
+defined in our `Greeting` service.
+
+To generate the client and server side interfaces:
+
+```sh
+$ make helloworld.grpc.pb.cc helloworld.pb.cc
+```
+Which internally invokes the proto-compiler as:
+
+```sh
+$ protoc -I ../../protos/ --grpc_out=. --plugin=protoc-gen-grpc=grpc_cpp_plugin ../../protos/helloworld.proto
+$ protoc -I ../../protos/ --cpp_out=. ../../protos/helloworld.proto
+```
+
+### Writing a client
+
+- Create a channel. A channel is a logical connection to an endpoint. A gRPC
+ channel can be created with the target address, credentials to use and
+ arguments as follows
+
+ ```
+ auto channel = CreateChannel("localhost:50051", InsecureCredentials(), ChannelArguments());
+ ```
+
+- Create a stub. A stub implements the rpc methods of a service and in the
+ generated code, a method is provided to created a stub with a channel:
+
+ ```
+ auto stub = helloworld::Greeter::NewStub(channel);
+ ```
+
+- Make a unary rpc, with `ClientContext` and request/response proto messages.
+
+ ```
+ ClientContext context;
+ HelloRequest request;
+ request.set_name("hello");
+ HelloReply reply;
+ Status status = stub->SayHello(&context, request, &reply);
+ ```
+
+- Check returned status and response.
+
+ ```
+ if (status.ok()) {
+ // check reply.message()
+ } else {
+ // rpc failed.
+ }
+ ```
+
+For a working example, refer to [greeter_client.cc](examples/cpp/helloworld/greeter_client.cc).
+
+### Writing a server
+
+- Implement the service interface
+
+ ```
+ class GreeterServiceImpl final : public Greeter::Service {
+ Status SayHello(ServerContext* context, const HelloRequest* request,
+ HelloReply* reply) override {
+ std::string prefix("Hello ");
+ reply->set_message(prefix + request->name());
+ return Status::OK;
+ }
+ };
+
+ ```
+
+- Build a server exporting the service
+
+ ```
+ GreeterServiceImpl service;
+ ServerBuilder builder;
+ builder.AddListeningPort("0.0.0.0:50051", grpc::InsecureServerCredentials());
+ builder.RegisterService(&service);
+ std::unique_ptr server(builder.BuildAndStart());
+ ```
+
+For a working example, refer to [greeter_server.cc](examples/cpp/helloworld/greeter_server.cc).
+
+### Writing asynchronous client and server
+
+gRPC uses `CompletionQueue` API for asynchronous operations. The basic work flow
+is
+- bind a `CompletionQueue` to a rpc call
+- do something like a read or write, present with a unique `void*` tag
+- call `CompletionQueue::Next` to wait for operations to complete. If a tag
+ appears, it indicates that the corresponding operation is complete.
+
+#### Async client
+
+The channel and stub creation code is the same as the sync client.
+
+- Initiate the rpc and create a handle for the rpc. Bind the rpc to a
+ `CompletionQueue`.
+
+ ```
+ CompletionQueue cq;
+ auto rpc = stub->AsyncSayHello(&context, request, &cq);
+ ```
+
+- Ask for reply and final status, with a unique tag
+
+ ```
+ Status status;
+ rpc->Finish(&reply, &status, (void*)1);
+ ```
+
+- Wait for the completion queue to return the next tag. The reply and status are
+ ready once the tag passed into the corresponding `Finish()` call is returned.
+
+ ```
+ void* got_tag;
+ bool ok = false;
+ cq.Next(&got_tag, &ok);
+ if (ok && got_tag == (void*)1) {
+ // check reply and status
+ }
+ ```
+
+For a working example, refer to [greeter_async_client.cc](examples/cpp/helloworld/greeter_async_client.cc).
+
+#### Async server
+
+The server implementation requests a rpc call with a tag and then wait for the
+completion queue to return the tag. The basic flow is
+
+- Build a server exporting the async service
+
+ ```
+ helloworld::Greeter::AsyncService service;
+ ServerBuilder builder;
+ builder.AddListeningPort("0.0.0.0:50051", InsecureServerCredentials());
+ builder.RegisterAsyncService(&service);
+ auto cq = builder.AddCompletionQueue();
+ auto server = builder.BuildAndStart();
+ ```
+
+- Request one rpc
+
+ ```
+ ServerContext context;
+ HelloRequest request;
+ ServerAsyncResponseWriter responder;
+ service.RequestSayHello(&context, &request, &responder, &cq, &cq, (void*)1);
+ ```
+
+- Wait for the completion queue to return the tag. The context, request and
+ responder are ready once the tag is retrieved.
+
+ ```
+ HelloReply reply;
+ Status status;
+ void* got_tag;
+ bool ok = false;
+ cq.Next(&got_tag, &ok);
+ if (ok && got_tag == (void*)1) {
+ // set reply and status
+ responder.Finish(reply, status, (void*)2);
+ }
+ ```
+
+- Wait for the completion queue to return the tag. The rpc is finished when the
+ tag is back.
+
+ ```
+ void* got_tag;
+ bool ok = false;
+ cq.Next(&got_tag, &ok);
+ if (ok && got_tag == (void*)2) {
+ // clean up
+ }
+ ```
+
+To handle multiple rpcs, the async server creates an object `CallData` to
+maintain the state of each rpc and use the address of it as the unique tag. For
+simplicity the server only uses one completion queue for all events, and runs a
+main loop in `HandleRpcs` to query the queue.
+
+For a working example, refer to [greeter_async_server.cc](examples/cpp/helloworld/greeter_async_server.cc).
+
+
+
+
diff --git a/examples/cpp/helloworld/greeter_async_client.cc b/examples/cpp/helloworld/greeter_async_client.cc
new file mode 100644
index 00000000000..d99f89b1359
--- /dev/null
+++ b/examples/cpp/helloworld/greeter_async_client.cc
@@ -0,0 +1,98 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "helloworld.grpc.pb.h"
+
+using grpc::Channel;
+using grpc::ChannelArguments;
+using grpc::ClientAsyncResponseReader;
+using grpc::ClientContext;
+using grpc::CompletionQueue;
+using grpc::Status;
+using helloworld::HelloRequest;
+using helloworld::HelloReply;
+using helloworld::Greeter;
+
+class GreeterClient {
+ public:
+ explicit GreeterClient(std::shared_ptr channel)
+ : stub_(Greeter::NewStub(channel)) {}
+
+ std::string SayHello(const std::string& user) {
+ HelloRequest request;
+ request.set_name(user);
+ HelloReply reply;
+ ClientContext context;
+ CompletionQueue cq;
+ Status status;
+
+ std::unique_ptr > rpc(
+ stub_->AsyncSayHello(&context, request, &cq));
+ rpc->Finish(&reply, &status, (void*)1);
+ void* got_tag;
+ bool ok = false;
+ cq.Next(&got_tag, &ok);
+ GPR_ASSERT(ok);
+ GPR_ASSERT(got_tag == (void*)1);
+
+ if (status.ok()) {
+ return reply.message();
+ } else {
+ return "Rpc failed";
+ }
+ }
+
+ private:
+ std::unique_ptr stub_;
+};
+
+int main(int argc, char** argv) {
+ GreeterClient greeter(grpc::CreateChannel(
+ "localhost:50051", grpc::InsecureCredentials(), ChannelArguments()));
+ std::string user("world");
+ std::string reply = greeter.SayHello(user);
+ std::cout << "Greeter received: " << reply << std::endl;
+
+ return 0;
+}
diff --git a/examples/cpp/helloworld/greeter_async_server.cc b/examples/cpp/helloworld/greeter_async_server.cc
new file mode 100644
index 00000000000..b8a0dbf0e2e
--- /dev/null
+++ b/examples/cpp/helloworld/greeter_async_server.cc
@@ -0,0 +1,136 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "helloworld.grpc.pb.h"
+
+using grpc::Server;
+using grpc::ServerAsyncResponseWriter;
+using grpc::ServerBuilder;
+using grpc::ServerContext;
+using grpc::ServerCompletionQueue;
+using grpc::Status;
+using helloworld::HelloRequest;
+using helloworld::HelloReply;
+using helloworld::Greeter;
+
+class ServerImpl final {
+ public:
+ ~ServerImpl() {
+ server_->Shutdown();
+ cq_->Shutdown();
+ }
+
+ // There is no shutdown handling in this code.
+ void Run() {
+ std::string server_address("0.0.0.0:50051");
+
+ ServerBuilder builder;
+ builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
+ builder.RegisterAsyncService(&service_);
+ cq_ = builder.AddCompletionQueue();
+ server_ = builder.BuildAndStart();
+ std::cout << "Server listening on " << server_address << std::endl;
+
+ HandleRpcs();
+ }
+
+ private:
+ class CallData {
+ public:
+ CallData(Greeter::AsyncService* service, ServerCompletionQueue* cq)
+ : service_(service), cq_(cq), responder_(&ctx_), status_(CREATE) {
+ Proceed();
+ }
+
+ void Proceed() {
+ if (status_ == CREATE) {
+ service_->RequestSayHello(&ctx_, &request_, &responder_, cq_, cq_,
+ this);
+ status_ = PROCESS;
+ } else if (status_ == PROCESS) {
+ new CallData(service_, cq_);
+ std::string prefix("Hello ");
+ reply_.set_message(prefix + request_.name());
+ responder_.Finish(reply_, Status::OK, this);
+ status_ = FINISH;
+ } else {
+ delete this;
+ }
+ }
+
+ private:
+ Greeter::AsyncService* service_;
+ ServerCompletionQueue* cq_;
+ ServerContext ctx_;
+ HelloRequest request_;
+ HelloReply reply_;
+ ServerAsyncResponseWriter responder_;
+ enum CallStatus { CREATE, PROCESS, FINISH };
+ CallStatus status_;
+ };
+
+ // This can be run in multiple threads if needed.
+ void HandleRpcs() {
+ new CallData(&service_, cq_.get());
+ void* tag;
+ bool ok;
+ while (true) {
+ cq_->Next(&tag, &ok);
+ GPR_ASSERT(ok);
+ static_cast(tag)->Proceed();
+ }
+ }
+
+ std::unique_ptr cq_;
+ Greeter::AsyncService service_;
+ std::unique_ptr server_;
+};
+
+int main(int argc, char** argv) {
+ ServerImpl server;
+ server.Run();
+
+ return 0;
+}
diff --git a/examples/cpp/helloworld/greeter_client.cc b/examples/cpp/helloworld/greeter_client.cc
new file mode 100644
index 00000000000..dd0358ac95d
--- /dev/null
+++ b/examples/cpp/helloworld/greeter_client.cc
@@ -0,0 +1,85 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include "helloworld.grpc.pb.h"
+
+using grpc::Channel;
+using grpc::ChannelArguments;
+using grpc::ClientContext;
+using grpc::Status;
+using helloworld::HelloRequest;
+using helloworld::HelloReply;
+using helloworld::Greeter;
+
+class GreeterClient {
+ public:
+ GreeterClient(std::shared_ptr channel)
+ : stub_(Greeter::NewStub(channel)) {}
+
+ std::string SayHello(const std::string& user) {
+ HelloRequest request;
+ request.set_name(user);
+ HelloReply reply;
+ ClientContext context;
+
+ Status status = stub_->SayHello(&context, request, &reply);
+ if (status.ok()) {
+ return reply.message();
+ } else {
+ return "Rpc failed";
+ }
+ }
+
+ private:
+ std::unique_ptr stub_;
+};
+
+int main(int argc, char** argv) {
+ GreeterClient greeter(
+ grpc::CreateChannel("localhost:50051", grpc::InsecureCredentials(),
+ ChannelArguments()));
+ std::string user("world");
+ std::string reply = greeter.SayHello(user);
+ std::cout << "Greeter received: " << reply << std::endl;
+
+ return 0;
+}
diff --git a/examples/cpp/helloworld/greeter_server.cc b/examples/cpp/helloworld/greeter_server.cc
new file mode 100644
index 00000000000..c1efdf563c4
--- /dev/null
+++ b/examples/cpp/helloworld/greeter_server.cc
@@ -0,0 +1,78 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include "helloworld.grpc.pb.h"
+
+using grpc::Server;
+using grpc::ServerBuilder;
+using grpc::ServerContext;
+using grpc::Status;
+using helloworld::HelloRequest;
+using helloworld::HelloReply;
+using helloworld::Greeter;
+
+class GreeterServiceImpl final : public Greeter::Service {
+ Status SayHello(ServerContext* context, const HelloRequest* request,
+ HelloReply* reply) override {
+ std::string prefix("Hello ");
+ reply->set_message(prefix + request->name());
+ return Status::OK;
+ }
+};
+
+void RunServer() {
+ std::string server_address("0.0.0.0:50051");
+ GreeterServiceImpl service;
+
+ ServerBuilder builder;
+ builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
+ builder.RegisterService(&service);
+ std::unique_ptr server(builder.BuildAndStart());
+ std::cout << "Server listening on " << server_address << std::endl;
+ server->Wait();
+}
+
+int main(int argc, char** argv) {
+ RunServer();
+
+ return 0;
+}
diff --git a/examples/cpp/route_guide/Makefile b/examples/cpp/route_guide/Makefile
new file mode 100644
index 00000000000..b906177af35
--- /dev/null
+++ b/examples/cpp/route_guide/Makefile
@@ -0,0 +1,113 @@
+#
+# Copyright 2015, Google Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+CXX = g++
+CPPFLAGS += -I/usr/local/include -pthread
+CXXFLAGS += -std=c++11
+LDFLAGS += -L/usr/local/lib -lgrpc++_unsecure -lgrpc -lgpr -lprotobuf -lpthread -ldl
+PROTOC = protoc
+GRPC_CPP_PLUGIN = grpc_cpp_plugin
+GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)`
+
+PROTOS_PATH = ../../protos
+
+vpath %.proto $(PROTOS_PATH)
+
+all: system-check route_guide_client route_guide_server
+
+route_guide_client: route_guide.pb.o route_guide.grpc.pb.o route_guide_client.o helper.o
+ $(CXX) $^ $(LDFLAGS) -o $@
+
+route_guide_server: route_guide.pb.o route_guide.grpc.pb.o route_guide_server.o helper.o
+ $(CXX) $^ $(LDFLAGS) -o $@
+
+%.grpc.pb.cc: %.proto
+ $(PROTOC) -I $(PROTOS_PATH) --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $<
+
+%.pb.cc: %.proto
+ $(PROTOC) -I $(PROTOS_PATH) --cpp_out=. $<
+
+clean:
+ rm -f *.o *.pb.cc *.pb.h route_guide_client route_guide_server
+
+
+# The following is to test your system and ensure a smoother experience.
+# They are by no means necessary to actually compile a grpc-enabled software.
+
+PROTOC_CMD = which $(PROTOC)
+PROTOC_CHECK_CMD = $(PROTOC) --version | grep -q libprotoc.3
+PLUGIN_CHECK_CMD = which $(GRPC_CPP_PLUGIN)
+HAS_PROTOC = $(shell $(PROTOC_CMD) > /dev/null && echo true || echo false)
+ifeq ($(HAS_PROTOC),true)
+HAS_VALID_PROTOC = $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
+endif
+HAS_PLUGIN = $(shell $(PLUGIN_CHECK_CMD) > /dev/null && echo true || echo false)
+
+SYSTEM_OK = false
+ifeq ($(HAS_VALID_PROTOC),true)
+ifeq ($(HAS_PLUGIN),true)
+SYSTEM_OK = true
+endif
+endif
+
+system-check:
+ifneq ($(HAS_VALID_PROTOC),true)
+ @echo " DEPENDENCY ERROR"
+ @echo
+ @echo "You don't have protoc 3.0.0 installed in your path."
+ @echo "Please install Google protocol buffers 3.0.0 and its compiler."
+ @echo "You can find it here:"
+ @echo
+ @echo " https://github.com/google/protobuf/releases/tag/v3.0.0-alpha-1"
+ @echo
+ @echo "Here is what I get when trying to evaluate your version of protoc:"
+ @echo
+ -$(PROTOC) --version
+ @echo
+ @echo
+endif
+ifneq ($(HAS_PLUGIN),true)
+ @echo " DEPENDENCY ERROR"
+ @echo
+ @echo "You don't have the grpc c++ protobuf plugin installed in your path."
+ @echo "Please install grpc. You can find it here:"
+ @echo
+ @echo " https://github.com/grpc/grpc"
+ @echo
+ @echo "Here is what I get when trying to detect if you have the plugin:"
+ @echo
+ -which $(GRPC_CPP_PLUGIN)
+ @echo
+ @echo
+endif
+ifneq ($(SYSTEM_OK),true)
+ @false
+endif
diff --git a/examples/cpp/route_guide/helper.cc b/examples/cpp/route_guide/helper.cc
new file mode 100644
index 00000000000..c2415afdf72
--- /dev/null
+++ b/examples/cpp/route_guide/helper.cc
@@ -0,0 +1,178 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "route_guide.grpc.pb.h"
+
+namespace examples {
+
+std::string GetDbFileContent(int argc, char** argv) {
+ std::string db_path;
+ std::string arg_str("--db_path");
+ if (argc > 1) {
+ std::string argv_1 = argv[1];
+ size_t start_position = argv_1.find(arg_str);
+ if (start_position != std::string::npos) {
+ start_position += arg_str.size();
+ if (argv_1[start_position] == ' ' ||
+ argv_1[start_position] == '=') {
+ db_path = argv_1.substr(start_position + 1);
+ }
+ }
+ } else {
+ db_path = "route_guide_db.json";
+ }
+ std::ifstream db_file(db_path);
+ if (!db_file.is_open()) {
+ std::cout << "Failed to open " << db_path << std::endl;
+ return "";
+ }
+ std::stringstream db;
+ db << db_file.rdbuf();
+ return db.str();
+}
+
+// A simple parser for the json db file. It requires the db file to have the
+// exact form of [{"location": { "latitude": 123, "longitude": 456}, "name":
+// "the name can be empty" }, { ... } ... The spaces will be stripped.
+class Parser {
+ public:
+ explicit Parser(const std::string& db) : db_(db) {
+ // Remove all spaces.
+ db_.erase(
+ std::remove_if(db_.begin(), db_.end(), isspace),
+ db_.end());
+ if (!Match("[")) {
+ SetFailedAndReturnFalse();
+ }
+ }
+
+ bool Finished() {
+ return current_ >= db_.size();
+ }
+
+ bool TryParseOne(Feature* feature) {
+ if (failed_ || Finished() || !Match("{")) {
+ return SetFailedAndReturnFalse();
+ }
+ if (!Match(location_) || !Match("{") || !Match(latitude_)) {
+ return SetFailedAndReturnFalse();
+ }
+ long temp = 0;
+ ReadLong(&temp);
+ feature->mutable_location()->set_latitude(temp);
+ if (!Match(",") || !Match(longitude_)) {
+ return SetFailedAndReturnFalse();
+ }
+ ReadLong(&temp);
+ feature->mutable_location()->set_longitude(temp);
+ if (!Match("},") || !Match(name_) || !Match("\"")) {
+ return SetFailedAndReturnFalse();
+ }
+ size_t name_start = current_;
+ while (current_ != db_.size() && db_[current_++] != '"') {
+ }
+ if (current_ == db_.size()) {
+ return SetFailedAndReturnFalse();
+ }
+ feature->set_name(db_.substr(name_start, current_-name_start-1));
+ if (!Match("},")) {
+ if (db_[current_ - 1] == ']' && current_ == db_.size()) {
+ return true;
+ }
+ return SetFailedAndReturnFalse();
+ }
+ return true;
+ }
+
+ private:
+
+ bool SetFailedAndReturnFalse() {
+ failed_ = true;
+ return false;
+ }
+
+ bool Match(const std::string& prefix) {
+ bool eq = db_.substr(current_, prefix.size()) == prefix;
+ current_ += prefix.size();
+ return eq;
+ }
+
+ void ReadLong(long* l) {
+ size_t start = current_;
+ while (current_ != db_.size() && db_[current_] != ',' && db_[current_] != '}') {
+ current_++;
+ }
+ // It will throw an exception if fails.
+ *l = std::stol(db_.substr(start, current_ - start));
+ }
+
+ bool failed_ = false;
+ std::string db_;
+ size_t current_ = 0;
+ const std::string location_ = "\"location\":";
+ const std::string latitude_ = "\"latitude\":";
+ const std::string longitude_ = "\"longitude\":";
+ const std::string name_ = "\"name\":";
+};
+
+void ParseDb(const std::string& db, std::vector* feature_list) {
+ feature_list->clear();
+ std::string db_content(db);
+ db_content.erase(
+ std::remove_if(db_content.begin(), db_content.end(), isspace),
+ db_content.end());
+
+ Parser parser(db_content);
+ Feature feature;
+ while (!parser.Finished()) {
+ feature_list->push_back(Feature());
+ if (!parser.TryParseOne(&feature_list->back())) {
+ std::cout << "Error parsing the db file";
+ feature_list->clear();
+ break;
+ }
+ }
+ std::cout << "DB parsed, loaded " << feature_list->size()
+ << " features." << std::endl;
+}
+
+
+} // namespace examples
+
diff --git a/examples/pubsub/subscriber.h b/examples/cpp/route_guide/helper.h
similarity index 68%
rename from examples/pubsub/subscriber.h
rename to examples/cpp/route_guide/helper.h
index c5b1df0d3ec..65c93c1d347 100644
--- a/examples/pubsub/subscriber.h
+++ b/examples/cpp/route_guide/helper.h
@@ -31,37 +31,20 @@
*
*/
-#ifndef GRPC_EXAMPLES_PUBSUB_SUBSCRIBER_H
-#define GRPC_EXAMPLES_PUBSUB_SUBSCRIBER_H
+#ifndef GRPC_COMMON_CPP_ROUTE_GUIDE_HELPER_H_
+#define GRPC_COMMON_CPP_ROUTE_GUIDE_HELPER_H_
-#include
+#include
+#include
-#include "examples/pubsub/pubsub.grpc.pb.h"
-
-namespace grpc {
namespace examples {
-namespace pubsub {
-
-class Subscriber {
- public:
- Subscriber(std::shared_ptr channel);
- void Shutdown();
-
- Status CreateSubscription(const grpc::string& topic,
- const grpc::string& name);
+class Feature;
- Status GetSubscription(const grpc::string& name, grpc::string* topic);
+std::string GetDbFileContent(int argc, char** argv);
- Status DeleteSubscription(const grpc::string& name);
+void ParseDb(const std::string& db, std::vector* feature_list);
- Status Pull(const grpc::string& name, grpc::string* data);
-
- private:
- std::unique_ptr stub_;
-};
-
-} // namespace pubsub
} // namespace examples
-} // namespace grpc
-#endif // GRPC_EXAMPLES_PUBSUB_SUBSCRIBER_H
+#endif // GRPC_COMMON_CPP_ROUTE_GUIDE_HELPER_H_
+
diff --git a/examples/cpp/route_guide/route_guide_client.cc b/examples/cpp/route_guide/route_guide_client.cc
new file mode 100644
index 00000000000..814def27f35
--- /dev/null
+++ b/examples/cpp/route_guide/route_guide_client.cc
@@ -0,0 +1,252 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include "helper.h"
+#include "route_guide.grpc.pb.h"
+
+using grpc::Channel;
+using grpc::ChannelArguments;
+using grpc::ClientContext;
+using grpc::ClientReader;
+using grpc::ClientReaderWriter;
+using grpc::ClientWriter;
+using grpc::Status;
+using examples::Point;
+using examples::Feature;
+using examples::Rectangle;
+using examples::RouteSummary;
+using examples::RouteNote;
+using examples::RouteGuide;
+
+Point MakePoint(long latitude, long longitude) {
+ Point p;
+ p.set_latitude(latitude);
+ p.set_longitude(longitude);
+ return p;
+}
+
+Feature MakeFeature(const std::string& name,
+ long latitude, long longitude) {
+ Feature f;
+ f.set_name(name);
+ f.mutable_location()->CopyFrom(MakePoint(latitude, longitude));
+ return f;
+}
+
+RouteNote MakeRouteNote(const std::string& message,
+ long latitude, long longitude) {
+ RouteNote n;
+ n.set_message(message);
+ n.mutable_location()->CopyFrom(MakePoint(latitude, longitude));
+ return n;
+}
+
+class RouteGuideClient {
+ public:
+ RouteGuideClient(std::shared_ptr channel, const std::string& db)
+ : stub_(RouteGuide::NewStub(channel)) {
+ examples::ParseDb(db, &feature_list_);
+ }
+
+ void GetFeature() {
+ Point point;
+ Feature feature;
+ point = MakePoint(409146138, -746188906);
+ GetOneFeature(point, &feature);
+ point = MakePoint(0, 0);
+ GetOneFeature(point, &feature);
+ }
+
+ void ListFeatures() {
+ examples::Rectangle rect;
+ Feature feature;
+ ClientContext context;
+
+ rect.mutable_lo()->set_latitude(400000000);
+ rect.mutable_lo()->set_longitude(-750000000);
+ rect.mutable_hi()->set_latitude(420000000);
+ rect.mutable_hi()->set_longitude(-730000000);
+ std::cout << "Looking for features between 40, -75 and 42, -73"
+ << std::endl;
+
+ std::unique_ptr > reader(
+ stub_->ListFeatures(&context, rect));
+ while (reader->Read(&feature)) {
+ std::cout << "Found feature called "
+ << feature.name() << " at "
+ << feature.location().latitude()/kCoordFactor_ << ", "
+ << feature.location().longitude()/kCoordFactor_ << std::endl;
+ }
+ Status status = reader->Finish();
+ if (status.ok()) {
+ std::cout << "ListFeatures rpc succeeded." << std::endl;
+ } else {
+ std::cout << "ListFeatures rpc failed." << std::endl;
+ }
+ }
+
+ void RecordRoute() {
+ Point point;
+ RouteSummary stats;
+ ClientContext context;
+ const int kPoints = 10;
+ unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
+
+ std::default_random_engine generator(seed);
+ std::uniform_int_distribution feature_distribution(
+ 0, feature_list_.size() - 1);
+ std::uniform_int_distribution delay_distribution(
+ 500, 1500);
+
+ std::unique_ptr > writer(
+ stub_->RecordRoute(&context, &stats));
+ for (int i = 0; i < kPoints; i++) {
+ const Feature& f = feature_list_[feature_distribution(generator)];
+ std::cout << "Visiting point "
+ << f.location().latitude()/kCoordFactor_ << ", "
+ << f.location().longitude()/kCoordFactor_ << std::endl;
+ if (!writer->Write(f.location())) {
+ // Broken stream.
+ break;
+ }
+ std::this_thread::sleep_for(std::chrono::milliseconds(
+ delay_distribution(generator)));
+ }
+ writer->WritesDone();
+ Status status = writer->Finish();
+ if (status.ok()) {
+ std::cout << "Finished trip with " << stats.point_count() << " points\n"
+ << "Passed " << stats.feature_count() << " features\n"
+ << "Travelled " << stats.distance() << " meters\n"
+ << "It took " << stats.elapsed_time() << " seconds"
+ << std::endl;
+ } else {
+ std::cout << "RecordRoute rpc failed." << std::endl;
+ }
+ }
+
+ void RouteChat() {
+ ClientContext context;
+
+ std::shared_ptr > stream(
+ stub_->RouteChat(&context));
+
+ std::thread writer([stream]() {
+ std::vector notes{
+ MakeRouteNote("First message", 0, 0),
+ MakeRouteNote("Second message", 0, 1),
+ MakeRouteNote("Third message", 1, 0),
+ MakeRouteNote("Fourth message", 0, 0)};
+ for (const RouteNote& note : notes) {
+ std::cout << "Sending message " << note.message()
+ << " at " << note.location().latitude() << ", "
+ << note.location().longitude() << std::endl;
+ stream->Write(note);
+ }
+ stream->WritesDone();
+ });
+
+ RouteNote server_note;
+ while (stream->Read(&server_note)) {
+ std::cout << "Got message " << server_note.message()
+ << " at " << server_note.location().latitude() << ", "
+ << server_note.location().longitude() << std::endl;
+ }
+ writer.join();
+ Status status = stream->Finish();
+ if (!status.ok()) {
+ std::cout << "RouteChat rpc failed." << std::endl;
+ }
+ }
+
+ private:
+
+ bool GetOneFeature(const Point& point, Feature* feature) {
+ ClientContext context;
+ Status status = stub_->GetFeature(&context, point, feature);
+ if (!status.ok()) {
+ std::cout << "GetFeature rpc failed." << std::endl;
+ return false;
+ }
+ if (!feature->has_location()) {
+ std::cout << "Server returns incomplete feature." << std::endl;
+ return false;
+ }
+ if (feature->name().empty()) {
+ std::cout << "Found no feature at "
+ << feature->location().latitude()/kCoordFactor_ << ", "
+ << feature->location().longitude()/kCoordFactor_ << std::endl;
+ } else {
+ std::cout << "Found feature called " << feature->name() << " at "
+ << feature->location().latitude()/kCoordFactor_ << ", "
+ << feature->location().longitude()/kCoordFactor_ << std::endl;
+ }
+ return true;
+ }
+
+ const float kCoordFactor_ = 10000000.0;
+ std::unique_ptr stub_;
+ std::vector feature_list_;
+};
+
+int main(int argc, char** argv) {
+ // Expect only arg: --db_path=path/to/route_guide_db.json.
+ std::string db = examples::GetDbFileContent(argc, argv);
+ RouteGuideClient guide(
+ grpc::CreateChannel("localhost:50051", grpc::InsecureCredentials(),
+ ChannelArguments()),
+ db);
+
+ std::cout << "-------------- GetFeature --------------" << std::endl;
+ guide.GetFeature();
+ std::cout << "-------------- ListFeatures --------------" << std::endl;
+ guide.ListFeatures();
+ std::cout << "-------------- RecordRoute --------------" << std::endl;
+ guide.RecordRoute();
+ std::cout << "-------------- RouteChat --------------" << std::endl;
+ guide.RouteChat();
+
+ return 0;
+}
diff --git a/examples/cpp/route_guide/route_guide_db.json b/examples/cpp/route_guide/route_guide_db.json
new file mode 100644
index 00000000000..9d6a980ab7d
--- /dev/null
+++ b/examples/cpp/route_guide/route_guide_db.json
@@ -0,0 +1,601 @@
+[{
+ "location": {
+ "latitude": 407838351,
+ "longitude": -746143763
+ },
+ "name": "Patriots Path, Mendham, NJ 07945, USA"
+}, {
+ "location": {
+ "latitude": 408122808,
+ "longitude": -743999179
+ },
+ "name": "101 New Jersey 10, Whippany, NJ 07981, USA"
+}, {
+ "location": {
+ "latitude": 413628156,
+ "longitude": -749015468
+ },
+ "name": "U.S. 6, Shohola, PA 18458, USA"
+}, {
+ "location": {
+ "latitude": 419999544,
+ "longitude": -740371136
+ },
+ "name": "5 Conners Road, Kingston, NY 12401, USA"
+}, {
+ "location": {
+ "latitude": 414008389,
+ "longitude": -743951297
+ },
+ "name": "Mid Hudson Psychiatric Center, New Hampton, NY 10958, USA"
+}, {
+ "location": {
+ "latitude": 419611318,
+ "longitude": -746524769
+ },
+ "name": "287 Flugertown Road, Livingston Manor, NY 12758, USA"
+}, {
+ "location": {
+ "latitude": 406109563,
+ "longitude": -742186778
+ },
+ "name": "4001 Tremley Point Road, Linden, NJ 07036, USA"
+}, {
+ "location": {
+ "latitude": 416802456,
+ "longitude": -742370183
+ },
+ "name": "352 South Mountain Road, Wallkill, NY 12589, USA"
+}, {
+ "location": {
+ "latitude": 412950425,
+ "longitude": -741077389
+ },
+ "name": "Bailey Turn Road, Harriman, NY 10926, USA"
+}, {
+ "location": {
+ "latitude": 412144655,
+ "longitude": -743949739
+ },
+ "name": "193-199 Wawayanda Road, Hewitt, NJ 07421, USA"
+}, {
+ "location": {
+ "latitude": 415736605,
+ "longitude": -742847522
+ },
+ "name": "406-496 Ward Avenue, Pine Bush, NY 12566, USA"
+}, {
+ "location": {
+ "latitude": 413843930,
+ "longitude": -740501726
+ },
+ "name": "162 Merrill Road, Highland Mills, NY 10930, USA"
+}, {
+ "location": {
+ "latitude": 410873075,
+ "longitude": -744459023
+ },
+ "name": "Clinton Road, West Milford, NJ 07480, USA"
+}, {
+ "location": {
+ "latitude": 412346009,
+ "longitude": -744026814
+ },
+ "name": "16 Old Brook Lane, Warwick, NY 10990, USA"
+}, {
+ "location": {
+ "latitude": 402948455,
+ "longitude": -747903913
+ },
+ "name": "3 Drake Lane, Pennington, NJ 08534, USA"
+}, {
+ "location": {
+ "latitude": 406337092,
+ "longitude": -740122226
+ },
+ "name": "6324 8th Avenue, Brooklyn, NY 11220, USA"
+}, {
+ "location": {
+ "latitude": 406421967,
+ "longitude": -747727624
+ },
+ "name": "1 Merck Access Road, Whitehouse Station, NJ 08889, USA"
+}, {
+ "location": {
+ "latitude": 416318082,
+ "longitude": -749677716
+ },
+ "name": "78-98 Schalck Road, Narrowsburg, NY 12764, USA"
+}, {
+ "location": {
+ "latitude": 415301720,
+ "longitude": -748416257
+ },
+ "name": "282 Lakeview Drive Road, Highland Lake, NY 12743, USA"
+}, {
+ "location": {
+ "latitude": 402647019,
+ "longitude": -747071791
+ },
+ "name": "330 Evelyn Avenue, Hamilton Township, NJ 08619, USA"
+}, {
+ "location": {
+ "latitude": 412567807,
+ "longitude": -741058078
+ },
+ "name": "New York State Reference Route 987E, Southfields, NY 10975, USA"
+}, {
+ "location": {
+ "latitude": 416855156,
+ "longitude": -744420597
+ },
+ "name": "103-271 Tempaloni Road, Ellenville, NY 12428, USA"
+}, {
+ "location": {
+ "latitude": 404663628,
+ "longitude": -744820157
+ },
+ "name": "1300 Airport Road, North Brunswick Township, NJ 08902, USA"
+}, {
+ "location": {
+ "latitude": 407113723,
+ "longitude": -749746483
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 402133926,
+ "longitude": -743613249
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 400273442,
+ "longitude": -741220915
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 411236786,
+ "longitude": -744070769
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 411633782,
+ "longitude": -746784970
+ },
+ "name": "211-225 Plains Road, Augusta, NJ 07822, USA"
+}, {
+ "location": {
+ "latitude": 415830701,
+ "longitude": -742952812
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 413447164,
+ "longitude": -748712898
+ },
+ "name": "165 Pedersen Ridge Road, Milford, PA 18337, USA"
+}, {
+ "location": {
+ "latitude": 405047245,
+ "longitude": -749800722
+ },
+ "name": "100-122 Locktown Road, Frenchtown, NJ 08825, USA"
+}, {
+ "location": {
+ "latitude": 418858923,
+ "longitude": -746156790
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 417951888,
+ "longitude": -748484944
+ },
+ "name": "650-652 Willi Hill Road, Swan Lake, NY 12783, USA"
+}, {
+ "location": {
+ "latitude": 407033786,
+ "longitude": -743977337
+ },
+ "name": "26 East 3rd Street, New Providence, NJ 07974, USA"
+}, {
+ "location": {
+ "latitude": 417548014,
+ "longitude": -740075041
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 410395868,
+ "longitude": -744972325
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 404615353,
+ "longitude": -745129803
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 406589790,
+ "longitude": -743560121
+ },
+ "name": "611 Lawrence Avenue, Westfield, NJ 07090, USA"
+}, {
+ "location": {
+ "latitude": 414653148,
+ "longitude": -740477477
+ },
+ "name": "18 Lannis Avenue, New Windsor, NY 12553, USA"
+}, {
+ "location": {
+ "latitude": 405957808,
+ "longitude": -743255336
+ },
+ "name": "82-104 Amherst Avenue, Colonia, NJ 07067, USA"
+}, {
+ "location": {
+ "latitude": 411733589,
+ "longitude": -741648093
+ },
+ "name": "170 Seven Lakes Drive, Sloatsburg, NY 10974, USA"
+}, {
+ "location": {
+ "latitude": 412676291,
+ "longitude": -742606606
+ },
+ "name": "1270 Lakes Road, Monroe, NY 10950, USA"
+}, {
+ "location": {
+ "latitude": 409224445,
+ "longitude": -748286738
+ },
+ "name": "509-535 Alphano Road, Great Meadows, NJ 07838, USA"
+}, {
+ "location": {
+ "latitude": 406523420,
+ "longitude": -742135517
+ },
+ "name": "652 Garden Street, Elizabeth, NJ 07202, USA"
+}, {
+ "location": {
+ "latitude": 401827388,
+ "longitude": -740294537
+ },
+ "name": "349 Sea Spray Court, Neptune City, NJ 07753, USA"
+}, {
+ "location": {
+ "latitude": 410564152,
+ "longitude": -743685054
+ },
+ "name": "13-17 Stanley Street, West Milford, NJ 07480, USA"
+}, {
+ "location": {
+ "latitude": 408472324,
+ "longitude": -740726046
+ },
+ "name": "47 Industrial Avenue, Teterboro, NJ 07608, USA"
+}, {
+ "location": {
+ "latitude": 412452168,
+ "longitude": -740214052
+ },
+ "name": "5 White Oak Lane, Stony Point, NY 10980, USA"
+}, {
+ "location": {
+ "latitude": 409146138,
+ "longitude": -746188906
+ },
+ "name": "Berkshire Valley Management Area Trail, Jefferson, NJ, USA"
+}, {
+ "location": {
+ "latitude": 404701380,
+ "longitude": -744781745
+ },
+ "name": "1007 Jersey Avenue, New Brunswick, NJ 08901, USA"
+}, {
+ "location": {
+ "latitude": 409642566,
+ "longitude": -746017679
+ },
+ "name": "6 East Emerald Isle Drive, Lake Hopatcong, NJ 07849, USA"
+}, {
+ "location": {
+ "latitude": 408031728,
+ "longitude": -748645385
+ },
+ "name": "1358-1474 New Jersey 57, Port Murray, NJ 07865, USA"
+}, {
+ "location": {
+ "latitude": 413700272,
+ "longitude": -742135189
+ },
+ "name": "367 Prospect Road, Chester, NY 10918, USA"
+}, {
+ "location": {
+ "latitude": 404310607,
+ "longitude": -740282632
+ },
+ "name": "10 Simon Lake Drive, Atlantic Highlands, NJ 07716, USA"
+}, {
+ "location": {
+ "latitude": 409319800,
+ "longitude": -746201391
+ },
+ "name": "11 Ward Street, Mount Arlington, NJ 07856, USA"
+}, {
+ "location": {
+ "latitude": 406685311,
+ "longitude": -742108603
+ },
+ "name": "300-398 Jefferson Avenue, Elizabeth, NJ 07201, USA"
+}, {
+ "location": {
+ "latitude": 419018117,
+ "longitude": -749142781
+ },
+ "name": "43 Dreher Road, Roscoe, NY 12776, USA"
+}, {
+ "location": {
+ "latitude": 412856162,
+ "longitude": -745148837
+ },
+ "name": "Swan Street, Pine Island, NY 10969, USA"
+}, {
+ "location": {
+ "latitude": 416560744,
+ "longitude": -746721964
+ },
+ "name": "66 Pleasantview Avenue, Monticello, NY 12701, USA"
+}, {
+ "location": {
+ "latitude": 405314270,
+ "longitude": -749836354
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 414219548,
+ "longitude": -743327440
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 415534177,
+ "longitude": -742900616
+ },
+ "name": "565 Winding Hills Road, Montgomery, NY 12549, USA"
+}, {
+ "location": {
+ "latitude": 406898530,
+ "longitude": -749127080
+ },
+ "name": "231 Rocky Run Road, Glen Gardner, NJ 08826, USA"
+}, {
+ "location": {
+ "latitude": 407586880,
+ "longitude": -741670168
+ },
+ "name": "100 Mount Pleasant Avenue, Newark, NJ 07104, USA"
+}, {
+ "location": {
+ "latitude": 400106455,
+ "longitude": -742870190
+ },
+ "name": "517-521 Huntington Drive, Manchester Township, NJ 08759, USA"
+}, {
+ "location": {
+ "latitude": 400066188,
+ "longitude": -746793294
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 418803880,
+ "longitude": -744102673
+ },
+ "name": "40 Mountain Road, Napanoch, NY 12458, USA"
+}, {
+ "location": {
+ "latitude": 414204288,
+ "longitude": -747895140
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 414777405,
+ "longitude": -740615601
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 415464475,
+ "longitude": -747175374
+ },
+ "name": "48 North Road, Forestburgh, NY 12777, USA"
+}, {
+ "location": {
+ "latitude": 404062378,
+ "longitude": -746376177
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 405688272,
+ "longitude": -749285130
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 400342070,
+ "longitude": -748788996
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 401809022,
+ "longitude": -744157964
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 404226644,
+ "longitude": -740517141
+ },
+ "name": "9 Thompson Avenue, Leonardo, NJ 07737, USA"
+}, {
+ "location": {
+ "latitude": 410322033,
+ "longitude": -747871659
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 407100674,
+ "longitude": -747742727
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 418811433,
+ "longitude": -741718005
+ },
+ "name": "213 Bush Road, Stone Ridge, NY 12484, USA"
+}, {
+ "location": {
+ "latitude": 415034302,
+ "longitude": -743850945
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 411349992,
+ "longitude": -743694161
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 404839914,
+ "longitude": -744759616
+ },
+ "name": "1-17 Bergen Court, New Brunswick, NJ 08901, USA"
+}, {
+ "location": {
+ "latitude": 414638017,
+ "longitude": -745957854
+ },
+ "name": "35 Oakland Valley Road, Cuddebackville, NY 12729, USA"
+}, {
+ "location": {
+ "latitude": 412127800,
+ "longitude": -740173578
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 401263460,
+ "longitude": -747964303
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 412843391,
+ "longitude": -749086026
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 418512773,
+ "longitude": -743067823
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 404318328,
+ "longitude": -740835638
+ },
+ "name": "42-102 Main Street, Belford, NJ 07718, USA"
+}, {
+ "location": {
+ "latitude": 419020746,
+ "longitude": -741172328
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 404080723,
+ "longitude": -746119569
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 401012643,
+ "longitude": -744035134
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 404306372,
+ "longitude": -741079661
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 403966326,
+ "longitude": -748519297
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 405002031,
+ "longitude": -748407866
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 409532885,
+ "longitude": -742200683
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 416851321,
+ "longitude": -742674555
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 406411633,
+ "longitude": -741722051
+ },
+ "name": "3387 Richmond Terrace, Staten Island, NY 10303, USA"
+}, {
+ "location": {
+ "latitude": 413069058,
+ "longitude": -744597778
+ },
+ "name": "261 Van Sickle Road, Goshen, NY 10924, USA"
+}, {
+ "location": {
+ "latitude": 418465462,
+ "longitude": -746859398
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 411733222,
+ "longitude": -744228360
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 410248224,
+ "longitude": -747127767
+ },
+ "name": "3 Hasta Way, Newton, NJ 07860, USA"
+}]
diff --git a/examples/cpp/route_guide/route_guide_server.cc b/examples/cpp/route_guide/route_guide_server.cc
new file mode 100644
index 00000000000..b37539299a3
--- /dev/null
+++ b/examples/cpp/route_guide/route_guide_server.cc
@@ -0,0 +1,202 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include "helper.h"
+#include "route_guide.grpc.pb.h"
+
+using grpc::Server;
+using grpc::ServerBuilder;
+using grpc::ServerContext;
+using grpc::ServerReader;
+using grpc::ServerReaderWriter;
+using grpc::ServerWriter;
+using grpc::Status;
+using examples::Point;
+using examples::Feature;
+using examples::Rectangle;
+using examples::RouteSummary;
+using examples::RouteNote;
+using examples::RouteGuide;
+using std::chrono::system_clock;
+
+
+float ConvertToRadians(float num) {
+ return num * 3.1415926 /180;
+}
+
+float GetDistance(const Point& start, const Point& end) {
+ const float kCoordFactor = 10000000.0;
+ float lat_1 = start.latitude() / kCoordFactor;
+ float lat_2 = end.latitude() / kCoordFactor;
+ float lon_1 = start.longitude() / kCoordFactor;
+ float lon_2 = end.longitude() / kCoordFactor;
+ float lat_rad_1 = ConvertToRadians(lat_1);
+ float lat_rad_2 = ConvertToRadians(lat_2);
+ float delta_lat_rad = ConvertToRadians(lat_2-lat_1);
+ float delta_lon_rad = ConvertToRadians(lon_2-lon_1);
+
+ float a = pow(sin(delta_lat_rad/2), 2) + cos(lat_rad_1) * cos(lat_rad_2) *
+ pow(sin(delta_lon_rad/2), 2);
+ float c = 2 * atan2(sqrt(a), sqrt(1-a));
+ int R = 6371000; // metres
+
+ return R * c;
+}
+
+std::string GetFeatureName(const Point& point,
+ const std::vector& feature_list) {
+ for (const Feature& f : feature_list) {
+ if (f.location().latitude() == point.latitude() &&
+ f.location().longitude() == point.longitude()) {
+ return f.name();
+ }
+ }
+ return "";
+}
+
+class RouteGuideImpl final : public RouteGuide::Service {
+ public:
+ explicit RouteGuideImpl(const std::string& db) {
+ examples::ParseDb(db, &feature_list_);
+ }
+
+ Status GetFeature(ServerContext* context, const Point* point,
+ Feature* feature) override {
+ feature->set_name(GetFeatureName(*point, feature_list_));
+ feature->mutable_location()->CopyFrom(*point);
+ return Status::OK;
+ }
+
+ Status ListFeatures(ServerContext* context,
+ const examples::Rectangle* rectangle,
+ ServerWriter* writer) override {
+ auto lo = rectangle->lo();
+ auto hi = rectangle->hi();
+ long left = (std::min)(lo.longitude(), hi.longitude());
+ long right = (std::max)(lo.longitude(), hi.longitude());
+ long top = (std::max)(lo.latitude(), hi.latitude());
+ long bottom = (std::min)(lo.latitude(), hi.latitude());
+ for (const Feature& f : feature_list_) {
+ if (f.location().longitude() >= left &&
+ f.location().longitude() <= right &&
+ f.location().latitude() >= bottom &&
+ f.location().latitude() <= top) {
+ writer->Write(f);
+ }
+ }
+ return Status::OK;
+ }
+
+ Status RecordRoute(ServerContext* context, ServerReader* reader,
+ RouteSummary* summary) override {
+ Point point;
+ int point_count = 0;
+ int feature_count = 0;
+ float distance = 0.0;
+ Point previous;
+
+ system_clock::time_point start_time = system_clock::now();
+ while (reader->Read(&point)) {
+ point_count++;
+ if (!GetFeatureName(point, feature_list_).empty()) {
+ feature_count++;
+ }
+ if (point_count != 1) {
+ distance += GetDistance(previous, point);
+ }
+ previous = point;
+ }
+ system_clock::time_point end_time = system_clock::now();
+ summary->set_point_count(point_count);
+ summary->set_feature_count(feature_count);
+ summary->set_distance(static_cast(distance));
+ auto secs = std::chrono::duration_cast(
+ end_time - start_time);
+ summary->set_elapsed_time(secs.count());
+
+ return Status::OK;
+ }
+
+ Status RouteChat(ServerContext* context,
+ ServerReaderWriter* stream) override {
+ std::vector received_notes;
+ RouteNote note;
+ while (stream->Read(¬e)) {
+ for (const RouteNote& n : received_notes) {
+ if (n.location().latitude() == note.location().latitude() &&
+ n.location().longitude() == note.location().longitude()) {
+ stream->Write(n);
+ }
+ }
+ received_notes.push_back(note);
+ }
+
+ return Status::OK;
+ }
+
+ private:
+
+ std::vector feature_list_;
+};
+
+void RunServer(const std::string& db_path) {
+ std::string server_address("0.0.0.0:50051");
+ RouteGuideImpl service(db_path);
+
+ ServerBuilder builder;
+ builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
+ builder.RegisterService(&service);
+ std::unique_ptr server(builder.BuildAndStart());
+ std::cout << "Server listening on " << server_address << std::endl;
+ server->Wait();
+}
+
+int main(int argc, char** argv) {
+ // Expect only arg: --db_path=path/to/route_guide_db.json.
+ std::string db = examples::GetDbFileContent(argc, argv);
+ RunServer(db);
+
+ return 0;
+}
diff --git a/examples/csharp/.gitignore b/examples/csharp/.gitignore
new file mode 100644
index 00000000000..585000ea2d5
--- /dev/null
+++ b/examples/csharp/.gitignore
@@ -0,0 +1,5 @@
+bin/
+obj/
+packages/
+*.suo
+*.userprefs
diff --git a/examples/csharp/.nuget/packages.config b/examples/csharp/.nuget/packages.config
new file mode 100644
index 00000000000..b14373069f1
--- /dev/null
+++ b/examples/csharp/.nuget/packages.config
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/examples/csharp/Greeter.sln b/examples/csharp/Greeter.sln
new file mode 100644
index 00000000000..9430e94de99
--- /dev/null
+++ b/examples/csharp/Greeter.sln
@@ -0,0 +1,42 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2013
+VisualStudioVersion = 12.0.31101.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Greeter", "Greeter\Greeter.csproj", "{724DFC8C-4B57-4C3F-811C-0463BE2A2829}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreeterServer", "GreeterServer\GreeterServer.csproj", "{A7706C84-92D2-4B7A-B779-76B64D2950EC}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreeterClient", "GreeterClient\GreeterClient.csproj", "{ACCF4597-3748-4117-8633-1CB767F8CCC3}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{FF1EBE95-F20D-4C27-8A61-D0125F3C8152}"
+ ProjectSection(SolutionItems) = preProject
+ .nuget\packages.config = .nuget\packages.config
+ EndProjectSection
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {724DFC8C-4B57-4C3F-811C-0463BE2A2829}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {724DFC8C-4B57-4C3F-811C-0463BE2A2829}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {724DFC8C-4B57-4C3F-811C-0463BE2A2829}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {724DFC8C-4B57-4C3F-811C-0463BE2A2829}.Release|Any CPU.Build.0 = Release|Any CPU
+ {A7706C84-92D2-4B7A-B779-76B64D2950EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {A7706C84-92D2-4B7A-B779-76B64D2950EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A7706C84-92D2-4B7A-B779-76B64D2950EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {A7706C84-92D2-4B7A-B779-76B64D2950EC}.Release|Any CPU.Build.0 = Release|Any CPU
+ {ACCF4597-3748-4117-8633-1CB767F8CCC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {ACCF4597-3748-4117-8633-1CB767F8CCC3}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {ACCF4597-3748-4117-8633-1CB767F8CCC3}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {ACCF4597-3748-4117-8633-1CB767F8CCC3}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(MonoDevelopProperties) = preSolution
+ StartupItem = Greeter\Greeter.csproj
+ EndGlobalSection
+EndGlobal
diff --git a/examples/csharp/Greeter/.gitignore b/examples/csharp/Greeter/.gitignore
new file mode 100644
index 00000000000..1746e3269ed
--- /dev/null
+++ b/examples/csharp/Greeter/.gitignore
@@ -0,0 +1,2 @@
+bin
+obj
diff --git a/examples/csharp/Greeter/Greeter.csproj b/examples/csharp/Greeter/Greeter.csproj
new file mode 100644
index 00000000000..b8f965dbd22
--- /dev/null
+++ b/examples/csharp/Greeter/Greeter.csproj
@@ -0,0 +1,81 @@
+
+
+
+
+
+
+ Debug
+ AnyCPU
+ 10.0.0
+ 2.0
+ {724DFC8C-4B57-4C3F-811C-0463BE2A2829}
+ Library
+ Greeter
+ Greeter
+ v4.5
+ 927432a0
+
+
+ true
+ full
+ false
+ bin\Debug
+ DEBUG;
+ prompt
+ 4
+ false
+
+
+ full
+ true
+ bin\Release
+ prompt
+ 4
+ false
+
+
+
+ ..\packages\Google.ProtocolBuffers.2.4.1.555\lib\net40\Google.ProtocolBuffers.dll
+
+
+ ..\packages\Google.ProtocolBuffers.2.4.1.555\lib\net40\Google.ProtocolBuffers.Serialization.dll
+
+
+ False
+ ..\packages\Grpc.Core.0.6.0\lib\net45\Grpc.Core.dll
+
+
+
+ False
+ ..\packages\System.Collections.Immutable.1.1.36\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll
+
+
+ ..\packages\Ix-Async.1.2.3\lib\net45\System.Interactive.Async.dll
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/csharp/Greeter/Helloworld.cs b/examples/csharp/Greeter/Helloworld.cs
new file mode 100644
index 00000000000..923a4271e98
--- /dev/null
+++ b/examples/csharp/Greeter/Helloworld.cs
@@ -0,0 +1,617 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: helloworld.proto
+#pragma warning disable 1591, 0612, 3021
+#region Designer generated code
+
+using pb = global::Google.ProtocolBuffers;
+using pbc = global::Google.ProtocolBuffers.Collections;
+using pbd = global::Google.ProtocolBuffers.Descriptors;
+using scg = global::System.Collections.Generic;
+namespace helloworld {
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ public static partial class Helloworld {
+
+ #region Extension registration
+ public static void RegisterAllExtensions(pb::ExtensionRegistry registry) {
+ }
+ #endregion
+ #region Static variables
+ internal static pbd::MessageDescriptor internal__static_helloworld_HelloRequest__Descriptor;
+ internal static pb::FieldAccess.FieldAccessorTable internal__static_helloworld_HelloRequest__FieldAccessorTable;
+ internal static pbd::MessageDescriptor internal__static_helloworld_HelloReply__Descriptor;
+ internal static pb::FieldAccess.FieldAccessorTable internal__static_helloworld_HelloReply__FieldAccessorTable;
+ #endregion
+ #region Descriptor
+ public static pbd::FileDescriptor Descriptor {
+ get { return descriptor; }
+ }
+ private static pbd::FileDescriptor descriptor;
+
+ static Helloworld() {
+ byte[] descriptorData = global::System.Convert.FromBase64String(
+ string.Concat(
+ "ChBoZWxsb3dvcmxkLnByb3RvEgpoZWxsb3dvcmxkIhwKDEhlbGxvUmVxdWVz",
+ "dBIMCgRuYW1lGAEgASgJIh0KCkhlbGxvUmVwbHkSDwoHbWVzc2FnZRgBIAEo",
+ "CTJJCgdHcmVldGVyEj4KCFNheUhlbGxvEhguaGVsbG93b3JsZC5IZWxsb1Jl",
+ "cXVlc3QaFi5oZWxsb3dvcmxkLkhlbGxvUmVwbHkiAEISChBpby5ncnBjLmV4",
+ "YW1wbGVz"));
+ pbd::FileDescriptor.InternalDescriptorAssigner assigner = delegate(pbd::FileDescriptor root) {
+ descriptor = root;
+ internal__static_helloworld_HelloRequest__Descriptor = Descriptor.MessageTypes[0];
+ internal__static_helloworld_HelloRequest__FieldAccessorTable =
+ new pb::FieldAccess.FieldAccessorTable(internal__static_helloworld_HelloRequest__Descriptor,
+ new string[] { "Name", });
+ internal__static_helloworld_HelloReply__Descriptor = Descriptor.MessageTypes[1];
+ internal__static_helloworld_HelloReply__FieldAccessorTable =
+ new pb::FieldAccess.FieldAccessorTable(internal__static_helloworld_HelloReply__Descriptor,
+ new string[] { "Message", });
+ pb::ExtensionRegistry registry = pb::ExtensionRegistry.CreateInstance();
+ RegisterAllExtensions(registry);
+ return registry;
+ };
+ pbd::FileDescriptor.InternalBuildGeneratedFileFrom(descriptorData,
+ new pbd::FileDescriptor[] {
+ }, assigner);
+ }
+ #endregion
+
+ }
+ #region Messages
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ public sealed partial class HelloRequest : pb::GeneratedMessage {
+ private HelloRequest() { }
+ private static readonly HelloRequest defaultInstance = new HelloRequest().MakeReadOnly();
+ private static readonly string[] _helloRequestFieldNames = new string[] { "name" };
+ private static readonly uint[] _helloRequestFieldTags = new uint[] { 10 };
+ public static HelloRequest DefaultInstance {
+ get { return defaultInstance; }
+ }
+
+ public override HelloRequest DefaultInstanceForType {
+ get { return DefaultInstance; }
+ }
+
+ protected override HelloRequest ThisMessage {
+ get { return this; }
+ }
+
+ public static pbd::MessageDescriptor Descriptor {
+ get { return global::helloworld.Helloworld.internal__static_helloworld_HelloRequest__Descriptor; }
+ }
+
+ protected override pb::FieldAccess.FieldAccessorTable InternalFieldAccessors {
+ get { return global::helloworld.Helloworld.internal__static_helloworld_HelloRequest__FieldAccessorTable; }
+ }
+
+ public const int NameFieldNumber = 1;
+ private bool hasName;
+ private string name_ = "";
+ public bool HasName {
+ get { return hasName; }
+ }
+ public string Name {
+ get { return name_; }
+ }
+
+ public override bool IsInitialized {
+ get {
+ return true;
+ }
+ }
+
+ public override void WriteTo(pb::ICodedOutputStream output) {
+ CalcSerializedSize();
+ string[] field_names = _helloRequestFieldNames;
+ if (hasName) {
+ output.WriteString(1, field_names[0], Name);
+ }
+ UnknownFields.WriteTo(output);
+ }
+
+ private int memoizedSerializedSize = -1;
+ public override int SerializedSize {
+ get {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+ return CalcSerializedSize();
+ }
+ }
+
+ private int CalcSerializedSize() {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ if (hasName) {
+ size += pb::CodedOutputStream.ComputeStringSize(1, Name);
+ }
+ size += UnknownFields.SerializedSize;
+ memoizedSerializedSize = size;
+ return size;
+ }
+ public static HelloRequest ParseFrom(pb::ByteString data) {
+ return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
+ }
+ public static HelloRequest ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
+ }
+ public static HelloRequest ParseFrom(byte[] data) {
+ return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
+ }
+ public static HelloRequest ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
+ }
+ public static HelloRequest ParseFrom(global::System.IO.Stream input) {
+ return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
+ }
+ public static HelloRequest ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
+ }
+ public static HelloRequest ParseDelimitedFrom(global::System.IO.Stream input) {
+ return CreateBuilder().MergeDelimitedFrom(input).BuildParsed();
+ }
+ public static HelloRequest ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
+ return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed();
+ }
+ public static HelloRequest ParseFrom(pb::ICodedInputStream input) {
+ return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
+ }
+ public static HelloRequest ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
+ }
+ private HelloRequest MakeReadOnly() {
+ return this;
+ }
+
+ public static Builder CreateBuilder() { return new Builder(); }
+ public override Builder ToBuilder() { return CreateBuilder(this); }
+ public override Builder CreateBuilderForType() { return new Builder(); }
+ public static Builder CreateBuilder(HelloRequest prototype) {
+ return new Builder(prototype);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ public sealed partial class Builder : pb::GeneratedBuilder {
+ protected override Builder ThisBuilder {
+ get { return this; }
+ }
+ public Builder() {
+ result = DefaultInstance;
+ resultIsReadOnly = true;
+ }
+ internal Builder(HelloRequest cloneFrom) {
+ result = cloneFrom;
+ resultIsReadOnly = true;
+ }
+
+ private bool resultIsReadOnly;
+ private HelloRequest result;
+
+ private HelloRequest PrepareBuilder() {
+ if (resultIsReadOnly) {
+ HelloRequest original = result;
+ result = new HelloRequest();
+ resultIsReadOnly = false;
+ MergeFrom(original);
+ }
+ return result;
+ }
+
+ public override bool IsInitialized {
+ get { return result.IsInitialized; }
+ }
+
+ protected override HelloRequest MessageBeingBuilt {
+ get { return PrepareBuilder(); }
+ }
+
+ public override Builder Clear() {
+ result = DefaultInstance;
+ resultIsReadOnly = true;
+ return this;
+ }
+
+ public override Builder Clone() {
+ if (resultIsReadOnly) {
+ return new Builder(result);
+ } else {
+ return new Builder().MergeFrom(result);
+ }
+ }
+
+ public override pbd::MessageDescriptor DescriptorForType {
+ get { return global::helloworld.HelloRequest.Descriptor; }
+ }
+
+ public override HelloRequest DefaultInstanceForType {
+ get { return global::helloworld.HelloRequest.DefaultInstance; }
+ }
+
+ public override HelloRequest BuildPartial() {
+ if (resultIsReadOnly) {
+ return result;
+ }
+ resultIsReadOnly = true;
+ return result.MakeReadOnly();
+ }
+
+ public override Builder MergeFrom(pb::IMessage other) {
+ if (other is HelloRequest) {
+ return MergeFrom((HelloRequest) other);
+ } else {
+ base.MergeFrom(other);
+ return this;
+ }
+ }
+
+ public override Builder MergeFrom(HelloRequest other) {
+ if (other == global::helloworld.HelloRequest.DefaultInstance) return this;
+ PrepareBuilder();
+ if (other.HasName) {
+ Name = other.Name;
+ }
+ this.MergeUnknownFields(other.UnknownFields);
+ return this;
+ }
+
+ public override Builder MergeFrom(pb::ICodedInputStream input) {
+ return MergeFrom(input, pb::ExtensionRegistry.Empty);
+ }
+
+ public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
+ PrepareBuilder();
+ pb::UnknownFieldSet.Builder unknownFields = null;
+ uint tag;
+ string field_name;
+ while (input.ReadTag(out tag, out field_name)) {
+ if(tag == 0 && field_name != null) {
+ int field_ordinal = global::System.Array.BinarySearch(_helloRequestFieldNames, field_name, global::System.StringComparer.Ordinal);
+ if(field_ordinal >= 0)
+ tag = _helloRequestFieldTags[field_ordinal];
+ else {
+ if (unknownFields == null) {
+ unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
+ }
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
+ continue;
+ }
+ }
+ switch (tag) {
+ case 0: {
+ throw pb::InvalidProtocolBufferException.InvalidTag();
+ }
+ default: {
+ if (pb::WireFormat.IsEndGroupTag(tag)) {
+ if (unknownFields != null) {
+ this.UnknownFields = unknownFields.Build();
+ }
+ return this;
+ }
+ if (unknownFields == null) {
+ unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
+ }
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
+ break;
+ }
+ case 10: {
+ result.hasName = input.ReadString(ref result.name_);
+ break;
+ }
+ }
+ }
+
+ if (unknownFields != null) {
+ this.UnknownFields = unknownFields.Build();
+ }
+ return this;
+ }
+
+
+ public bool HasName {
+ get { return result.hasName; }
+ }
+ public string Name {
+ get { return result.Name; }
+ set { SetName(value); }
+ }
+ public Builder SetName(string value) {
+ pb::ThrowHelper.ThrowIfNull(value, "value");
+ PrepareBuilder();
+ result.hasName = true;
+ result.name_ = value;
+ return this;
+ }
+ public Builder ClearName() {
+ PrepareBuilder();
+ result.hasName = false;
+ result.name_ = "";
+ return this;
+ }
+ }
+ static HelloRequest() {
+ object.ReferenceEquals(global::helloworld.Helloworld.Descriptor, null);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ public sealed partial class HelloReply : pb::GeneratedMessage {
+ private HelloReply() { }
+ private static readonly HelloReply defaultInstance = new HelloReply().MakeReadOnly();
+ private static readonly string[] _helloReplyFieldNames = new string[] { "message" };
+ private static readonly uint[] _helloReplyFieldTags = new uint[] { 10 };
+ public static HelloReply DefaultInstance {
+ get { return defaultInstance; }
+ }
+
+ public override HelloReply DefaultInstanceForType {
+ get { return DefaultInstance; }
+ }
+
+ protected override HelloReply ThisMessage {
+ get { return this; }
+ }
+
+ public static pbd::MessageDescriptor Descriptor {
+ get { return global::helloworld.Helloworld.internal__static_helloworld_HelloReply__Descriptor; }
+ }
+
+ protected override pb::FieldAccess.FieldAccessorTable InternalFieldAccessors {
+ get { return global::helloworld.Helloworld.internal__static_helloworld_HelloReply__FieldAccessorTable; }
+ }
+
+ public const int MessageFieldNumber = 1;
+ private bool hasMessage;
+ private string message_ = "";
+ public bool HasMessage {
+ get { return hasMessage; }
+ }
+ public string Message {
+ get { return message_; }
+ }
+
+ public override bool IsInitialized {
+ get {
+ return true;
+ }
+ }
+
+ public override void WriteTo(pb::ICodedOutputStream output) {
+ CalcSerializedSize();
+ string[] field_names = _helloReplyFieldNames;
+ if (hasMessage) {
+ output.WriteString(1, field_names[0], Message);
+ }
+ UnknownFields.WriteTo(output);
+ }
+
+ private int memoizedSerializedSize = -1;
+ public override int SerializedSize {
+ get {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+ return CalcSerializedSize();
+ }
+ }
+
+ private int CalcSerializedSize() {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ if (hasMessage) {
+ size += pb::CodedOutputStream.ComputeStringSize(1, Message);
+ }
+ size += UnknownFields.SerializedSize;
+ memoizedSerializedSize = size;
+ return size;
+ }
+ public static HelloReply ParseFrom(pb::ByteString data) {
+ return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
+ }
+ public static HelloReply ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
+ }
+ public static HelloReply ParseFrom(byte[] data) {
+ return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
+ }
+ public static HelloReply ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
+ }
+ public static HelloReply ParseFrom(global::System.IO.Stream input) {
+ return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
+ }
+ public static HelloReply ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
+ }
+ public static HelloReply ParseDelimitedFrom(global::System.IO.Stream input) {
+ return CreateBuilder().MergeDelimitedFrom(input).BuildParsed();
+ }
+ public static HelloReply ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
+ return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed();
+ }
+ public static HelloReply ParseFrom(pb::ICodedInputStream input) {
+ return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
+ }
+ public static HelloReply ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
+ }
+ private HelloReply MakeReadOnly() {
+ return this;
+ }
+
+ public static Builder CreateBuilder() { return new Builder(); }
+ public override Builder ToBuilder() { return CreateBuilder(this); }
+ public override Builder CreateBuilderForType() { return new Builder(); }
+ public static Builder CreateBuilder(HelloReply prototype) {
+ return new Builder(prototype);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ public sealed partial class Builder : pb::GeneratedBuilder {
+ protected override Builder ThisBuilder {
+ get { return this; }
+ }
+ public Builder() {
+ result = DefaultInstance;
+ resultIsReadOnly = true;
+ }
+ internal Builder(HelloReply cloneFrom) {
+ result = cloneFrom;
+ resultIsReadOnly = true;
+ }
+
+ private bool resultIsReadOnly;
+ private HelloReply result;
+
+ private HelloReply PrepareBuilder() {
+ if (resultIsReadOnly) {
+ HelloReply original = result;
+ result = new HelloReply();
+ resultIsReadOnly = false;
+ MergeFrom(original);
+ }
+ return result;
+ }
+
+ public override bool IsInitialized {
+ get { return result.IsInitialized; }
+ }
+
+ protected override HelloReply MessageBeingBuilt {
+ get { return PrepareBuilder(); }
+ }
+
+ public override Builder Clear() {
+ result = DefaultInstance;
+ resultIsReadOnly = true;
+ return this;
+ }
+
+ public override Builder Clone() {
+ if (resultIsReadOnly) {
+ return new Builder(result);
+ } else {
+ return new Builder().MergeFrom(result);
+ }
+ }
+
+ public override pbd::MessageDescriptor DescriptorForType {
+ get { return global::helloworld.HelloReply.Descriptor; }
+ }
+
+ public override HelloReply DefaultInstanceForType {
+ get { return global::helloworld.HelloReply.DefaultInstance; }
+ }
+
+ public override HelloReply BuildPartial() {
+ if (resultIsReadOnly) {
+ return result;
+ }
+ resultIsReadOnly = true;
+ return result.MakeReadOnly();
+ }
+
+ public override Builder MergeFrom(pb::IMessage other) {
+ if (other is HelloReply) {
+ return MergeFrom((HelloReply) other);
+ } else {
+ base.MergeFrom(other);
+ return this;
+ }
+ }
+
+ public override Builder MergeFrom(HelloReply other) {
+ if (other == global::helloworld.HelloReply.DefaultInstance) return this;
+ PrepareBuilder();
+ if (other.HasMessage) {
+ Message = other.Message;
+ }
+ this.MergeUnknownFields(other.UnknownFields);
+ return this;
+ }
+
+ public override Builder MergeFrom(pb::ICodedInputStream input) {
+ return MergeFrom(input, pb::ExtensionRegistry.Empty);
+ }
+
+ public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
+ PrepareBuilder();
+ pb::UnknownFieldSet.Builder unknownFields = null;
+ uint tag;
+ string field_name;
+ while (input.ReadTag(out tag, out field_name)) {
+ if(tag == 0 && field_name != null) {
+ int field_ordinal = global::System.Array.BinarySearch(_helloReplyFieldNames, field_name, global::System.StringComparer.Ordinal);
+ if(field_ordinal >= 0)
+ tag = _helloReplyFieldTags[field_ordinal];
+ else {
+ if (unknownFields == null) {
+ unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
+ }
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
+ continue;
+ }
+ }
+ switch (tag) {
+ case 0: {
+ throw pb::InvalidProtocolBufferException.InvalidTag();
+ }
+ default: {
+ if (pb::WireFormat.IsEndGroupTag(tag)) {
+ if (unknownFields != null) {
+ this.UnknownFields = unknownFields.Build();
+ }
+ return this;
+ }
+ if (unknownFields == null) {
+ unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
+ }
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
+ break;
+ }
+ case 10: {
+ result.hasMessage = input.ReadString(ref result.message_);
+ break;
+ }
+ }
+ }
+
+ if (unknownFields != null) {
+ this.UnknownFields = unknownFields.Build();
+ }
+ return this;
+ }
+
+
+ public bool HasMessage {
+ get { return result.hasMessage; }
+ }
+ public string Message {
+ get { return result.Message; }
+ set { SetMessage(value); }
+ }
+ public Builder SetMessage(string value) {
+ pb::ThrowHelper.ThrowIfNull(value, "value");
+ PrepareBuilder();
+ result.hasMessage = true;
+ result.message_ = value;
+ return this;
+ }
+ public Builder ClearMessage() {
+ PrepareBuilder();
+ result.hasMessage = false;
+ result.message_ = "";
+ return this;
+ }
+ }
+ static HelloReply() {
+ object.ReferenceEquals(global::helloworld.Helloworld.Descriptor, null);
+ }
+ }
+
+ #endregion
+
+}
+
+#endregion Designer generated code
diff --git a/examples/csharp/Greeter/HelloworldGrpc.cs b/examples/csharp/Greeter/HelloworldGrpc.cs
new file mode 100644
index 00000000000..1ca9d2899b3
--- /dev/null
+++ b/examples/csharp/Greeter/HelloworldGrpc.cs
@@ -0,0 +1,78 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: helloworld.proto
+#region Designer generated code
+
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using Grpc.Core;
+
+namespace helloworld {
+ public static class Greeter
+ {
+ static readonly string __ServiceName = "helloworld.Greeter";
+
+ static readonly Marshaller __Marshaller_HelloRequest = Marshallers.Create((arg) => arg.ToByteArray(), global::helloworld.HelloRequest.ParseFrom);
+ static readonly Marshaller __Marshaller_HelloReply = Marshallers.Create((arg) => arg.ToByteArray(), global::helloworld.HelloReply.ParseFrom);
+
+ static readonly Method __Method_SayHello = new Method(
+ MethodType.Unary,
+ "SayHello",
+ __Marshaller_HelloRequest,
+ __Marshaller_HelloReply);
+
+ // client-side stub interface
+ public interface IGreeterClient
+ {
+ global::helloworld.HelloReply SayHello(global::helloworld.HelloRequest request, CancellationToken token = default(CancellationToken));
+ Task SayHelloAsync(global::helloworld.HelloRequest request, CancellationToken token = default(CancellationToken));
+ }
+
+ // server-side interface
+ public interface IGreeter
+ {
+ Task SayHello(ServerCallContext context, global::helloworld.HelloRequest request);
+ }
+
+ // client stub
+ public class GreeterClient : AbstractStub, IGreeterClient
+ {
+ public GreeterClient(Channel channel) : this(channel, StubConfiguration.Default)
+ {
+ }
+ public GreeterClient(Channel channel, StubConfiguration config) : base(channel, config)
+ {
+ }
+ public global::helloworld.HelloReply SayHello(global::helloworld.HelloRequest request, CancellationToken token = default(CancellationToken))
+ {
+ var call = CreateCall(__ServiceName, __Method_SayHello);
+ return Calls.BlockingUnaryCall(call, request, token);
+ }
+ public Task SayHelloAsync(global::helloworld.HelloRequest request, CancellationToken token = default(CancellationToken))
+ {
+ var call = CreateCall(__ServiceName, __Method_SayHello);
+ return Calls.AsyncUnaryCall(call, request, token);
+ }
+ }
+
+ // creates service definition that can be registered with a server
+ public static ServerServiceDefinition BindService(IGreeter serviceImpl)
+ {
+ return ServerServiceDefinition.CreateBuilder(__ServiceName)
+ .AddMethod(__Method_SayHello, serviceImpl.SayHello).Build();
+ }
+
+ // creates a new client stub
+ public static IGreeterClient NewStub(Channel channel)
+ {
+ return new GreeterClient(channel);
+ }
+
+ // creates a new client stub
+ public static IGreeterClient NewStub(Channel channel, StubConfiguration config)
+ {
+ return new GreeterClient(channel, config);
+ }
+ }
+}
+#endregion
diff --git a/examples/csharp/Greeter/Properties/AssemblyInfo.cs b/examples/csharp/Greeter/Properties/AssemblyInfo.cs
new file mode 100644
index 00000000000..b9d0dc264d5
--- /dev/null
+++ b/examples/csharp/Greeter/Properties/AssemblyInfo.cs
@@ -0,0 +1,22 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+// Information about this assembly is defined by the following attributes.
+// Change them to the values specific to your project.
+[assembly: AssemblyTitle("Greeter")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("")]
+[assembly: AssemblyCopyright("jtattermusch")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
+// The form "{Major}.{Minor}.*" will automatically update the build and revision,
+// and "{Major}.{Minor}.{Build}.*" will update just the revision.
+[assembly: AssemblyVersion("1.0.*")]
+// The following attributes are used to specify the signing key for the assembly,
+// if desired. See the Mono documentation for more information about signing.
+//[assembly: AssemblyDelaySign(false)]
+//[assembly: AssemblyKeyFile("")]
+
diff --git a/examples/csharp/Greeter/packages.config b/examples/csharp/Greeter/packages.config
new file mode 100644
index 00000000000..5922553bc37
--- /dev/null
+++ b/examples/csharp/Greeter/packages.config
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/csharp/Greeter/protos/helloworld.proto b/examples/csharp/Greeter/protos/helloworld.proto
new file mode 100644
index 00000000000..e02ebd94e7c
--- /dev/null
+++ b/examples/csharp/Greeter/protos/helloworld.proto
@@ -0,0 +1,52 @@
+// Copyright 2015, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// TODO(jtattermusch): as of now, C# protobufs don't officially support
+// proto3.
+syntax = "proto2";
+
+option java_package = "io.grpc.examples";
+
+package helloworld;
+
+// The greeting service definition.
+service Greeter {
+ // Sends a greeting
+ rpc SayHello (HelloRequest) returns (HelloReply) {}
+}
+
+// The request message containing the user's name.
+message HelloRequest {
+ optional string name = 1;
+}
+
+// The response message containing the greetings
+message HelloReply {
+ optional string message = 1;
+}
diff --git a/examples/csharp/GreeterClient/.gitignore b/examples/csharp/GreeterClient/.gitignore
new file mode 100644
index 00000000000..1746e3269ed
--- /dev/null
+++ b/examples/csharp/GreeterClient/.gitignore
@@ -0,0 +1,2 @@
+bin
+obj
diff --git a/examples/csharp/GreeterClient/GreeterClient.csproj b/examples/csharp/GreeterClient/GreeterClient.csproj
new file mode 100644
index 00000000000..59b768af018
--- /dev/null
+++ b/examples/csharp/GreeterClient/GreeterClient.csproj
@@ -0,0 +1,84 @@
+
+
+
+
+
+
+ Debug
+ AnyCPU
+ 10.0.0
+ 2.0
+ {ACCF4597-3748-4117-8633-1CB767F8CCC3}
+ Exe
+ GreeterClient
+ GreeterClient
+ v4.5
+ 985ca8be
+
+
+ true
+ full
+ false
+ bin\Debug
+ DEBUG;
+ prompt
+ 4
+ true
+
+
+ full
+ true
+ bin\Release
+ prompt
+ 4
+ true
+
+
+
+ ..\packages\Google.ProtocolBuffers.2.4.1.555\lib\net40\Google.ProtocolBuffers.dll
+
+
+ ..\packages\Google.ProtocolBuffers.2.4.1.555\lib\net40\Google.ProtocolBuffers.Serialization.dll
+
+
+ False
+ ..\packages\Grpc.Core.0.6.0\lib\net45\Grpc.Core.dll
+
+
+
+ False
+ ..\packages\System.Collections.Immutable.1.1.36\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll
+
+
+ ..\packages\Ix-Async.1.2.3\lib\net45\System.Interactive.Async.dll
+
+
+
+
+
+
+
+
+
+ {724DFC8C-4B57-4C3F-811C-0463BE2A2829}
+ Greeter
+
+
+
+
+
+
+
+ This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/csharp/GreeterClient/Program.cs b/examples/csharp/GreeterClient/Program.cs
new file mode 100644
index 00000000000..61c29762b12
--- /dev/null
+++ b/examples/csharp/GreeterClient/Program.cs
@@ -0,0 +1,25 @@
+using System;
+using Grpc.Core;
+using helloworld;
+
+namespace GreeterClient
+{
+ class ClientMainClass
+ {
+ public static void Main(string[] args)
+ {
+ GrpcEnvironment.Initialize();
+
+ using (Channel channel = new Channel("127.0.0.1:50051"))
+ {
+ var client = Greeter.NewStub(channel);
+ String user = "you";
+
+ var reply = client.SayHello(new HelloRequest.Builder { Name = user }.Build());
+ Console.WriteLine("Greeting: " + reply.Message);
+ }
+
+ GrpcEnvironment.Shutdown();
+ }
+ }
+}
diff --git a/examples/csharp/GreeterClient/Properties/AssemblyInfo.cs b/examples/csharp/GreeterClient/Properties/AssemblyInfo.cs
new file mode 100644
index 00000000000..1422e952d8b
--- /dev/null
+++ b/examples/csharp/GreeterClient/Properties/AssemblyInfo.cs
@@ -0,0 +1,22 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+// Information about this assembly is defined by the following attributes.
+// Change them to the values specific to your project.
+[assembly: AssemblyTitle("GreeterClient")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("")]
+[assembly: AssemblyCopyright("jtattermusch")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
+// The form "{Major}.{Minor}.*" will automatically update the build and revision,
+// and "{Major}.{Minor}.{Build}.*" will update just the revision.
+[assembly: AssemblyVersion("1.0.*")]
+// The following attributes are used to specify the signing key for the assembly,
+// if desired. See the Mono documentation for more information about signing.
+//[assembly: AssemblyDelaySign(false)]
+//[assembly: AssemblyKeyFile("")]
+
diff --git a/examples/csharp/GreeterClient/packages.config b/examples/csharp/GreeterClient/packages.config
new file mode 100644
index 00000000000..5922553bc37
--- /dev/null
+++ b/examples/csharp/GreeterClient/packages.config
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/csharp/GreeterServer/.gitignore b/examples/csharp/GreeterServer/.gitignore
new file mode 100644
index 00000000000..1746e3269ed
--- /dev/null
+++ b/examples/csharp/GreeterServer/.gitignore
@@ -0,0 +1,2 @@
+bin
+obj
diff --git a/examples/csharp/GreeterServer/GreeterServer.csproj b/examples/csharp/GreeterServer/GreeterServer.csproj
new file mode 100644
index 00000000000..cd50d6cd529
--- /dev/null
+++ b/examples/csharp/GreeterServer/GreeterServer.csproj
@@ -0,0 +1,84 @@
+
+
+
+
+
+
+ Debug
+ AnyCPU
+ 10.0.0
+ 2.0
+ {A7706C84-92D2-4B7A-B779-76B64D2950EC}
+ Exe
+ GreeterServer
+ GreeterServer
+ v4.5
+ a1eeb1d8
+
+
+ true
+ full
+ false
+ bin\Debug
+ DEBUG;
+ prompt
+ 4
+ true
+
+
+ full
+ true
+ bin\Release
+ prompt
+ 4
+ true
+
+
+
+ ..\packages\Google.ProtocolBuffers.2.4.1.555\lib\net40\Google.ProtocolBuffers.dll
+
+
+ ..\packages\Google.ProtocolBuffers.2.4.1.555\lib\net40\Google.ProtocolBuffers.Serialization.dll
+
+
+ False
+ ..\packages\Grpc.Core.0.6.0\lib\net45\Grpc.Core.dll
+
+
+
+ False
+ ..\packages\System.Collections.Immutable.1.1.36\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll
+
+
+ ..\packages\Ix-Async.1.2.3\lib\net45\System.Interactive.Async.dll
+
+
+
+
+
+
+
+
+
+ {724DFC8C-4B57-4C3F-811C-0463BE2A2829}
+ Greeter
+
+
+
+
+
+
+
+ This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/csharp/GreeterServer/Program.cs b/examples/csharp/GreeterServer/Program.cs
new file mode 100644
index 00000000000..9482797c3b9
--- /dev/null
+++ b/examples/csharp/GreeterServer/Program.cs
@@ -0,0 +1,37 @@
+using System;
+using System.Threading.Tasks;
+using Grpc.Core;
+using helloworld;
+
+namespace GreeterServer
+{
+ class GreeterImpl : Greeter.IGreeter
+ {
+ // Server side handler of the SayHello RPC
+ public Task SayHello(ServerCallContext context, HelloRequest request)
+ {
+ var reply = new HelloReply.Builder { Message = "Hello " + request.Name }.Build();
+ return Task.FromResult(reply);
+ }
+ }
+
+ class ServerMainClass
+ {
+ public static void Main(string[] args)
+ {
+ GrpcEnvironment.Initialize();
+
+ Server server = new Server();
+ server.AddServiceDefinition(Greeter.BindService(new GreeterImpl()));
+ int port = server.AddListeningPort("localhost", 50051);
+ server.Start();
+
+ Console.WriteLine("Greeter server listening on port " + port);
+ Console.WriteLine("Press any key to stop the server...");
+ Console.ReadKey();
+
+ server.ShutdownAsync().Wait();
+ GrpcEnvironment.Shutdown();
+ }
+ }
+}
diff --git a/examples/csharp/GreeterServer/Properties/AssemblyInfo.cs b/examples/csharp/GreeterServer/Properties/AssemblyInfo.cs
new file mode 100644
index 00000000000..f8a8d521d85
--- /dev/null
+++ b/examples/csharp/GreeterServer/Properties/AssemblyInfo.cs
@@ -0,0 +1,22 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+// Information about this assembly is defined by the following attributes.
+// Change them to the values specific to your project.
+[assembly: AssemblyTitle("GreeterServer")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("")]
+[assembly: AssemblyCopyright("jtattermusch")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
+// The form "{Major}.{Minor}.*" will automatically update the build and revision,
+// and "{Major}.{Minor}.{Build}.*" will update just the revision.
+[assembly: AssemblyVersion("1.0.*")]
+// The following attributes are used to specify the signing key for the assembly,
+// if desired. See the Mono documentation for more information about signing.
+//[assembly: AssemblyDelaySign(false)]
+//[assembly: AssemblyKeyFile("")]
+
diff --git a/examples/csharp/GreeterServer/packages.config b/examples/csharp/GreeterServer/packages.config
new file mode 100644
index 00000000000..5922553bc37
--- /dev/null
+++ b/examples/csharp/GreeterServer/packages.config
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/csharp/README.md b/examples/csharp/README.md
new file mode 100644
index 00000000000..fcdcc735f9b
--- /dev/null
+++ b/examples/csharp/README.md
@@ -0,0 +1,72 @@
+gRPC in 3 minutes (C#)
+========================
+
+BACKGROUND
+-------------
+For this sample, we've already generated the server and client stubs from `helloworld.proto`.
+Example projects depend on NuGet packages `Grpc` and `Google.ProtocolBuffers` which have been already added to the project for you.
+
+PREREQUISITES
+-------------
+**Windows**
+- .NET 4.5+
+- VS 2013 (with NuGet plugin installed)
+
+**Linux (Mono)**
+- Mono
+- Monodevelop 5.9 with NuGet Add-in installed (older versions might work)
+
+**MacOS (Mono)**
+- Xamarin Studio (with NuGet plugin installed)
+
+BUILD
+-------
+
+**Windows**
+- Clone this repository.
+
+- Open solution `Greeter.sln` with Visual Studio
+
+- Build the solution (this will automatically download NuGet dependencies)
+
+**Linux (Mono)**
+- Clone this repository.
+
+- Install gRPC C Core using instructions in https://github.com/grpc/homebrew-grpc
+
+- gRPC C# depends on native shared library `libgrpc_csharp_ext.so`. To make it visible
+ to Mono runtime, follow instructions in [Using gRPC C# on Linux](https://github.com/grpc/grpc/tree/master/src/csharp#usage-linux-mono)
+
+- Open solution `Greeter.sln` in MonoDevelop (you need to manually restore dependencies by using `mono nuget.exe restore` if you don't have NuGet add-in)
+
+- Build the solution.
+
+**MacOS (Mono)**
+- See [Using gRPC C# on MacOS](https://github.com/grpc/grpc/tree/master/src/csharp#usage-macos-mono) for more info
+ on MacOS support.
+
+Try it!
+-------
+
+- Run the server
+
+ ```
+ > cd GreeterServer/bin/Debug
+ > GreeterServer.exe
+ ```
+
+- Run the client
+
+ ```
+ > cd GreeterClient/bin/Debug
+ > GreeterClient.exe
+ ```
+
+You can also run the server and client directly from Visual Studio.
+
+On Linux or Mac, use `mono GreeterServer.exe` and `mono GreeterClient.exe` to run the server and client.
+
+Tutorial
+--------
+
+You can find a more detailed tutorial in [gRPC Basics: C#](examples/csharp/route_guide/README.md)
diff --git a/examples/csharp/route_guide/.gitignore b/examples/csharp/route_guide/.gitignore
new file mode 100644
index 00000000000..585000ea2d5
--- /dev/null
+++ b/examples/csharp/route_guide/.gitignore
@@ -0,0 +1,5 @@
+bin/
+obj/
+packages/
+*.suo
+*.userprefs
diff --git a/examples/csharp/route_guide/.nuget/packages.config b/examples/csharp/route_guide/.nuget/packages.config
new file mode 100644
index 00000000000..b14373069f1
--- /dev/null
+++ b/examples/csharp/route_guide/.nuget/packages.config
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/examples/csharp/route_guide/README.md b/examples/csharp/route_guide/README.md
new file mode 100644
index 00000000000..c3262c9b8ae
--- /dev/null
+++ b/examples/csharp/route_guide/README.md
@@ -0,0 +1,409 @@
+#gRPC Basics: C# #
+
+This tutorial provides a basic C# programmer's introduction to working with gRPC. By walking through this example you'll learn how to:
+
+- Define a service in a .proto file.
+- Generate server and client code using the protocol buffer compiler.
+- Use the C# gRPC API to write a simple client and server for your service.
+
+It assumes that you have read the [Getting started](https://github.com/grpc/grpc/tree/master/examples) guide and are familiar with [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). Note that the example in this tutorial only uses the proto2 version of the protocol buffers language, as proto3 support for C# is not ready yet (see [protobuf C# README](https://github.com/google/protobuf/tree/master/csharp#proto2--proto3)).
+
+This isn't a comprehensive guide to using gRPC in C#: more reference documentation is coming soon.
+
+## Why use gRPC?
+
+Our example is a simple route mapping application that lets clients get information about features on their route, create a summary of their route, and exchange route information such as traffic updates with the server and other clients.
+
+With gRPC we can define our service once in a .proto file and implement clients and servers in any of gRPC's supported languages, which in turn can be run in environments ranging from servers inside Google to your own tablet - all the complexity of communication between different languages and environments is handled for you by gRPC. We also get all the advantages of working with protocol buffers, including efficient serialization, a simple IDL, and easy interface updating.
+
+## Example code and setup
+
+The example code for our tutorial is in [examples/csharp/route_guide](examples/csharp/route_guide). To download the example, clone this repository by running the following command:
+```shell
+$ git clone https://github.com/grpc/grpc.git
+```
+
+All the files for this tutorial are in the directory `examples/csharp/route_guide`.
+Open the solution `examples/csharp/route_guide/RouteGuide.sln` from Visual Studio (or Monodevelop on Linux).
+
+On Windows, you should not need to do anything besides opening the solution. All the needed dependencies will be restored
+for you automatically by the `Grpc` NuGet package upon building the solution.
+
+On Linux (or MacOS), you will first need to install protobuf and gRPC C Core using Linuxbrew (or Homebrew) tool in order to be
+able to generate the server and client interface code and run the examples. Follow the instructions for [Linux](https://github.com/grpc/grpc/tree/master/src/csharp#usage-linux-mono) or [MacOS](https://github.com/grpc/grpc/tree/master/src/csharp#usage-macos-mono).
+
+## Defining the service
+
+Our first step (as you'll know from [Getting started](https://github.com/grpc/grpc/tree/master/examples)) is to define the gRPC *service* and the method *request* and *response* types using [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). You can see the complete .proto file in [`examples/csharp/route_guide/RouteGuide/protos/route_guide.proto`](examples/csharp/route_guide/RouteGuide/protos/route_guide.proto).
+
+To define a service, you specify a named `service` in your .proto file:
+
+```protobuf
+service RouteGuide {
+ ...
+}
+```
+
+Then you define `rpc` methods inside your service definition, specifying their request and response types. gRPC lets you define four kinds of service method, all of which are used in the `RouteGuide` service:
+
+- A *simple RPC* where the client sends a request to the server using the stub and waits for a response to come back, just like a normal function call.
+```protobuf
+ // Obtains the feature at a given position.
+ rpc GetFeature(Point) returns (Feature) {}
+```
+
+- A *server-side streaming RPC* where the client sends a request to the server and gets a stream to read a sequence of messages back. The client reads from the returned stream until there are no more messages. As you can see in our example, you specify a server-side streaming method by placing the `stream` keyword before the *response* type.
+```protobuf
+ // Obtains the Features available within the given Rectangle. Results are
+ // streamed rather than returned at once (e.g. in a response message with a
+ // repeated field), as the rectangle may cover a large area and contain a
+ // huge number of features.
+ rpc ListFeatures(Rectangle) returns (stream Feature) {}
+```
+
+- A *client-side streaming RPC* where the client writes a sequence of messages and sends them to the server, again using a provided stream. Once the client has finished writing the messages, it waits for the server to read them all and return its response. You specify a server-side streaming method by placing the `stream` keyword before the *request* type.
+```protobuf
+ // Accepts a stream of Points on a route being traversed, returning a
+ // RouteSummary when traversal is completed.
+ rpc RecordRoute(stream Point) returns (RouteSummary) {}
+```
+
+- A *bidirectional streaming RPC* where both sides send a sequence of messages using a read-write stream. The two streams operate independently, so clients and servers can read and write in whatever order they like: for example, the server could wait to receive all the client messages before writing its responses, or it could alternately read a message then write a message, or some other combination of reads and writes. The order of messages in each stream is preserved. You specify this type of method by placing the `stream` keyword before both the request and the response.
+```protobuf
+ // Accepts a stream of RouteNotes sent while a route is being traversed,
+ // while receiving other RouteNotes (e.g. from other users).
+ rpc RouteChat(stream RouteNote) returns (stream RouteNote) {}
+```
+
+Our .proto file also contains protocol buffer message type definitions for all the request and response types used in our service methods - for example, here's the `Point` message type:
+```protobuf
+// Points are represented as latitude-longitude pairs in the E7 representation
+// (degrees multiplied by 10**7 and rounded to the nearest integer).
+// Latitudes should be in the range +/- 90 degrees and longitude should be in
+// the range +/- 180 degrees (inclusive).
+message Point {
+ int32 latitude = 1;
+ int32 longitude = 2;
+}
+```
+
+
+## Generating client and server code
+
+Next we need to generate the gRPC client and server interfaces from our .proto service definition. We do this using the protocol buffer compiler `protoc` with a special gRPC C# plugin.
+
+If you want to run this yourself, make sure you've installed protoc and gRPC C# plugin. The instructions vary based on your OS:
+- For Windows, the `Grpc.Tools` NuGet package contains the binaries you will need to generate the code.
+- For Linux, make sure you've [installed gRPC C Core using Linuxbrew](https://github.com/grpc/grpc/tree/master/src/csharp#usage-linux-mono)
+- For MacOS, make sure you've [installed gRPC C Core using Homebrew](https://github.com/grpc/grpc/tree/master/src/csharp#usage-macos-mono)
+
+Once that's done, the following command can be used to generate the C# code.
+
+To generate the code on Windows, we use `protoc.exe` and `grpc_csharp_plugin.exe` binaries that are shipped with the `Grpc.Tools` NuGet package under the `tools` directory.
+Normally you would need to add the `Grpc.Tools` package to the solution yourself, but in this tutorial it has been already done for you. Following command should be run from the `csharp/route_guide` directory:
+```
+> packages\Grpc.Tools.0.5.1\tools\protoc -I RouteGuide/protos --csharp_out=RouteGuide --grpc_out=RouteGuide --plugin=protoc-gen-grpc=packages\Grpc.Tools.0.5.1\tools\grpc_csharp_plugin.exe RouteGuide/protos/route_guide.proto
+```
+
+On Linux/MacOS, we rely on `protoc` and `grpc_csharp_plugin` being installed by Linuxbrew/Homebrew. Run this command from the route_guide directory:
+```shell
+$ protoc -I RouteGuide/protos --csharp_out=RouteGuide --grpc_out=RouteGuide --plugin=protoc-gen-grpc=`which grpc_csharp_plugin` RouteGuide/protos/route_guide.proto
+```
+
+Running one of the previous commands regenerates the following files in the RouteGuide directory:
+- `RouteGuide/RouteGuide.cs` defines a namespace `examples`
+ - This contains all the protocol buffer code to populate, serialize, and retrieve our request and response message types
+- `RouteGuide/RouteGuideGrpc.cs`, provides stub and service classes
+ - an interface `RouteGuide.IRouteGuide` to inherit from when defining RouteGuide service implementations
+ - a class `RouteGuide.RouteGuideClient` that can be used to access remote RouteGuide instances
+
+
+
+## Creating the server
+
+First let's look at how we create a `RouteGuide` server. If you're only interested in creating gRPC clients, you can skip this section and go straight to [Creating the client](#client) (though you might find it interesting anyway!).
+
+There are two parts to making our `RouteGuide` service do its job:
+- Implementing the service interface generated from our service definition: doing the actual "work" of our service.
+- Running a gRPC server to listen for requests from clients and return the service responses.
+
+You can find our example `RouteGuide` server in [examples/csharp/route_guide/RouteGuideServer/RouteGuideImpl.cs](examples/csharp/route_guide/RouteGuideServer/RouteGuideServerImpl.cs). Let's take a closer look at how it works.
+
+### Implementing RouteGuide
+
+As you can see, our server has a `RouteGuideImpl` class that implements the generated `RouteGuide.IRouteGuide`:
+
+```csharp
+// RouteGuideImpl provides an implementation of the RouteGuide service.
+public class RouteGuideImpl : RouteGuide.IRouteGuide
+```
+
+#### Simple RPC
+
+`RouteGuideImpl` implements all our service methods. Let's look at the simplest type first, `GetFeature`, which just gets a `Point` from the client and returns the corresponding feature information from its database in a `Feature`.
+
+```csharp
+ public Task GetFeature(Grpc.Core.ServerCallContext context, Point request)
+ {
+ return Task.FromResult(CheckFeature(request));
+ }
+```
+
+The method is passed a context for the RPC (which is empty in the alpha release), the client's `Point` protocol buffer request, and returns a `Feature` protocol buffer. In the method we create the `Feature` with the appropriate information, and then return it. To allow asynchronous
+implementation, the method returns `Task` rather than just `Feature`. You are free to perform your computations synchronously and return
+the result once you've finished, just as we do in the example.
+
+#### Server-side streaming RPC
+
+Now let's look at something a bit more complicated - a streaming RPC. `ListFeatures` is a server-side streaming RPC, so we need to send back multiple `Feature` protocol buffers to our client.
+
+```csharp
+ // in RouteGuideImpl
+ public async Task ListFeatures(Grpc.Core.ServerCallContext context, Rectangle request,
+ Grpc.Core.IServerStreamWriter responseStream)
+ {
+ int left = Math.Min(request.Lo.Longitude, request.Hi.Longitude);
+ int right = Math.Max(request.Lo.Longitude, request.Hi.Longitude);
+ int top = Math.Max(request.Lo.Latitude, request.Hi.Latitude);
+ int bottom = Math.Min(request.Lo.Latitude, request.Hi.Latitude);
+
+ foreach (var feature in features)
+ {
+ if (!RouteGuideUtil.Exists(feature))
+ {
+ continue;
+ }
+
+ int lat = feature.Location.Latitude;
+ int lon = feature.Location.Longitude;
+ if (lon >= left && lon <= right && lat >= bottom && lat <= top)
+ {
+ await responseStream.WriteAsync(feature);
+ }
+ }
+ }
+```
+
+As you can see, here the request object is a `Rectangle` in which our client wants to find `Feature`s, but instead of returning a simple response we need to write responses to an asynchronous stream `IServerStreamWriter` using async method `WriteAsync`.
+
+#### Client-side streaming RPC
+
+Similarly, the client-side streaming method `RecordRoute` uses an [IAsyncEnumerator](https://github.com/Reactive-Extensions/Rx.NET/blob/master/Ix.NET/Source/System.Interactive.Async/IAsyncEnumerator.cs), to read the stream of requests using the async method `MoveNext` and the `Current` property.
+
+```csharp
+ public async Task RecordRoute(Grpc.Core.ServerCallContext context,
+ Grpc.Core.IAsyncStreamReader requestStream)
+ {
+ int pointCount = 0;
+ int featureCount = 0;
+ int distance = 0;
+ Point previous = null;
+ var stopwatch = new Stopwatch();
+ stopwatch.Start();
+
+ while (await requestStream.MoveNext())
+ {
+ var point = requestStream.Current;
+ pointCount++;
+ if (RouteGuideUtil.Exists(CheckFeature(point)))
+ {
+ featureCount++;
+ }
+ if (previous != null)
+ {
+ distance += (int) CalcDistance(previous, point);
+ }
+ previous = point;
+ }
+
+ stopwatch.Stop();
+ return RouteSummary.CreateBuilder().SetPointCount(pointCount)
+ .SetFeatureCount(featureCount).SetDistance(distance)
+ .SetElapsedTime((int) (stopwatch.ElapsedMilliseconds / 1000)).Build();
+ }
+```
+
+#### Bidirectional streaming RPC
+
+Finally, let's look at our bidirectional streaming RPC `RouteChat`.
+
+```csharp
+ public async Task RouteChat(Grpc.Core.ServerCallContext context,
+ Grpc.Core.IAsyncStreamReader requestStream, Grpc.Core.IServerStreamWriter responseStream)
+ {
+ while (await requestStream.MoveNext())
+ {
+ var note = requestStream.Current;
+ List notes = GetOrCreateNotes(note.Location);
+
+ List prevNotes;
+ lock (notes)
+ {
+ prevNotes = new List(notes);
+ }
+
+ foreach (var prevNote in prevNotes)
+ {
+ await responseStream.WriteAsync(prevNote);
+ }
+
+ lock (notes)
+ {
+ notes.Add(note);
+ }
+ }
+ }
+```
+
+Here the method receives both `requestStream` and `responseStream` arguments. Reading the requests is done the same way as in the client-side streaming method `RecordRoute`. Writing the responses is done the same way as in the server-side streaming method `ListFeatures`.
+
+### Starting the server
+
+Once we've implemented all our methods, we also need to start up a gRPC server so that clients can actually use our service. The following snippet shows how we do this for our `RouteGuide` service:
+
+```csharp
+var features = RouteGuideUtil.ParseFeatures(RouteGuideUtil.DefaultFeaturesFile);
+GrpcEnvironment.Initialize();
+
+Server server = new Server();
+server.AddServiceDefinition(RouteGuide.BindService(new RouteGuideImpl(features)));
+int port = server.AddListeningPort("localhost", 50052);
+server.Start();
+
+Console.WriteLine("RouteGuide server listening on port " + port);
+Console.WriteLine("Press any key to stop the server...");
+Console.ReadKey();
+
+server.ShutdownAsync().Wait();
+GrpcEnvironment.Shutdown();
+```
+As you can see, we build and start our server using `Grpc.Core.Server` class. To do this, we:
+
+1. Create an instance of `Grpc.Core.Server`.
+1. Create an instance of our service implementation class `RouteGuideImpl`.
+3. Register our service implementation with the server using the `AddServiceDefinition` method and the generated method `RouteGuide.BindService`.
+2. Specify the address and port we want to use to listen for client requests using the `AddListeningPort` method.
+4. Call `Start` on the server instance to start an RPC server for our service.
+
+
+## Creating the client
+
+In this section, we'll look at creating a C# client for our `RouteGuide` service. You can see our complete example client code in [examples/csharp/route_guide/RouteGuideClient/Program.cs](examples/csharp/route_guide/RouteGuideClient/Program.cs).
+
+### Creating a stub
+
+To call service methods, we first need to create a *stub*.
+
+First, we need to create a gRPC client channel that will connect to gRPC server. Then, we use the `RouteGuide.NewStub` method of the `RouteGuide` class generated from our .proto.
+
+```csharp
+GrpcEnvironment.Initialize();
+
+using (Channel channel = new Channel("127.0.0.1:50052"))
+{
+ var client = RouteGuide.NewStub(channel);
+
+ // YOUR CODE GOES HERE
+}
+
+GrpcEnvironment.Shutdown();
+```
+
+### Calling service methods
+
+Now let's look at how we call our service methods. gRPC C# provides asynchronous versions of each of the supported method types. For convenience,
+gRPC C# also provides a synchronous method stub, but only for simple (single request/single response) RPCs.
+
+#### Simple RPC
+
+Calling the simple RPC `GetFeature` in a synchronous way is nearly as straightforward as calling a local method.
+
+```csharp
+Point request = Point.CreateBuilder().SetLatitude(409146138).SetLongitude(-746188906).Build();
+Feature feature = client.GetFeature(request);
+```
+
+As you can see, we create and populate a request protocol buffer object (in our case `Point`), and call the desired method on the client object, passing it the request. If the RPC finishes with success, the response protocol buffer (in our case `Feature`) will be returned. Otherwise, an exception of type `RpcException` will be thrown, indicating the status code of the problem.
+
+Alternatively, if you are in async context, you can call an asynchronous version of the method (and use `await` keyword to await the result):
+```csharp
+Point request = Point.CreateBuilder().SetLatitude(409146138).SetLongitude(-746188906).Build();
+Feature feature = await client.GetFeatureAsync(request);
+```
+
+#### Streaming RPCs
+
+Now let's look at our streaming methods. If you've already read [Creating the server](#server) some of this may look very familiar - streaming RPCs are implemented in a similar way on both sides. The difference with respect to simple call is that the client methods return an instance of a call object, that provides access to request/response streams and/or asynchronous result (depending on the streaming type you are using).
+
+Here's where we call the server-side streaming method `ListFeatures`, which has property `ReponseStream` of type `IAsyncEnumerator`
+
+```csharp
+using (var call = client.ListFeatures(request))
+{
+ while (await call.ResponseStream.MoveNext())
+ {
+ Feature feature = call.ResponseStream.Current;
+ Console.WriteLine("Received " + feature.ToString());
+ }
+}
+```
+
+The client-side streaming method `RecordRoute` is similar, except we use the property `RequestStream` to write the requests one by one using `WriteAsync` and eventually signal that no more request will be send using `CompleteAsync`. The method result can be obtained through the property
+`Result`.
+```csharp
+using (var call = client.RecordRoute())
+{
+ foreach (var point in points)
+ {
+ await call.RequestStream.WriteAsync(point);
+ }
+ await call.RequestStream.CompleteAsync();
+
+ RouteSummary summary = await call.Result;
+}
+```
+
+Finally, let's look at our bidirectional streaming RPC `RouteChat`. In this case, we write the request to `RequestStream` and receive the responses from `ResponseStream`. As you can see from the example, the streams are independent of each other.
+
+```csharp
+ using (var call = client.RouteChat())
+ {
+ var responseReaderTask = Task.Run(async () =>
+ {
+ while (await call.ResponseStream.MoveNext())
+ {
+ var note = call.ResponseStream.Current;
+ Console.WriteLine("Received " + note);
+ }
+ });
+
+ foreach (RouteNote request in requests)
+ {
+ await call.RequestStream.WriteAsync(request);
+ }
+ await call.RequestStream.CompleteAsync();
+ await responseReaderTask;
+}
+```
+
+## Try it out!
+
+Build client and server:
+
+Open the solution `examples/csharp/route_guide/RouteGuide.sln` from Visual Studio (or Monodevelop on Linux) and hit "Build".
+
+Run the server, which will listen on port 50052:
+```
+> cd RouteGuideServer/bin/Debug
+> RouteGuideServer.exe
+```
+
+Run the client (in a different terminal):
+```
+> cd RouteGuideClient/bin/Debug
+> RouteGuideClient.exe
+```
+
+You can also run the server and client directly from Visual Studio.
+
+On Linux or Mac, use `mono RouteGuideServer.exe` and `mono RouteGuideClient.exe` to run the server and client.
diff --git a/examples/csharp/route_guide/RouteGuide.sln b/examples/csharp/route_guide/RouteGuide.sln
new file mode 100644
index 00000000000..0b79fdc5ca7
--- /dev/null
+++ b/examples/csharp/route_guide/RouteGuide.sln
@@ -0,0 +1,39 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2013
+VisualStudioVersion = 12.0.31101.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RouteGuide", "RouteGuide\RouteGuide.csproj", "{49954D9C-5F17-4662-96B2-73BE833DD81A}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RouteGuideClient", "RouteGuideClient\RouteGuideClient.csproj", "{D47BE663-4DE3-4206-B7A8-EA3FA066DADC}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RouteGuideServer", "RouteGuideServer\RouteGuideServer.csproj", "{4B7C7794-BE24-4477-ACE7-18259EB73D27}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{2F6B184B-A576-4F21-AF2E-27E73D1FC96E}"
+ ProjectSection(SolutionItems) = preProject
+ .nuget\packages.config = .nuget\packages.config
+ EndProjectSection
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {49954D9C-5F17-4662-96B2-73BE833DD81A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {49954D9C-5F17-4662-96B2-73BE833DD81A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {49954D9C-5F17-4662-96B2-73BE833DD81A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {49954D9C-5F17-4662-96B2-73BE833DD81A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D47BE663-4DE3-4206-B7A8-EA3FA066DADC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D47BE663-4DE3-4206-B7A8-EA3FA066DADC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D47BE663-4DE3-4206-B7A8-EA3FA066DADC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D47BE663-4DE3-4206-B7A8-EA3FA066DADC}.Release|Any CPU.Build.0 = Release|Any CPU
+ {4B7C7794-BE24-4477-ACE7-18259EB73D27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {4B7C7794-BE24-4477-ACE7-18259EB73D27}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {4B7C7794-BE24-4477-ACE7-18259EB73D27}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {4B7C7794-BE24-4477-ACE7-18259EB73D27}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/examples/csharp/route_guide/RouteGuide/Properties/AssemblyInfo.cs b/examples/csharp/route_guide/RouteGuide/Properties/AssemblyInfo.cs
new file mode 100644
index 00000000000..9c3441e42f4
--- /dev/null
+++ b/examples/csharp/route_guide/RouteGuide/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("RouteGuide")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("RouteGuide")]
+[assembly: AssemblyCopyright("Copyright © 2015")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("ef6b85bc-ac27-46de-8714-a658236cc6fb")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/examples/csharp/route_guide/RouteGuide/RouteGuide.cs b/examples/csharp/route_guide/RouteGuide/RouteGuide.cs
new file mode 100644
index 00000000000..80508bcd3fd
--- /dev/null
+++ b/examples/csharp/route_guide/RouteGuide/RouteGuide.cs
@@ -0,0 +1,1873 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: route_guide.proto
+#pragma warning disable 1591, 0612, 3021
+#region Designer generated code
+
+using pb = global::Google.ProtocolBuffers;
+using pbc = global::Google.ProtocolBuffers.Collections;
+using pbd = global::Google.ProtocolBuffers.Descriptors;
+using scg = global::System.Collections.Generic;
+namespace examples {
+
+ namespace Proto {
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ public static partial class RouteGuide {
+
+ #region Extension registration
+ public static void RegisterAllExtensions(pb::ExtensionRegistry registry) {
+ }
+ #endregion
+ #region Static variables
+ internal static pbd::MessageDescriptor internal__static_examples_Point__Descriptor;
+ internal static pb::FieldAccess.FieldAccessorTable internal__static_examples_Point__FieldAccessorTable;
+ internal static pbd::MessageDescriptor internal__static_examples_Rectangle__Descriptor;
+ internal static pb::FieldAccess.FieldAccessorTable internal__static_examples_Rectangle__FieldAccessorTable;
+ internal static pbd::MessageDescriptor internal__static_examples_Feature__Descriptor;
+ internal static pb::FieldAccess.FieldAccessorTable internal__static_examples_Feature__FieldAccessorTable;
+ internal static pbd::MessageDescriptor internal__static_examples_RouteNote__Descriptor;
+ internal static pb::FieldAccess.FieldAccessorTable internal__static_examples_RouteNote__FieldAccessorTable;
+ internal static pbd::MessageDescriptor internal__static_examples_RouteSummary__Descriptor;
+ internal static pb::FieldAccess.FieldAccessorTable internal__static_examples_RouteSummary__FieldAccessorTable;
+ #endregion
+ #region Descriptor
+ public static pbd::FileDescriptor Descriptor {
+ get { return descriptor; }
+ }
+ private static pbd::FileDescriptor descriptor;
+
+ static RouteGuide() {
+ byte[] descriptorData = global::System.Convert.FromBase64String(
+ string.Concat(
+ "ChFyb3V0ZV9ndWlkZS5wcm90bxIIZXhhbXBsZXMiLAoFUG9pbnQSEAoIbGF0",
+ "aXR1ZGUYASABKAUSEQoJbG9uZ2l0dWRlGAIgASgFIkUKCVJlY3RhbmdsZRIb",
+ "CgJsbxgBIAEoCzIPLmV4YW1wbGVzLlBvaW50EhsKAmhpGAIgASgLMg8uZXhh",
+ "bXBsZXMuUG9pbnQiOgoHRmVhdHVyZRIMCgRuYW1lGAEgASgJEiEKCGxvY2F0",
+ "aW9uGAIgASgLMg8uZXhhbXBsZXMuUG9pbnQiPwoJUm91dGVOb3RlEiEKCGxv",
+ "Y2F0aW9uGAEgASgLMg8uZXhhbXBsZXMuUG9pbnQSDwoHbWVzc2FnZRgCIAEo",
+ "CSJiCgxSb3V0ZVN1bW1hcnkSEwoLcG9pbnRfY291bnQYASABKAUSFQoNZmVh",
+ "dHVyZV9jb3VudBgCIAEoBRIQCghkaXN0YW5jZRgDIAEoBRIUCgxlbGFwc2Vk",
+ "X3RpbWUYBCABKAUy9QEKClJvdXRlR3VpZGUSMgoKR2V0RmVhdHVyZRIPLmV4",
+ "YW1wbGVzLlBvaW50GhEuZXhhbXBsZXMuRmVhdHVyZSIAEjoKDExpc3RGZWF0",
+ "dXJlcxITLmV4YW1wbGVzLlJlY3RhbmdsZRoRLmV4YW1wbGVzLkZlYXR1cmUi",
+ "ADABEjoKC1JlY29yZFJvdXRlEg8uZXhhbXBsZXMuUG9pbnQaFi5leGFtcGxl",
+ "cy5Sb3V0ZVN1bW1hcnkiACgBEjsKCVJvdXRlQ2hhdBITLmV4YW1wbGVzLlJv",
+ "dXRlTm90ZRoTLmV4YW1wbGVzLlJvdXRlTm90ZSIAKAEwAQ=="));
+ pbd::FileDescriptor.InternalDescriptorAssigner assigner = delegate(pbd::FileDescriptor root) {
+ descriptor = root;
+ internal__static_examples_Point__Descriptor = Descriptor.MessageTypes[0];
+ internal__static_examples_Point__FieldAccessorTable =
+ new pb::FieldAccess.FieldAccessorTable(internal__static_examples_Point__Descriptor,
+ new string[] { "Latitude", "Longitude", });
+ internal__static_examples_Rectangle__Descriptor = Descriptor.MessageTypes[1];
+ internal__static_examples_Rectangle__FieldAccessorTable =
+ new pb::FieldAccess.FieldAccessorTable(internal__static_examples_Rectangle__Descriptor,
+ new string[] { "Lo", "Hi", });
+ internal__static_examples_Feature__Descriptor = Descriptor.MessageTypes[2];
+ internal__static_examples_Feature__FieldAccessorTable =
+ new pb::FieldAccess.FieldAccessorTable(internal__static_examples_Feature__Descriptor,
+ new string[] { "Name", "Location", });
+ internal__static_examples_RouteNote__Descriptor = Descriptor.MessageTypes[3];
+ internal__static_examples_RouteNote__FieldAccessorTable =
+ new pb::FieldAccess.FieldAccessorTable(internal__static_examples_RouteNote__Descriptor,
+ new string[] { "Location", "Message", });
+ internal__static_examples_RouteSummary__Descriptor = Descriptor.MessageTypes[4];
+ internal__static_examples_RouteSummary__FieldAccessorTable =
+ new pb::FieldAccess.FieldAccessorTable(internal__static_examples_RouteSummary__Descriptor,
+ new string[] { "PointCount", "FeatureCount", "Distance", "ElapsedTime", });
+ pb::ExtensionRegistry registry = pb::ExtensionRegistry.CreateInstance();
+ RegisterAllExtensions(registry);
+ return registry;
+ };
+ pbd::FileDescriptor.InternalBuildGeneratedFileFrom(descriptorData,
+ new pbd::FileDescriptor[] {
+ }, assigner);
+ }
+ #endregion
+
+ }
+ }
+ #region Messages
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ public sealed partial class Point : pb::GeneratedMessage {
+ private Point() { }
+ private static readonly Point defaultInstance = new Point().MakeReadOnly();
+ private static readonly string[] _pointFieldNames = new string[] { "latitude", "longitude" };
+ private static readonly uint[] _pointFieldTags = new uint[] { 8, 16 };
+ public static Point DefaultInstance {
+ get { return defaultInstance; }
+ }
+
+ public override Point DefaultInstanceForType {
+ get { return DefaultInstance; }
+ }
+
+ protected override Point ThisMessage {
+ get { return this; }
+ }
+
+ public static pbd::MessageDescriptor Descriptor {
+ get { return global::examples.Proto.RouteGuide.internal__static_examples_Point__Descriptor; }
+ }
+
+ protected override pb::FieldAccess.FieldAccessorTable InternalFieldAccessors {
+ get { return global::examples.Proto.RouteGuide.internal__static_examples_Point__FieldAccessorTable; }
+ }
+
+ public const int LatitudeFieldNumber = 1;
+ private bool hasLatitude;
+ private int latitude_;
+ public bool HasLatitude {
+ get { return hasLatitude; }
+ }
+ public int Latitude {
+ get { return latitude_; }
+ }
+
+ public const int LongitudeFieldNumber = 2;
+ private bool hasLongitude;
+ private int longitude_;
+ public bool HasLongitude {
+ get { return hasLongitude; }
+ }
+ public int Longitude {
+ get { return longitude_; }
+ }
+
+ public override bool IsInitialized {
+ get {
+ return true;
+ }
+ }
+
+ public override void WriteTo(pb::ICodedOutputStream output) {
+ CalcSerializedSize();
+ string[] field_names = _pointFieldNames;
+ if (hasLatitude) {
+ output.WriteInt32(1, field_names[0], Latitude);
+ }
+ if (hasLongitude) {
+ output.WriteInt32(2, field_names[1], Longitude);
+ }
+ UnknownFields.WriteTo(output);
+ }
+
+ private int memoizedSerializedSize = -1;
+ public override int SerializedSize {
+ get {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+ return CalcSerializedSize();
+ }
+ }
+
+ private int CalcSerializedSize() {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ if (hasLatitude) {
+ size += pb::CodedOutputStream.ComputeInt32Size(1, Latitude);
+ }
+ if (hasLongitude) {
+ size += pb::CodedOutputStream.ComputeInt32Size(2, Longitude);
+ }
+ size += UnknownFields.SerializedSize;
+ memoizedSerializedSize = size;
+ return size;
+ }
+ public static Point ParseFrom(pb::ByteString data) {
+ return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
+ }
+ public static Point ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
+ }
+ public static Point ParseFrom(byte[] data) {
+ return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
+ }
+ public static Point ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
+ }
+ public static Point ParseFrom(global::System.IO.Stream input) {
+ return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
+ }
+ public static Point ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
+ }
+ public static Point ParseDelimitedFrom(global::System.IO.Stream input) {
+ return CreateBuilder().MergeDelimitedFrom(input).BuildParsed();
+ }
+ public static Point ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
+ return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed();
+ }
+ public static Point ParseFrom(pb::ICodedInputStream input) {
+ return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
+ }
+ public static Point ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
+ }
+ private Point MakeReadOnly() {
+ return this;
+ }
+
+ public static Builder CreateBuilder() { return new Builder(); }
+ public override Builder ToBuilder() { return CreateBuilder(this); }
+ public override Builder CreateBuilderForType() { return new Builder(); }
+ public static Builder CreateBuilder(Point prototype) {
+ return new Builder(prototype);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ public sealed partial class Builder : pb::GeneratedBuilder {
+ protected override Builder ThisBuilder {
+ get { return this; }
+ }
+ public Builder() {
+ result = DefaultInstance;
+ resultIsReadOnly = true;
+ }
+ internal Builder(Point cloneFrom) {
+ result = cloneFrom;
+ resultIsReadOnly = true;
+ }
+
+ private bool resultIsReadOnly;
+ private Point result;
+
+ private Point PrepareBuilder() {
+ if (resultIsReadOnly) {
+ Point original = result;
+ result = new Point();
+ resultIsReadOnly = false;
+ MergeFrom(original);
+ }
+ return result;
+ }
+
+ public override bool IsInitialized {
+ get { return result.IsInitialized; }
+ }
+
+ protected override Point MessageBeingBuilt {
+ get { return PrepareBuilder(); }
+ }
+
+ public override Builder Clear() {
+ result = DefaultInstance;
+ resultIsReadOnly = true;
+ return this;
+ }
+
+ public override Builder Clone() {
+ if (resultIsReadOnly) {
+ return new Builder(result);
+ } else {
+ return new Builder().MergeFrom(result);
+ }
+ }
+
+ public override pbd::MessageDescriptor DescriptorForType {
+ get { return global::examples.Point.Descriptor; }
+ }
+
+ public override Point DefaultInstanceForType {
+ get { return global::examples.Point.DefaultInstance; }
+ }
+
+ public override Point BuildPartial() {
+ if (resultIsReadOnly) {
+ return result;
+ }
+ resultIsReadOnly = true;
+ return result.MakeReadOnly();
+ }
+
+ public override Builder MergeFrom(pb::IMessage other) {
+ if (other is Point) {
+ return MergeFrom((Point) other);
+ } else {
+ base.MergeFrom(other);
+ return this;
+ }
+ }
+
+ public override Builder MergeFrom(Point other) {
+ if (other == global::examples.Point.DefaultInstance) return this;
+ PrepareBuilder();
+ if (other.HasLatitude) {
+ Latitude = other.Latitude;
+ }
+ if (other.HasLongitude) {
+ Longitude = other.Longitude;
+ }
+ this.MergeUnknownFields(other.UnknownFields);
+ return this;
+ }
+
+ public override Builder MergeFrom(pb::ICodedInputStream input) {
+ return MergeFrom(input, pb::ExtensionRegistry.Empty);
+ }
+
+ public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
+ PrepareBuilder();
+ pb::UnknownFieldSet.Builder unknownFields = null;
+ uint tag;
+ string field_name;
+ while (input.ReadTag(out tag, out field_name)) {
+ if(tag == 0 && field_name != null) {
+ int field_ordinal = global::System.Array.BinarySearch(_pointFieldNames, field_name, global::System.StringComparer.Ordinal);
+ if(field_ordinal >= 0)
+ tag = _pointFieldTags[field_ordinal];
+ else {
+ if (unknownFields == null) {
+ unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
+ }
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
+ continue;
+ }
+ }
+ switch (tag) {
+ case 0: {
+ throw pb::InvalidProtocolBufferException.InvalidTag();
+ }
+ default: {
+ if (pb::WireFormat.IsEndGroupTag(tag)) {
+ if (unknownFields != null) {
+ this.UnknownFields = unknownFields.Build();
+ }
+ return this;
+ }
+ if (unknownFields == null) {
+ unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
+ }
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
+ break;
+ }
+ case 8: {
+ result.hasLatitude = input.ReadInt32(ref result.latitude_);
+ break;
+ }
+ case 16: {
+ result.hasLongitude = input.ReadInt32(ref result.longitude_);
+ break;
+ }
+ }
+ }
+
+ if (unknownFields != null) {
+ this.UnknownFields = unknownFields.Build();
+ }
+ return this;
+ }
+
+
+ public bool HasLatitude {
+ get { return result.hasLatitude; }
+ }
+ public int Latitude {
+ get { return result.Latitude; }
+ set { SetLatitude(value); }
+ }
+ public Builder SetLatitude(int value) {
+ PrepareBuilder();
+ result.hasLatitude = true;
+ result.latitude_ = value;
+ return this;
+ }
+ public Builder ClearLatitude() {
+ PrepareBuilder();
+ result.hasLatitude = false;
+ result.latitude_ = 0;
+ return this;
+ }
+
+ public bool HasLongitude {
+ get { return result.hasLongitude; }
+ }
+ public int Longitude {
+ get { return result.Longitude; }
+ set { SetLongitude(value); }
+ }
+ public Builder SetLongitude(int value) {
+ PrepareBuilder();
+ result.hasLongitude = true;
+ result.longitude_ = value;
+ return this;
+ }
+ public Builder ClearLongitude() {
+ PrepareBuilder();
+ result.hasLongitude = false;
+ result.longitude_ = 0;
+ return this;
+ }
+ }
+ static Point() {
+ object.ReferenceEquals(global::examples.Proto.RouteGuide.Descriptor, null);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ public sealed partial class Rectangle : pb::GeneratedMessage {
+ private Rectangle() { }
+ private static readonly Rectangle defaultInstance = new Rectangle().MakeReadOnly();
+ private static readonly string[] _rectangleFieldNames = new string[] { "hi", "lo" };
+ private static readonly uint[] _rectangleFieldTags = new uint[] { 18, 10 };
+ public static Rectangle DefaultInstance {
+ get { return defaultInstance; }
+ }
+
+ public override Rectangle DefaultInstanceForType {
+ get { return DefaultInstance; }
+ }
+
+ protected override Rectangle ThisMessage {
+ get { return this; }
+ }
+
+ public static pbd::MessageDescriptor Descriptor {
+ get { return global::examples.Proto.RouteGuide.internal__static_examples_Rectangle__Descriptor; }
+ }
+
+ protected override pb::FieldAccess.FieldAccessorTable InternalFieldAccessors {
+ get { return global::examples.Proto.RouteGuide.internal__static_examples_Rectangle__FieldAccessorTable; }
+ }
+
+ public const int LoFieldNumber = 1;
+ private bool hasLo;
+ private global::examples.Point lo_;
+ public bool HasLo {
+ get { return hasLo; }
+ }
+ public global::examples.Point Lo {
+ get { return lo_ ?? global::examples.Point.DefaultInstance; }
+ }
+
+ public const int HiFieldNumber = 2;
+ private bool hasHi;
+ private global::examples.Point hi_;
+ public bool HasHi {
+ get { return hasHi; }
+ }
+ public global::examples.Point Hi {
+ get { return hi_ ?? global::examples.Point.DefaultInstance; }
+ }
+
+ public override bool IsInitialized {
+ get {
+ return true;
+ }
+ }
+
+ public override void WriteTo(pb::ICodedOutputStream output) {
+ CalcSerializedSize();
+ string[] field_names = _rectangleFieldNames;
+ if (hasLo) {
+ output.WriteMessage(1, field_names[1], Lo);
+ }
+ if (hasHi) {
+ output.WriteMessage(2, field_names[0], Hi);
+ }
+ UnknownFields.WriteTo(output);
+ }
+
+ private int memoizedSerializedSize = -1;
+ public override int SerializedSize {
+ get {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+ return CalcSerializedSize();
+ }
+ }
+
+ private int CalcSerializedSize() {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ if (hasLo) {
+ size += pb::CodedOutputStream.ComputeMessageSize(1, Lo);
+ }
+ if (hasHi) {
+ size += pb::CodedOutputStream.ComputeMessageSize(2, Hi);
+ }
+ size += UnknownFields.SerializedSize;
+ memoizedSerializedSize = size;
+ return size;
+ }
+ public static Rectangle ParseFrom(pb::ByteString data) {
+ return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
+ }
+ public static Rectangle ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
+ }
+ public static Rectangle ParseFrom(byte[] data) {
+ return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
+ }
+ public static Rectangle ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
+ }
+ public static Rectangle ParseFrom(global::System.IO.Stream input) {
+ return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
+ }
+ public static Rectangle ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
+ }
+ public static Rectangle ParseDelimitedFrom(global::System.IO.Stream input) {
+ return CreateBuilder().MergeDelimitedFrom(input).BuildParsed();
+ }
+ public static Rectangle ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
+ return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed();
+ }
+ public static Rectangle ParseFrom(pb::ICodedInputStream input) {
+ return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
+ }
+ public static Rectangle ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
+ }
+ private Rectangle MakeReadOnly() {
+ return this;
+ }
+
+ public static Builder CreateBuilder() { return new Builder(); }
+ public override Builder ToBuilder() { return CreateBuilder(this); }
+ public override Builder CreateBuilderForType() { return new Builder(); }
+ public static Builder CreateBuilder(Rectangle prototype) {
+ return new Builder(prototype);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ public sealed partial class Builder : pb::GeneratedBuilder {
+ protected override Builder ThisBuilder {
+ get { return this; }
+ }
+ public Builder() {
+ result = DefaultInstance;
+ resultIsReadOnly = true;
+ }
+ internal Builder(Rectangle cloneFrom) {
+ result = cloneFrom;
+ resultIsReadOnly = true;
+ }
+
+ private bool resultIsReadOnly;
+ private Rectangle result;
+
+ private Rectangle PrepareBuilder() {
+ if (resultIsReadOnly) {
+ Rectangle original = result;
+ result = new Rectangle();
+ resultIsReadOnly = false;
+ MergeFrom(original);
+ }
+ return result;
+ }
+
+ public override bool IsInitialized {
+ get { return result.IsInitialized; }
+ }
+
+ protected override Rectangle MessageBeingBuilt {
+ get { return PrepareBuilder(); }
+ }
+
+ public override Builder Clear() {
+ result = DefaultInstance;
+ resultIsReadOnly = true;
+ return this;
+ }
+
+ public override Builder Clone() {
+ if (resultIsReadOnly) {
+ return new Builder(result);
+ } else {
+ return new Builder().MergeFrom(result);
+ }
+ }
+
+ public override pbd::MessageDescriptor DescriptorForType {
+ get { return global::examples.Rectangle.Descriptor; }
+ }
+
+ public override Rectangle DefaultInstanceForType {
+ get { return global::examples.Rectangle.DefaultInstance; }
+ }
+
+ public override Rectangle BuildPartial() {
+ if (resultIsReadOnly) {
+ return result;
+ }
+ resultIsReadOnly = true;
+ return result.MakeReadOnly();
+ }
+
+ public override Builder MergeFrom(pb::IMessage other) {
+ if (other is Rectangle) {
+ return MergeFrom((Rectangle) other);
+ } else {
+ base.MergeFrom(other);
+ return this;
+ }
+ }
+
+ public override Builder MergeFrom(Rectangle other) {
+ if (other == global::examples.Rectangle.DefaultInstance) return this;
+ PrepareBuilder();
+ if (other.HasLo) {
+ MergeLo(other.Lo);
+ }
+ if (other.HasHi) {
+ MergeHi(other.Hi);
+ }
+ this.MergeUnknownFields(other.UnknownFields);
+ return this;
+ }
+
+ public override Builder MergeFrom(pb::ICodedInputStream input) {
+ return MergeFrom(input, pb::ExtensionRegistry.Empty);
+ }
+
+ public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
+ PrepareBuilder();
+ pb::UnknownFieldSet.Builder unknownFields = null;
+ uint tag;
+ string field_name;
+ while (input.ReadTag(out tag, out field_name)) {
+ if(tag == 0 && field_name != null) {
+ int field_ordinal = global::System.Array.BinarySearch(_rectangleFieldNames, field_name, global::System.StringComparer.Ordinal);
+ if(field_ordinal >= 0)
+ tag = _rectangleFieldTags[field_ordinal];
+ else {
+ if (unknownFields == null) {
+ unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
+ }
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
+ continue;
+ }
+ }
+ switch (tag) {
+ case 0: {
+ throw pb::InvalidProtocolBufferException.InvalidTag();
+ }
+ default: {
+ if (pb::WireFormat.IsEndGroupTag(tag)) {
+ if (unknownFields != null) {
+ this.UnknownFields = unknownFields.Build();
+ }
+ return this;
+ }
+ if (unknownFields == null) {
+ unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
+ }
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
+ break;
+ }
+ case 10: {
+ global::examples.Point.Builder subBuilder = global::examples.Point.CreateBuilder();
+ if (result.hasLo) {
+ subBuilder.MergeFrom(Lo);
+ }
+ input.ReadMessage(subBuilder, extensionRegistry);
+ Lo = subBuilder.BuildPartial();
+ break;
+ }
+ case 18: {
+ global::examples.Point.Builder subBuilder = global::examples.Point.CreateBuilder();
+ if (result.hasHi) {
+ subBuilder.MergeFrom(Hi);
+ }
+ input.ReadMessage(subBuilder, extensionRegistry);
+ Hi = subBuilder.BuildPartial();
+ break;
+ }
+ }
+ }
+
+ if (unknownFields != null) {
+ this.UnknownFields = unknownFields.Build();
+ }
+ return this;
+ }
+
+
+ public bool HasLo {
+ get { return result.hasLo; }
+ }
+ public global::examples.Point Lo {
+ get { return result.Lo; }
+ set { SetLo(value); }
+ }
+ public Builder SetLo(global::examples.Point value) {
+ pb::ThrowHelper.ThrowIfNull(value, "value");
+ PrepareBuilder();
+ result.hasLo = true;
+ result.lo_ = value;
+ return this;
+ }
+ public Builder SetLo(global::examples.Point.Builder builderForValue) {
+ pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue");
+ PrepareBuilder();
+ result.hasLo = true;
+ result.lo_ = builderForValue.Build();
+ return this;
+ }
+ public Builder MergeLo(global::examples.Point value) {
+ pb::ThrowHelper.ThrowIfNull(value, "value");
+ PrepareBuilder();
+ if (result.hasLo &&
+ result.lo_ != global::examples.Point.DefaultInstance) {
+ result.lo_ = global::examples.Point.CreateBuilder(result.lo_).MergeFrom(value).BuildPartial();
+ } else {
+ result.lo_ = value;
+ }
+ result.hasLo = true;
+ return this;
+ }
+ public Builder ClearLo() {
+ PrepareBuilder();
+ result.hasLo = false;
+ result.lo_ = null;
+ return this;
+ }
+
+ public bool HasHi {
+ get { return result.hasHi; }
+ }
+ public global::examples.Point Hi {
+ get { return result.Hi; }
+ set { SetHi(value); }
+ }
+ public Builder SetHi(global::examples.Point value) {
+ pb::ThrowHelper.ThrowIfNull(value, "value");
+ PrepareBuilder();
+ result.hasHi = true;
+ result.hi_ = value;
+ return this;
+ }
+ public Builder SetHi(global::examples.Point.Builder builderForValue) {
+ pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue");
+ PrepareBuilder();
+ result.hasHi = true;
+ result.hi_ = builderForValue.Build();
+ return this;
+ }
+ public Builder MergeHi(global::examples.Point value) {
+ pb::ThrowHelper.ThrowIfNull(value, "value");
+ PrepareBuilder();
+ if (result.hasHi &&
+ result.hi_ != global::examples.Point.DefaultInstance) {
+ result.hi_ = global::examples.Point.CreateBuilder(result.hi_).MergeFrom(value).BuildPartial();
+ } else {
+ result.hi_ = value;
+ }
+ result.hasHi = true;
+ return this;
+ }
+ public Builder ClearHi() {
+ PrepareBuilder();
+ result.hasHi = false;
+ result.hi_ = null;
+ return this;
+ }
+ }
+ static Rectangle() {
+ object.ReferenceEquals(global::examples.Proto.RouteGuide.Descriptor, null);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ public sealed partial class Feature : pb::GeneratedMessage {
+ private Feature() { }
+ private static readonly Feature defaultInstance = new Feature().MakeReadOnly();
+ private static readonly string[] _featureFieldNames = new string[] { "location", "name" };
+ private static readonly uint[] _featureFieldTags = new uint[] { 18, 10 };
+ public static Feature DefaultInstance {
+ get { return defaultInstance; }
+ }
+
+ public override Feature DefaultInstanceForType {
+ get { return DefaultInstance; }
+ }
+
+ protected override Feature ThisMessage {
+ get { return this; }
+ }
+
+ public static pbd::MessageDescriptor Descriptor {
+ get { return global::examples.Proto.RouteGuide.internal__static_examples_Feature__Descriptor; }
+ }
+
+ protected override pb::FieldAccess.FieldAccessorTable InternalFieldAccessors {
+ get { return global::examples.Proto.RouteGuide.internal__static_examples_Feature__FieldAccessorTable; }
+ }
+
+ public const int NameFieldNumber = 1;
+ private bool hasName;
+ private string name_ = "";
+ public bool HasName {
+ get { return hasName; }
+ }
+ public string Name {
+ get { return name_; }
+ }
+
+ public const int LocationFieldNumber = 2;
+ private bool hasLocation;
+ private global::examples.Point location_;
+ public bool HasLocation {
+ get { return hasLocation; }
+ }
+ public global::examples.Point Location {
+ get { return location_ ?? global::examples.Point.DefaultInstance; }
+ }
+
+ public override bool IsInitialized {
+ get {
+ return true;
+ }
+ }
+
+ public override void WriteTo(pb::ICodedOutputStream output) {
+ CalcSerializedSize();
+ string[] field_names = _featureFieldNames;
+ if (hasName) {
+ output.WriteString(1, field_names[1], Name);
+ }
+ if (hasLocation) {
+ output.WriteMessage(2, field_names[0], Location);
+ }
+ UnknownFields.WriteTo(output);
+ }
+
+ private int memoizedSerializedSize = -1;
+ public override int SerializedSize {
+ get {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+ return CalcSerializedSize();
+ }
+ }
+
+ private int CalcSerializedSize() {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ if (hasName) {
+ size += pb::CodedOutputStream.ComputeStringSize(1, Name);
+ }
+ if (hasLocation) {
+ size += pb::CodedOutputStream.ComputeMessageSize(2, Location);
+ }
+ size += UnknownFields.SerializedSize;
+ memoizedSerializedSize = size;
+ return size;
+ }
+ public static Feature ParseFrom(pb::ByteString data) {
+ return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
+ }
+ public static Feature ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
+ }
+ public static Feature ParseFrom(byte[] data) {
+ return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
+ }
+ public static Feature ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
+ }
+ public static Feature ParseFrom(global::System.IO.Stream input) {
+ return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
+ }
+ public static Feature ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
+ }
+ public static Feature ParseDelimitedFrom(global::System.IO.Stream input) {
+ return CreateBuilder().MergeDelimitedFrom(input).BuildParsed();
+ }
+ public static Feature ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
+ return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed();
+ }
+ public static Feature ParseFrom(pb::ICodedInputStream input) {
+ return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
+ }
+ public static Feature ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
+ }
+ private Feature MakeReadOnly() {
+ return this;
+ }
+
+ public static Builder CreateBuilder() { return new Builder(); }
+ public override Builder ToBuilder() { return CreateBuilder(this); }
+ public override Builder CreateBuilderForType() { return new Builder(); }
+ public static Builder CreateBuilder(Feature prototype) {
+ return new Builder(prototype);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ public sealed partial class Builder : pb::GeneratedBuilder {
+ protected override Builder ThisBuilder {
+ get { return this; }
+ }
+ public Builder() {
+ result = DefaultInstance;
+ resultIsReadOnly = true;
+ }
+ internal Builder(Feature cloneFrom) {
+ result = cloneFrom;
+ resultIsReadOnly = true;
+ }
+
+ private bool resultIsReadOnly;
+ private Feature result;
+
+ private Feature PrepareBuilder() {
+ if (resultIsReadOnly) {
+ Feature original = result;
+ result = new Feature();
+ resultIsReadOnly = false;
+ MergeFrom(original);
+ }
+ return result;
+ }
+
+ public override bool IsInitialized {
+ get { return result.IsInitialized; }
+ }
+
+ protected override Feature MessageBeingBuilt {
+ get { return PrepareBuilder(); }
+ }
+
+ public override Builder Clear() {
+ result = DefaultInstance;
+ resultIsReadOnly = true;
+ return this;
+ }
+
+ public override Builder Clone() {
+ if (resultIsReadOnly) {
+ return new Builder(result);
+ } else {
+ return new Builder().MergeFrom(result);
+ }
+ }
+
+ public override pbd::MessageDescriptor DescriptorForType {
+ get { return global::examples.Feature.Descriptor; }
+ }
+
+ public override Feature DefaultInstanceForType {
+ get { return global::examples.Feature.DefaultInstance; }
+ }
+
+ public override Feature BuildPartial() {
+ if (resultIsReadOnly) {
+ return result;
+ }
+ resultIsReadOnly = true;
+ return result.MakeReadOnly();
+ }
+
+ public override Builder MergeFrom(pb::IMessage other) {
+ if (other is Feature) {
+ return MergeFrom((Feature) other);
+ } else {
+ base.MergeFrom(other);
+ return this;
+ }
+ }
+
+ public override Builder MergeFrom(Feature other) {
+ if (other == global::examples.Feature.DefaultInstance) return this;
+ PrepareBuilder();
+ if (other.HasName) {
+ Name = other.Name;
+ }
+ if (other.HasLocation) {
+ MergeLocation(other.Location);
+ }
+ this.MergeUnknownFields(other.UnknownFields);
+ return this;
+ }
+
+ public override Builder MergeFrom(pb::ICodedInputStream input) {
+ return MergeFrom(input, pb::ExtensionRegistry.Empty);
+ }
+
+ public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
+ PrepareBuilder();
+ pb::UnknownFieldSet.Builder unknownFields = null;
+ uint tag;
+ string field_name;
+ while (input.ReadTag(out tag, out field_name)) {
+ if(tag == 0 && field_name != null) {
+ int field_ordinal = global::System.Array.BinarySearch(_featureFieldNames, field_name, global::System.StringComparer.Ordinal);
+ if(field_ordinal >= 0)
+ tag = _featureFieldTags[field_ordinal];
+ else {
+ if (unknownFields == null) {
+ unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
+ }
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
+ continue;
+ }
+ }
+ switch (tag) {
+ case 0: {
+ throw pb::InvalidProtocolBufferException.InvalidTag();
+ }
+ default: {
+ if (pb::WireFormat.IsEndGroupTag(tag)) {
+ if (unknownFields != null) {
+ this.UnknownFields = unknownFields.Build();
+ }
+ return this;
+ }
+ if (unknownFields == null) {
+ unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
+ }
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
+ break;
+ }
+ case 10: {
+ result.hasName = input.ReadString(ref result.name_);
+ break;
+ }
+ case 18: {
+ global::examples.Point.Builder subBuilder = global::examples.Point.CreateBuilder();
+ if (result.hasLocation) {
+ subBuilder.MergeFrom(Location);
+ }
+ input.ReadMessage(subBuilder, extensionRegistry);
+ Location = subBuilder.BuildPartial();
+ break;
+ }
+ }
+ }
+
+ if (unknownFields != null) {
+ this.UnknownFields = unknownFields.Build();
+ }
+ return this;
+ }
+
+
+ public bool HasName {
+ get { return result.hasName; }
+ }
+ public string Name {
+ get { return result.Name; }
+ set { SetName(value); }
+ }
+ public Builder SetName(string value) {
+ pb::ThrowHelper.ThrowIfNull(value, "value");
+ PrepareBuilder();
+ result.hasName = true;
+ result.name_ = value;
+ return this;
+ }
+ public Builder ClearName() {
+ PrepareBuilder();
+ result.hasName = false;
+ result.name_ = "";
+ return this;
+ }
+
+ public bool HasLocation {
+ get { return result.hasLocation; }
+ }
+ public global::examples.Point Location {
+ get { return result.Location; }
+ set { SetLocation(value); }
+ }
+ public Builder SetLocation(global::examples.Point value) {
+ pb::ThrowHelper.ThrowIfNull(value, "value");
+ PrepareBuilder();
+ result.hasLocation = true;
+ result.location_ = value;
+ return this;
+ }
+ public Builder SetLocation(global::examples.Point.Builder builderForValue) {
+ pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue");
+ PrepareBuilder();
+ result.hasLocation = true;
+ result.location_ = builderForValue.Build();
+ return this;
+ }
+ public Builder MergeLocation(global::examples.Point value) {
+ pb::ThrowHelper.ThrowIfNull(value, "value");
+ PrepareBuilder();
+ if (result.hasLocation &&
+ result.location_ != global::examples.Point.DefaultInstance) {
+ result.location_ = global::examples.Point.CreateBuilder(result.location_).MergeFrom(value).BuildPartial();
+ } else {
+ result.location_ = value;
+ }
+ result.hasLocation = true;
+ return this;
+ }
+ public Builder ClearLocation() {
+ PrepareBuilder();
+ result.hasLocation = false;
+ result.location_ = null;
+ return this;
+ }
+ }
+ static Feature() {
+ object.ReferenceEquals(global::examples.Proto.RouteGuide.Descriptor, null);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ public sealed partial class RouteNote : pb::GeneratedMessage {
+ private RouteNote() { }
+ private static readonly RouteNote defaultInstance = new RouteNote().MakeReadOnly();
+ private static readonly string[] _routeNoteFieldNames = new string[] { "location", "message" };
+ private static readonly uint[] _routeNoteFieldTags = new uint[] { 10, 18 };
+ public static RouteNote DefaultInstance {
+ get { return defaultInstance; }
+ }
+
+ public override RouteNote DefaultInstanceForType {
+ get { return DefaultInstance; }
+ }
+
+ protected override RouteNote ThisMessage {
+ get { return this; }
+ }
+
+ public static pbd::MessageDescriptor Descriptor {
+ get { return global::examples.Proto.RouteGuide.internal__static_examples_RouteNote__Descriptor; }
+ }
+
+ protected override pb::FieldAccess.FieldAccessorTable InternalFieldAccessors {
+ get { return global::examples.Proto.RouteGuide.internal__static_examples_RouteNote__FieldAccessorTable; }
+ }
+
+ public const int LocationFieldNumber = 1;
+ private bool hasLocation;
+ private global::examples.Point location_;
+ public bool HasLocation {
+ get { return hasLocation; }
+ }
+ public global::examples.Point Location {
+ get { return location_ ?? global::examples.Point.DefaultInstance; }
+ }
+
+ public const int MessageFieldNumber = 2;
+ private bool hasMessage;
+ private string message_ = "";
+ public bool HasMessage {
+ get { return hasMessage; }
+ }
+ public string Message {
+ get { return message_; }
+ }
+
+ public override bool IsInitialized {
+ get {
+ return true;
+ }
+ }
+
+ public override void WriteTo(pb::ICodedOutputStream output) {
+ CalcSerializedSize();
+ string[] field_names = _routeNoteFieldNames;
+ if (hasLocation) {
+ output.WriteMessage(1, field_names[0], Location);
+ }
+ if (hasMessage) {
+ output.WriteString(2, field_names[1], Message);
+ }
+ UnknownFields.WriteTo(output);
+ }
+
+ private int memoizedSerializedSize = -1;
+ public override int SerializedSize {
+ get {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+ return CalcSerializedSize();
+ }
+ }
+
+ private int CalcSerializedSize() {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ if (hasLocation) {
+ size += pb::CodedOutputStream.ComputeMessageSize(1, Location);
+ }
+ if (hasMessage) {
+ size += pb::CodedOutputStream.ComputeStringSize(2, Message);
+ }
+ size += UnknownFields.SerializedSize;
+ memoizedSerializedSize = size;
+ return size;
+ }
+ public static RouteNote ParseFrom(pb::ByteString data) {
+ return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
+ }
+ public static RouteNote ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
+ }
+ public static RouteNote ParseFrom(byte[] data) {
+ return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
+ }
+ public static RouteNote ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
+ }
+ public static RouteNote ParseFrom(global::System.IO.Stream input) {
+ return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
+ }
+ public static RouteNote ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
+ }
+ public static RouteNote ParseDelimitedFrom(global::System.IO.Stream input) {
+ return CreateBuilder().MergeDelimitedFrom(input).BuildParsed();
+ }
+ public static RouteNote ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
+ return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed();
+ }
+ public static RouteNote ParseFrom(pb::ICodedInputStream input) {
+ return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
+ }
+ public static RouteNote ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
+ }
+ private RouteNote MakeReadOnly() {
+ return this;
+ }
+
+ public static Builder CreateBuilder() { return new Builder(); }
+ public override Builder ToBuilder() { return CreateBuilder(this); }
+ public override Builder CreateBuilderForType() { return new Builder(); }
+ public static Builder CreateBuilder(RouteNote prototype) {
+ return new Builder(prototype);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ public sealed partial class Builder : pb::GeneratedBuilder {
+ protected override Builder ThisBuilder {
+ get { return this; }
+ }
+ public Builder() {
+ result = DefaultInstance;
+ resultIsReadOnly = true;
+ }
+ internal Builder(RouteNote cloneFrom) {
+ result = cloneFrom;
+ resultIsReadOnly = true;
+ }
+
+ private bool resultIsReadOnly;
+ private RouteNote result;
+
+ private RouteNote PrepareBuilder() {
+ if (resultIsReadOnly) {
+ RouteNote original = result;
+ result = new RouteNote();
+ resultIsReadOnly = false;
+ MergeFrom(original);
+ }
+ return result;
+ }
+
+ public override bool IsInitialized {
+ get { return result.IsInitialized; }
+ }
+
+ protected override RouteNote MessageBeingBuilt {
+ get { return PrepareBuilder(); }
+ }
+
+ public override Builder Clear() {
+ result = DefaultInstance;
+ resultIsReadOnly = true;
+ return this;
+ }
+
+ public override Builder Clone() {
+ if (resultIsReadOnly) {
+ return new Builder(result);
+ } else {
+ return new Builder().MergeFrom(result);
+ }
+ }
+
+ public override pbd::MessageDescriptor DescriptorForType {
+ get { return global::examples.RouteNote.Descriptor; }
+ }
+
+ public override RouteNote DefaultInstanceForType {
+ get { return global::examples.RouteNote.DefaultInstance; }
+ }
+
+ public override RouteNote BuildPartial() {
+ if (resultIsReadOnly) {
+ return result;
+ }
+ resultIsReadOnly = true;
+ return result.MakeReadOnly();
+ }
+
+ public override Builder MergeFrom(pb::IMessage other) {
+ if (other is RouteNote) {
+ return MergeFrom((RouteNote) other);
+ } else {
+ base.MergeFrom(other);
+ return this;
+ }
+ }
+
+ public override Builder MergeFrom(RouteNote other) {
+ if (other == global::examples.RouteNote.DefaultInstance) return this;
+ PrepareBuilder();
+ if (other.HasLocation) {
+ MergeLocation(other.Location);
+ }
+ if (other.HasMessage) {
+ Message = other.Message;
+ }
+ this.MergeUnknownFields(other.UnknownFields);
+ return this;
+ }
+
+ public override Builder MergeFrom(pb::ICodedInputStream input) {
+ return MergeFrom(input, pb::ExtensionRegistry.Empty);
+ }
+
+ public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
+ PrepareBuilder();
+ pb::UnknownFieldSet.Builder unknownFields = null;
+ uint tag;
+ string field_name;
+ while (input.ReadTag(out tag, out field_name)) {
+ if(tag == 0 && field_name != null) {
+ int field_ordinal = global::System.Array.BinarySearch(_routeNoteFieldNames, field_name, global::System.StringComparer.Ordinal);
+ if(field_ordinal >= 0)
+ tag = _routeNoteFieldTags[field_ordinal];
+ else {
+ if (unknownFields == null) {
+ unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
+ }
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
+ continue;
+ }
+ }
+ switch (tag) {
+ case 0: {
+ throw pb::InvalidProtocolBufferException.InvalidTag();
+ }
+ default: {
+ if (pb::WireFormat.IsEndGroupTag(tag)) {
+ if (unknownFields != null) {
+ this.UnknownFields = unknownFields.Build();
+ }
+ return this;
+ }
+ if (unknownFields == null) {
+ unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
+ }
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
+ break;
+ }
+ case 10: {
+ global::examples.Point.Builder subBuilder = global::examples.Point.CreateBuilder();
+ if (result.hasLocation) {
+ subBuilder.MergeFrom(Location);
+ }
+ input.ReadMessage(subBuilder, extensionRegistry);
+ Location = subBuilder.BuildPartial();
+ break;
+ }
+ case 18: {
+ result.hasMessage = input.ReadString(ref result.message_);
+ break;
+ }
+ }
+ }
+
+ if (unknownFields != null) {
+ this.UnknownFields = unknownFields.Build();
+ }
+ return this;
+ }
+
+
+ public bool HasLocation {
+ get { return result.hasLocation; }
+ }
+ public global::examples.Point Location {
+ get { return result.Location; }
+ set { SetLocation(value); }
+ }
+ public Builder SetLocation(global::examples.Point value) {
+ pb::ThrowHelper.ThrowIfNull(value, "value");
+ PrepareBuilder();
+ result.hasLocation = true;
+ result.location_ = value;
+ return this;
+ }
+ public Builder SetLocation(global::examples.Point.Builder builderForValue) {
+ pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue");
+ PrepareBuilder();
+ result.hasLocation = true;
+ result.location_ = builderForValue.Build();
+ return this;
+ }
+ public Builder MergeLocation(global::examples.Point value) {
+ pb::ThrowHelper.ThrowIfNull(value, "value");
+ PrepareBuilder();
+ if (result.hasLocation &&
+ result.location_ != global::examples.Point.DefaultInstance) {
+ result.location_ = global::examples.Point.CreateBuilder(result.location_).MergeFrom(value).BuildPartial();
+ } else {
+ result.location_ = value;
+ }
+ result.hasLocation = true;
+ return this;
+ }
+ public Builder ClearLocation() {
+ PrepareBuilder();
+ result.hasLocation = false;
+ result.location_ = null;
+ return this;
+ }
+
+ public bool HasMessage {
+ get { return result.hasMessage; }
+ }
+ public string Message {
+ get { return result.Message; }
+ set { SetMessage(value); }
+ }
+ public Builder SetMessage(string value) {
+ pb::ThrowHelper.ThrowIfNull(value, "value");
+ PrepareBuilder();
+ result.hasMessage = true;
+ result.message_ = value;
+ return this;
+ }
+ public Builder ClearMessage() {
+ PrepareBuilder();
+ result.hasMessage = false;
+ result.message_ = "";
+ return this;
+ }
+ }
+ static RouteNote() {
+ object.ReferenceEquals(global::examples.Proto.RouteGuide.Descriptor, null);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ public sealed partial class RouteSummary : pb::GeneratedMessage {
+ private RouteSummary() { }
+ private static readonly RouteSummary defaultInstance = new RouteSummary().MakeReadOnly();
+ private static readonly string[] _routeSummaryFieldNames = new string[] { "distance", "elapsed_time", "feature_count", "point_count" };
+ private static readonly uint[] _routeSummaryFieldTags = new uint[] { 24, 32, 16, 8 };
+ public static RouteSummary DefaultInstance {
+ get { return defaultInstance; }
+ }
+
+ public override RouteSummary DefaultInstanceForType {
+ get { return DefaultInstance; }
+ }
+
+ protected override RouteSummary ThisMessage {
+ get { return this; }
+ }
+
+ public static pbd::MessageDescriptor Descriptor {
+ get { return global::examples.Proto.RouteGuide.internal__static_examples_RouteSummary__Descriptor; }
+ }
+
+ protected override pb::FieldAccess.FieldAccessorTable InternalFieldAccessors {
+ get { return global::examples.Proto.RouteGuide.internal__static_examples_RouteSummary__FieldAccessorTable; }
+ }
+
+ public const int PointCountFieldNumber = 1;
+ private bool hasPointCount;
+ private int pointCount_;
+ public bool HasPointCount {
+ get { return hasPointCount; }
+ }
+ public int PointCount {
+ get { return pointCount_; }
+ }
+
+ public const int FeatureCountFieldNumber = 2;
+ private bool hasFeatureCount;
+ private int featureCount_;
+ public bool HasFeatureCount {
+ get { return hasFeatureCount; }
+ }
+ public int FeatureCount {
+ get { return featureCount_; }
+ }
+
+ public const int DistanceFieldNumber = 3;
+ private bool hasDistance;
+ private int distance_;
+ public bool HasDistance {
+ get { return hasDistance; }
+ }
+ public int Distance {
+ get { return distance_; }
+ }
+
+ public const int ElapsedTimeFieldNumber = 4;
+ private bool hasElapsedTime;
+ private int elapsedTime_;
+ public bool HasElapsedTime {
+ get { return hasElapsedTime; }
+ }
+ public int ElapsedTime {
+ get { return elapsedTime_; }
+ }
+
+ public override bool IsInitialized {
+ get {
+ return true;
+ }
+ }
+
+ public override void WriteTo(pb::ICodedOutputStream output) {
+ CalcSerializedSize();
+ string[] field_names = _routeSummaryFieldNames;
+ if (hasPointCount) {
+ output.WriteInt32(1, field_names[3], PointCount);
+ }
+ if (hasFeatureCount) {
+ output.WriteInt32(2, field_names[2], FeatureCount);
+ }
+ if (hasDistance) {
+ output.WriteInt32(3, field_names[0], Distance);
+ }
+ if (hasElapsedTime) {
+ output.WriteInt32(4, field_names[1], ElapsedTime);
+ }
+ UnknownFields.WriteTo(output);
+ }
+
+ private int memoizedSerializedSize = -1;
+ public override int SerializedSize {
+ get {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+ return CalcSerializedSize();
+ }
+ }
+
+ private int CalcSerializedSize() {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ if (hasPointCount) {
+ size += pb::CodedOutputStream.ComputeInt32Size(1, PointCount);
+ }
+ if (hasFeatureCount) {
+ size += pb::CodedOutputStream.ComputeInt32Size(2, FeatureCount);
+ }
+ if (hasDistance) {
+ size += pb::CodedOutputStream.ComputeInt32Size(3, Distance);
+ }
+ if (hasElapsedTime) {
+ size += pb::CodedOutputStream.ComputeInt32Size(4, ElapsedTime);
+ }
+ size += UnknownFields.SerializedSize;
+ memoizedSerializedSize = size;
+ return size;
+ }
+ public static RouteSummary ParseFrom(pb::ByteString data) {
+ return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
+ }
+ public static RouteSummary ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
+ }
+ public static RouteSummary ParseFrom(byte[] data) {
+ return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
+ }
+ public static RouteSummary ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
+ }
+ public static RouteSummary ParseFrom(global::System.IO.Stream input) {
+ return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
+ }
+ public static RouteSummary ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
+ }
+ public static RouteSummary ParseDelimitedFrom(global::System.IO.Stream input) {
+ return CreateBuilder().MergeDelimitedFrom(input).BuildParsed();
+ }
+ public static RouteSummary ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
+ return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed();
+ }
+ public static RouteSummary ParseFrom(pb::ICodedInputStream input) {
+ return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
+ }
+ public static RouteSummary ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
+ }
+ private RouteSummary MakeReadOnly() {
+ return this;
+ }
+
+ public static Builder CreateBuilder() { return new Builder(); }
+ public override Builder ToBuilder() { return CreateBuilder(this); }
+ public override Builder CreateBuilderForType() { return new Builder(); }
+ public static Builder CreateBuilder(RouteSummary prototype) {
+ return new Builder(prototype);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ public sealed partial class Builder : pb::GeneratedBuilder {
+ protected override Builder ThisBuilder {
+ get { return this; }
+ }
+ public Builder() {
+ result = DefaultInstance;
+ resultIsReadOnly = true;
+ }
+ internal Builder(RouteSummary cloneFrom) {
+ result = cloneFrom;
+ resultIsReadOnly = true;
+ }
+
+ private bool resultIsReadOnly;
+ private RouteSummary result;
+
+ private RouteSummary PrepareBuilder() {
+ if (resultIsReadOnly) {
+ RouteSummary original = result;
+ result = new RouteSummary();
+ resultIsReadOnly = false;
+ MergeFrom(original);
+ }
+ return result;
+ }
+
+ public override bool IsInitialized {
+ get { return result.IsInitialized; }
+ }
+
+ protected override RouteSummary MessageBeingBuilt {
+ get { return PrepareBuilder(); }
+ }
+
+ public override Builder Clear() {
+ result = DefaultInstance;
+ resultIsReadOnly = true;
+ return this;
+ }
+
+ public override Builder Clone() {
+ if (resultIsReadOnly) {
+ return new Builder(result);
+ } else {
+ return new Builder().MergeFrom(result);
+ }
+ }
+
+ public override pbd::MessageDescriptor DescriptorForType {
+ get { return global::examples.RouteSummary.Descriptor; }
+ }
+
+ public override RouteSummary DefaultInstanceForType {
+ get { return global::examples.RouteSummary.DefaultInstance; }
+ }
+
+ public override RouteSummary BuildPartial() {
+ if (resultIsReadOnly) {
+ return result;
+ }
+ resultIsReadOnly = true;
+ return result.MakeReadOnly();
+ }
+
+ public override Builder MergeFrom(pb::IMessage other) {
+ if (other is RouteSummary) {
+ return MergeFrom((RouteSummary) other);
+ } else {
+ base.MergeFrom(other);
+ return this;
+ }
+ }
+
+ public override Builder MergeFrom(RouteSummary other) {
+ if (other == global::examples.RouteSummary.DefaultInstance) return this;
+ PrepareBuilder();
+ if (other.HasPointCount) {
+ PointCount = other.PointCount;
+ }
+ if (other.HasFeatureCount) {
+ FeatureCount = other.FeatureCount;
+ }
+ if (other.HasDistance) {
+ Distance = other.Distance;
+ }
+ if (other.HasElapsedTime) {
+ ElapsedTime = other.ElapsedTime;
+ }
+ this.MergeUnknownFields(other.UnknownFields);
+ return this;
+ }
+
+ public override Builder MergeFrom(pb::ICodedInputStream input) {
+ return MergeFrom(input, pb::ExtensionRegistry.Empty);
+ }
+
+ public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
+ PrepareBuilder();
+ pb::UnknownFieldSet.Builder unknownFields = null;
+ uint tag;
+ string field_name;
+ while (input.ReadTag(out tag, out field_name)) {
+ if(tag == 0 && field_name != null) {
+ int field_ordinal = global::System.Array.BinarySearch(_routeSummaryFieldNames, field_name, global::System.StringComparer.Ordinal);
+ if(field_ordinal >= 0)
+ tag = _routeSummaryFieldTags[field_ordinal];
+ else {
+ if (unknownFields == null) {
+ unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
+ }
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
+ continue;
+ }
+ }
+ switch (tag) {
+ case 0: {
+ throw pb::InvalidProtocolBufferException.InvalidTag();
+ }
+ default: {
+ if (pb::WireFormat.IsEndGroupTag(tag)) {
+ if (unknownFields != null) {
+ this.UnknownFields = unknownFields.Build();
+ }
+ return this;
+ }
+ if (unknownFields == null) {
+ unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
+ }
+ ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
+ break;
+ }
+ case 8: {
+ result.hasPointCount = input.ReadInt32(ref result.pointCount_);
+ break;
+ }
+ case 16: {
+ result.hasFeatureCount = input.ReadInt32(ref result.featureCount_);
+ break;
+ }
+ case 24: {
+ result.hasDistance = input.ReadInt32(ref result.distance_);
+ break;
+ }
+ case 32: {
+ result.hasElapsedTime = input.ReadInt32(ref result.elapsedTime_);
+ break;
+ }
+ }
+ }
+
+ if (unknownFields != null) {
+ this.UnknownFields = unknownFields.Build();
+ }
+ return this;
+ }
+
+
+ public bool HasPointCount {
+ get { return result.hasPointCount; }
+ }
+ public int PointCount {
+ get { return result.PointCount; }
+ set { SetPointCount(value); }
+ }
+ public Builder SetPointCount(int value) {
+ PrepareBuilder();
+ result.hasPointCount = true;
+ result.pointCount_ = value;
+ return this;
+ }
+ public Builder ClearPointCount() {
+ PrepareBuilder();
+ result.hasPointCount = false;
+ result.pointCount_ = 0;
+ return this;
+ }
+
+ public bool HasFeatureCount {
+ get { return result.hasFeatureCount; }
+ }
+ public int FeatureCount {
+ get { return result.FeatureCount; }
+ set { SetFeatureCount(value); }
+ }
+ public Builder SetFeatureCount(int value) {
+ PrepareBuilder();
+ result.hasFeatureCount = true;
+ result.featureCount_ = value;
+ return this;
+ }
+ public Builder ClearFeatureCount() {
+ PrepareBuilder();
+ result.hasFeatureCount = false;
+ result.featureCount_ = 0;
+ return this;
+ }
+
+ public bool HasDistance {
+ get { return result.hasDistance; }
+ }
+ public int Distance {
+ get { return result.Distance; }
+ set { SetDistance(value); }
+ }
+ public Builder SetDistance(int value) {
+ PrepareBuilder();
+ result.hasDistance = true;
+ result.distance_ = value;
+ return this;
+ }
+ public Builder ClearDistance() {
+ PrepareBuilder();
+ result.hasDistance = false;
+ result.distance_ = 0;
+ return this;
+ }
+
+ public bool HasElapsedTime {
+ get { return result.hasElapsedTime; }
+ }
+ public int ElapsedTime {
+ get { return result.ElapsedTime; }
+ set { SetElapsedTime(value); }
+ }
+ public Builder SetElapsedTime(int value) {
+ PrepareBuilder();
+ result.hasElapsedTime = true;
+ result.elapsedTime_ = value;
+ return this;
+ }
+ public Builder ClearElapsedTime() {
+ PrepareBuilder();
+ result.hasElapsedTime = false;
+ result.elapsedTime_ = 0;
+ return this;
+ }
+ }
+ static RouteSummary() {
+ object.ReferenceEquals(global::examples.Proto.RouteGuide.Descriptor, null);
+ }
+ }
+
+ #endregion
+
+}
+
+#endregion Designer generated code
diff --git a/examples/csharp/route_guide/RouteGuide/RouteGuide.csproj b/examples/csharp/route_guide/RouteGuide/RouteGuide.csproj
new file mode 100644
index 00000000000..8358974aac0
--- /dev/null
+++ b/examples/csharp/route_guide/RouteGuide/RouteGuide.csproj
@@ -0,0 +1,101 @@
+
+
+
+
+
+
+
+ Debug
+ AnyCPU
+ {49954D9C-5F17-4662-96B2-73BE833DD81A}
+ Library
+ Properties
+ RouteGuide
+ RouteGuide
+ v4.5
+ 512
+ 214cccda
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+ ..\packages\Google.ProtocolBuffers.2.4.1.555\lib\net40\Google.ProtocolBuffers.dll
+
+
+ ..\packages\Google.ProtocolBuffers.2.4.1.555\lib\net40\Google.ProtocolBuffers.Serialization.dll
+
+
+ False
+ ..\packages\Grpc.Core.0.6.0\lib\net45\Grpc.Core.dll
+
+
+ False
+ ..\packages\Newtonsoft.Json.7.0.1-beta2\lib\net45\Newtonsoft.Json.dll
+
+
+
+ False
+ ..\packages\System.Collections.Immutable.1.1.36\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll
+
+
+
+ ..\packages\Ix-Async.1.2.3\lib\net45\System.Interactive.Async.dll
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ PreserveNewest
+
+
+
+
+
+ This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/csharp/route_guide/RouteGuide/RouteGuideGrpc.cs b/examples/csharp/route_guide/RouteGuide/RouteGuideGrpc.cs
new file mode 100644
index 00000000000..c4b3900dca3
--- /dev/null
+++ b/examples/csharp/route_guide/RouteGuide/RouteGuideGrpc.cs
@@ -0,0 +1,123 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: route_guide.proto
+#region Designer generated code
+
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using Grpc.Core;
+
+namespace examples {
+ public static class RouteGuide
+ {
+ static readonly string __ServiceName = "examples.RouteGuide";
+
+ static readonly Marshaller __Marshaller_Point = Marshallers.Create((arg) => arg.ToByteArray(), global::examples.Point.ParseFrom);
+ static readonly Marshaller __Marshaller_Feature = Marshallers.Create((arg) => arg.ToByteArray(), global::examples.Feature.ParseFrom);
+ static readonly Marshaller __Marshaller_Rectangle = Marshallers.Create((arg) => arg.ToByteArray(), global::examples.Rectangle.ParseFrom);
+ static readonly Marshaller __Marshaller_RouteSummary = Marshallers.Create((arg) => arg.ToByteArray(), global::examples.RouteSummary.ParseFrom);
+ static readonly Marshaller __Marshaller_RouteNote = Marshallers.Create((arg) => arg.ToByteArray(), global::examples.RouteNote.ParseFrom);
+
+ static readonly Method __Method_GetFeature = new Method(
+ MethodType.Unary,
+ "GetFeature",
+ __Marshaller_Point,
+ __Marshaller_Feature);
+
+ static readonly Method __Method_ListFeatures = new Method(
+ MethodType.ServerStreaming,
+ "ListFeatures",
+ __Marshaller_Rectangle,
+ __Marshaller_Feature);
+
+ static readonly Method __Method_RecordRoute = new Method(
+ MethodType.ClientStreaming,
+ "RecordRoute",
+ __Marshaller_Point,
+ __Marshaller_RouteSummary);
+
+ static readonly Method __Method_RouteChat = new Method(
+ MethodType.DuplexStreaming,
+ "RouteChat",
+ __Marshaller_RouteNote,
+ __Marshaller_RouteNote);
+
+ // client-side stub interface
+ public interface IRouteGuideClient
+ {
+ global::examples.Feature GetFeature(global::examples.Point request, CancellationToken token = default(CancellationToken));
+ Task GetFeatureAsync(global::examples.Point request, CancellationToken token = default(CancellationToken));
+ AsyncServerStreamingCall ListFeatures(global::examples.Rectangle request, CancellationToken token = default(CancellationToken));
+ AsyncClientStreamingCall RecordRoute(CancellationToken token = default(CancellationToken));
+ AsyncDuplexStreamingCall RouteChat(CancellationToken token = default(CancellationToken));
+ }
+
+ // server-side interface
+ public interface IRouteGuide
+ {
+ Task GetFeature(ServerCallContext context, global::examples.Point request);
+ Task ListFeatures(ServerCallContext context, global::examples.Rectangle request, IServerStreamWriter responseStream);
+ Task RecordRoute(ServerCallContext context, IAsyncStreamReader requestStream);
+ Task RouteChat(ServerCallContext context, IAsyncStreamReader requestStream, IServerStreamWriter responseStream);
+ }
+
+ // client stub
+ public class RouteGuideClient : AbstractStub, IRouteGuideClient
+ {
+ public RouteGuideClient(Channel channel) : this(channel, StubConfiguration.Default)
+ {
+ }
+ public RouteGuideClient(Channel channel, StubConfiguration config) : base(channel, config)
+ {
+ }
+ public global::examples.Feature GetFeature(global::examples.Point request, CancellationToken token = default(CancellationToken))
+ {
+ var call = CreateCall(__ServiceName, __Method_GetFeature);
+ return Calls.BlockingUnaryCall(call, request, token);
+ }
+ public Task GetFeatureAsync(global::examples.Point request, CancellationToken token = default(CancellationToken))
+ {
+ var call = CreateCall(__ServiceName, __Method_GetFeature);
+ return Calls.AsyncUnaryCall(call, request, token);
+ }
+ public AsyncServerStreamingCall ListFeatures(global::examples.Rectangle request, CancellationToken token = default(CancellationToken))
+ {
+ var call = CreateCall(__ServiceName, __Method_ListFeatures);
+ return Calls.AsyncServerStreamingCall(call, request, token);
+ }
+ public AsyncClientStreamingCall RecordRoute(CancellationToken token = default(CancellationToken))
+ {
+ var call = CreateCall(__ServiceName, __Method_RecordRoute);
+ return Calls.AsyncClientStreamingCall(call, token);
+ }
+ public AsyncDuplexStreamingCall RouteChat(CancellationToken token = default(CancellationToken))
+ {
+ var call = CreateCall(__ServiceName, __Method_RouteChat);
+ return Calls.AsyncDuplexStreamingCall(call, token);
+ }
+ }
+
+ // creates service definition that can be registered with a server
+ public static ServerServiceDefinition BindService(IRouteGuide serviceImpl)
+ {
+ return ServerServiceDefinition.CreateBuilder(__ServiceName)
+ .AddMethod(__Method_GetFeature, serviceImpl.GetFeature)
+ .AddMethod(__Method_ListFeatures, serviceImpl.ListFeatures)
+ .AddMethod(__Method_RecordRoute, serviceImpl.RecordRoute)
+ .AddMethod(__Method_RouteChat, serviceImpl.RouteChat).Build();
+ }
+
+ // creates a new client stub
+ public static IRouteGuideClient NewStub(Channel channel)
+ {
+ return new RouteGuideClient(channel);
+ }
+
+ // creates a new client stub
+ public static IRouteGuideClient NewStub(Channel channel, StubConfiguration config)
+ {
+ return new RouteGuideClient(channel, config);
+ }
+ }
+}
+#endregion
diff --git a/examples/csharp/route_guide/RouteGuide/RouteGuideUtil.cs b/examples/csharp/route_guide/RouteGuide/RouteGuideUtil.cs
new file mode 100644
index 00000000000..6fb8b1e28ab
--- /dev/null
+++ b/examples/csharp/route_guide/RouteGuide/RouteGuideUtil.cs
@@ -0,0 +1,67 @@
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace examples
+{
+ public static class RouteGuideUtil
+ {
+ public const string DefaultFeaturesFile = "route_guide_db.json";
+
+ private const double CoordFactor = 1e7;
+
+ ///
+ /// Indicates whether the given feature exists (i.e. has a valid name).
+ ///
+ public static bool Exists(Feature feature)
+ {
+ return feature != null && (feature.Name.Length != 0);
+ }
+
+ public static double GetLatitude(Point point)
+ {
+ return point.Latitude / CoordFactor;
+ }
+
+ public static double GetLongitude(Point point)
+ {
+ return point.Longitude / CoordFactor;
+ }
+
+ ///
+ /// Parses features from a JSON file.
+ ///
+ public static List ParseFeatures(string filename)
+ {
+ var features = new List();
+ var jsonFeatures = JsonConvert.DeserializeObject>(File.ReadAllText(filename));
+
+
+ foreach(var jsonFeature in jsonFeatures)
+ {
+ features.Add(Feature.CreateBuilder().SetName(jsonFeature.name).SetLocation(
+ Point.CreateBuilder()
+ .SetLongitude(jsonFeature.location.longitude)
+ .SetLatitude(jsonFeature.location.latitude).Build()).Build());
+ }
+ return features;
+ }
+
+ private class JsonFeature
+ {
+ public string name;
+ public JsonLocation location;
+ }
+
+ private class JsonLocation
+ {
+ public int longitude;
+ public int latitude;
+ }
+ }
+}
diff --git a/examples/csharp/route_guide/RouteGuide/packages.config b/examples/csharp/route_guide/RouteGuide/packages.config
new file mode 100644
index 00000000000..79abe0aa655
--- /dev/null
+++ b/examples/csharp/route_guide/RouteGuide/packages.config
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/csharp/route_guide/RouteGuide/protos/route_guide.proto b/examples/csharp/route_guide/RouteGuide/protos/route_guide.proto
new file mode 100644
index 00000000000..f4110b5515b
--- /dev/null
+++ b/examples/csharp/route_guide/RouteGuide/protos/route_guide.proto
@@ -0,0 +1,123 @@
+// Copyright 2015, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// TODO(jtattermusch): as of now, C# protobufs don't officially support
+// proto3.
+syntax = "proto2";
+
+package examples;
+
+// Interface exported by the server.
+service RouteGuide {
+ // A simple RPC.
+ //
+ // Obtains the feature at a given position.
+ //
+ // A feature with an empty name is returned if there's no feature at the given
+ // position.
+ rpc GetFeature(Point) returns (Feature) {}
+
+ // A server-to-client streaming RPC.
+ //
+ // Obtains the Features available within the given Rectangle. Results are
+ // streamed rather than returned at once (e.g. in a response message with a
+ // repeated field), as the rectangle may cover a large area and contain a
+ // huge number of features.
+ rpc ListFeatures(Rectangle) returns (stream Feature) {}
+
+ // A client-to-server streaming RPC.
+ //
+ // Accepts a stream of Points on a route being traversed, returning a
+ // RouteSummary when traversal is completed.
+ rpc RecordRoute(stream Point) returns (RouteSummary) {}
+
+ // A Bidirectional streaming RPC.
+ //
+ // Accepts a stream of RouteNotes sent while a route is being traversed,
+ // while receiving other RouteNotes (e.g. from other users).
+ rpc RouteChat(stream RouteNote) returns (stream RouteNote) {}
+}
+
+// Points are represented as latitude-longitude pairs in the E7 representation
+// (degrees multiplied by 10**7 and rounded to the nearest integer).
+// Latitudes should be in the range +/- 90 degrees and longitude should be in
+// the range +/- 180 degrees (inclusive).
+message Point {
+ optional int32 latitude = 1;
+ optional int32 longitude = 2;
+}
+
+// A latitude-longitude rectangle, represented as two diagonally opposite
+// points "lo" and "hi".
+message Rectangle {
+ // One corner of the rectangle.
+ optional Point lo = 1;
+
+ // The other corner of the rectangle.
+ optional Point hi = 2;
+}
+
+// A feature names something at a given point.
+//
+// If a feature could not be named, the name is empty.
+message Feature {
+ // The name of the feature.
+ optional string name = 1;
+
+ // The point where the feature is detected.
+ optional Point location = 2;
+}
+
+// A RouteNote is a message sent while at a given point.
+message RouteNote {
+ // The location from which the message is sent.
+ optional Point location = 1;
+
+ // The message to be sent.
+ optional string message = 2;
+}
+
+// A RouteSummary is received in response to a RecordRoute rpc.
+//
+// It contains the number of individual points received, the number of
+// detected features, and the total distance covered as the cumulative sum of
+// the distance between each point.
+message RouteSummary {
+ // The number of points received.
+ optional int32 point_count = 1;
+
+ // The number of known features passed while traversing the route.
+ optional int32 feature_count = 2;
+
+ // The distance covered in metres.
+ optional int32 distance = 3;
+
+ // The duration of the traversal in seconds.
+ optional int32 elapsed_time = 4;
+}
diff --git a/examples/csharp/route_guide/RouteGuide/route_guide_db.json b/examples/csharp/route_guide/RouteGuide/route_guide_db.json
new file mode 100644
index 00000000000..209f0162593
--- /dev/null
+++ b/examples/csharp/route_guide/RouteGuide/route_guide_db.json
@@ -0,0 +1,601 @@
+[{
+ "location": {
+ "latitude": 407838351,
+ "longitude": -746143763
+ },
+ "name": "Patriots Path, Mendham, NJ 07945, USA"
+}, {
+ "location": {
+ "latitude": 408122808,
+ "longitude": -743999179
+ },
+ "name": "101 New Jersey 10, Whippany, NJ 07981, USA"
+}, {
+ "location": {
+ "latitude": 413628156,
+ "longitude": -749015468
+ },
+ "name": "U.S. 6, Shohola, PA 18458, USA"
+}, {
+ "location": {
+ "latitude": 419999544,
+ "longitude": -740371136
+ },
+ "name": "5 Conners Road, Kingston, NY 12401, USA"
+}, {
+ "location": {
+ "latitude": 414008389,
+ "longitude": -743951297
+ },
+ "name": "Mid Hudson Psychiatric Center, New Hampton, NY 10958, USA"
+}, {
+ "location": {
+ "latitude": 419611318,
+ "longitude": -746524769
+ },
+ "name": "287 Flugertown Road, Livingston Manor, NY 12758, USA"
+}, {
+ "location": {
+ "latitude": 406109563,
+ "longitude": -742186778
+ },
+ "name": "4001 Tremley Point Road, Linden, NJ 07036, USA"
+}, {
+ "location": {
+ "latitude": 416802456,
+ "longitude": -742370183
+ },
+ "name": "352 South Mountain Road, Wallkill, NY 12589, USA"
+}, {
+ "location": {
+ "latitude": 412950425,
+ "longitude": -741077389
+ },
+ "name": "Bailey Turn Road, Harriman, NY 10926, USA"
+}, {
+ "location": {
+ "latitude": 412144655,
+ "longitude": -743949739
+ },
+ "name": "193-199 Wawayanda Road, Hewitt, NJ 07421, USA"
+}, {
+ "location": {
+ "latitude": 415736605,
+ "longitude": -742847522
+ },
+ "name": "406-496 Ward Avenue, Pine Bush, NY 12566, USA"
+}, {
+ "location": {
+ "latitude": 413843930,
+ "longitude": -740501726
+ },
+ "name": "162 Merrill Road, Highland Mills, NY 10930, USA"
+}, {
+ "location": {
+ "latitude": 410873075,
+ "longitude": -744459023
+ },
+ "name": "Clinton Road, West Milford, NJ 07480, USA"
+}, {
+ "location": {
+ "latitude": 412346009,
+ "longitude": -744026814
+ },
+ "name": "16 Old Brook Lane, Warwick, NY 10990, USA"
+}, {
+ "location": {
+ "latitude": 402948455,
+ "longitude": -747903913
+ },
+ "name": "3 Drake Lane, Pennington, NJ 08534, USA"
+}, {
+ "location": {
+ "latitude": 406337092,
+ "longitude": -740122226
+ },
+ "name": "6324 8th Avenue, Brooklyn, NY 11220, USA"
+}, {
+ "location": {
+ "latitude": 406421967,
+ "longitude": -747727624
+ },
+ "name": "1 Merck Access Road, Whitehouse Station, NJ 08889, USA"
+}, {
+ "location": {
+ "latitude": 416318082,
+ "longitude": -749677716
+ },
+ "name": "78-98 Schalck Road, Narrowsburg, NY 12764, USA"
+}, {
+ "location": {
+ "latitude": 415301720,
+ "longitude": -748416257
+ },
+ "name": "282 Lakeview Drive Road, Highland Lake, NY 12743, USA"
+}, {
+ "location": {
+ "latitude": 402647019,
+ "longitude": -747071791
+ },
+ "name": "330 Evelyn Avenue, Hamilton Township, NJ 08619, USA"
+}, {
+ "location": {
+ "latitude": 412567807,
+ "longitude": -741058078
+ },
+ "name": "New York State Reference Route 987E, Southfields, NY 10975, USA"
+}, {
+ "location": {
+ "latitude": 416855156,
+ "longitude": -744420597
+ },
+ "name": "103-271 Tempaloni Road, Ellenville, NY 12428, USA"
+}, {
+ "location": {
+ "latitude": 404663628,
+ "longitude": -744820157
+ },
+ "name": "1300 Airport Road, North Brunswick Township, NJ 08902, USA"
+}, {
+ "location": {
+ "latitude": 407113723,
+ "longitude": -749746483
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 402133926,
+ "longitude": -743613249
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 400273442,
+ "longitude": -741220915
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 411236786,
+ "longitude": -744070769
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 411633782,
+ "longitude": -746784970
+ },
+ "name": "211-225 Plains Road, Augusta, NJ 07822, USA"
+}, {
+ "location": {
+ "latitude": 415830701,
+ "longitude": -742952812
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 413447164,
+ "longitude": -748712898
+ },
+ "name": "165 Pedersen Ridge Road, Milford, PA 18337, USA"
+}, {
+ "location": {
+ "latitude": 405047245,
+ "longitude": -749800722
+ },
+ "name": "100-122 Locktown Road, Frenchtown, NJ 08825, USA"
+}, {
+ "location": {
+ "latitude": 418858923,
+ "longitude": -746156790
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 417951888,
+ "longitude": -748484944
+ },
+ "name": "650-652 Willi Hill Road, Swan Lake, NY 12783, USA"
+}, {
+ "location": {
+ "latitude": 407033786,
+ "longitude": -743977337
+ },
+ "name": "26 East 3rd Street, New Providence, NJ 07974, USA"
+}, {
+ "location": {
+ "latitude": 417548014,
+ "longitude": -740075041
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 410395868,
+ "longitude": -744972325
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 404615353,
+ "longitude": -745129803
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 406589790,
+ "longitude": -743560121
+ },
+ "name": "611 Lawrence Avenue, Westfield, NJ 07090, USA"
+}, {
+ "location": {
+ "latitude": 414653148,
+ "longitude": -740477477
+ },
+ "name": "18 Lannis Avenue, New Windsor, NY 12553, USA"
+}, {
+ "location": {
+ "latitude": 405957808,
+ "longitude": -743255336
+ },
+ "name": "82-104 Amherst Avenue, Colonia, NJ 07067, USA"
+}, {
+ "location": {
+ "latitude": 411733589,
+ "longitude": -741648093
+ },
+ "name": "170 Seven Lakes Drive, Sloatsburg, NY 10974, USA"
+}, {
+ "location": {
+ "latitude": 412676291,
+ "longitude": -742606606
+ },
+ "name": "1270 Lakes Road, Monroe, NY 10950, USA"
+}, {
+ "location": {
+ "latitude": 409224445,
+ "longitude": -748286738
+ },
+ "name": "509-535 Alphano Road, Great Meadows, NJ 07838, USA"
+}, {
+ "location": {
+ "latitude": 406523420,
+ "longitude": -742135517
+ },
+ "name": "652 Garden Street, Elizabeth, NJ 07202, USA"
+}, {
+ "location": {
+ "latitude": 401827388,
+ "longitude": -740294537
+ },
+ "name": "349 Sea Spray Court, Neptune City, NJ 07753, USA"
+}, {
+ "location": {
+ "latitude": 410564152,
+ "longitude": -743685054
+ },
+ "name": "13-17 Stanley Street, West Milford, NJ 07480, USA"
+}, {
+ "location": {
+ "latitude": 408472324,
+ "longitude": -740726046
+ },
+ "name": "47 Industrial Avenue, Teterboro, NJ 07608, USA"
+}, {
+ "location": {
+ "latitude": 412452168,
+ "longitude": -740214052
+ },
+ "name": "5 White Oak Lane, Stony Point, NY 10980, USA"
+}, {
+ "location": {
+ "latitude": 409146138,
+ "longitude": -746188906
+ },
+ "name": "Berkshire Valley Management Area Trail, Jefferson, NJ, USA"
+}, {
+ "location": {
+ "latitude": 404701380,
+ "longitude": -744781745
+ },
+ "name": "1007 Jersey Avenue, New Brunswick, NJ 08901, USA"
+}, {
+ "location": {
+ "latitude": 409642566,
+ "longitude": -746017679
+ },
+ "name": "6 East Emerald Isle Drive, Lake Hopatcong, NJ 07849, USA"
+}, {
+ "location": {
+ "latitude": 408031728,
+ "longitude": -748645385
+ },
+ "name": "1358-1474 New Jersey 57, Port Murray, NJ 07865, USA"
+}, {
+ "location": {
+ "latitude": 413700272,
+ "longitude": -742135189
+ },
+ "name": "367 Prospect Road, Chester, NY 10918, USA"
+}, {
+ "location": {
+ "latitude": 404310607,
+ "longitude": -740282632
+ },
+ "name": "10 Simon Lake Drive, Atlantic Highlands, NJ 07716, USA"
+}, {
+ "location": {
+ "latitude": 409319800,
+ "longitude": -746201391
+ },
+ "name": "11 Ward Street, Mount Arlington, NJ 07856, USA"
+}, {
+ "location": {
+ "latitude": 406685311,
+ "longitude": -742108603
+ },
+ "name": "300-398 Jefferson Avenue, Elizabeth, NJ 07201, USA"
+}, {
+ "location": {
+ "latitude": 419018117,
+ "longitude": -749142781
+ },
+ "name": "43 Dreher Road, Roscoe, NY 12776, USA"
+}, {
+ "location": {
+ "latitude": 412856162,
+ "longitude": -745148837
+ },
+ "name": "Swan Street, Pine Island, NY 10969, USA"
+}, {
+ "location": {
+ "latitude": 416560744,
+ "longitude": -746721964
+ },
+ "name": "66 Pleasantview Avenue, Monticello, NY 12701, USA"
+}, {
+ "location": {
+ "latitude": 405314270,
+ "longitude": -749836354
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 414219548,
+ "longitude": -743327440
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 415534177,
+ "longitude": -742900616
+ },
+ "name": "565 Winding Hills Road, Montgomery, NY 12549, USA"
+}, {
+ "location": {
+ "latitude": 406898530,
+ "longitude": -749127080
+ },
+ "name": "231 Rocky Run Road, Glen Gardner, NJ 08826, USA"
+}, {
+ "location": {
+ "latitude": 407586880,
+ "longitude": -741670168
+ },
+ "name": "100 Mount Pleasant Avenue, Newark, NJ 07104, USA"
+}, {
+ "location": {
+ "latitude": 400106455,
+ "longitude": -742870190
+ },
+ "name": "517-521 Huntington Drive, Manchester Township, NJ 08759, USA"
+}, {
+ "location": {
+ "latitude": 400066188,
+ "longitude": -746793294
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 418803880,
+ "longitude": -744102673
+ },
+ "name": "40 Mountain Road, Napanoch, NY 12458, USA"
+}, {
+ "location": {
+ "latitude": 414204288,
+ "longitude": -747895140
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 414777405,
+ "longitude": -740615601
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 415464475,
+ "longitude": -747175374
+ },
+ "name": "48 North Road, Forestburgh, NY 12777, USA"
+}, {
+ "location": {
+ "latitude": 404062378,
+ "longitude": -746376177
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 405688272,
+ "longitude": -749285130
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 400342070,
+ "longitude": -748788996
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 401809022,
+ "longitude": -744157964
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 404226644,
+ "longitude": -740517141
+ },
+ "name": "9 Thompson Avenue, Leonardo, NJ 07737, USA"
+}, {
+ "location": {
+ "latitude": 410322033,
+ "longitude": -747871659
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 407100674,
+ "longitude": -747742727
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 418811433,
+ "longitude": -741718005
+ },
+ "name": "213 Bush Road, Stone Ridge, NY 12484, USA"
+}, {
+ "location": {
+ "latitude": 415034302,
+ "longitude": -743850945
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 411349992,
+ "longitude": -743694161
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 404839914,
+ "longitude": -744759616
+ },
+ "name": "1-17 Bergen Court, New Brunswick, NJ 08901, USA"
+}, {
+ "location": {
+ "latitude": 414638017,
+ "longitude": -745957854
+ },
+ "name": "35 Oakland Valley Road, Cuddebackville, NY 12729, USA"
+}, {
+ "location": {
+ "latitude": 412127800,
+ "longitude": -740173578
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 401263460,
+ "longitude": -747964303
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 412843391,
+ "longitude": -749086026
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 418512773,
+ "longitude": -743067823
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 404318328,
+ "longitude": -740835638
+ },
+ "name": "42-102 Main Street, Belford, NJ 07718, USA"
+}, {
+ "location": {
+ "latitude": 419020746,
+ "longitude": -741172328
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 404080723,
+ "longitude": -746119569
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 401012643,
+ "longitude": -744035134
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 404306372,
+ "longitude": -741079661
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 403966326,
+ "longitude": -748519297
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 405002031,
+ "longitude": -748407866
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 409532885,
+ "longitude": -742200683
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 416851321,
+ "longitude": -742674555
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 406411633,
+ "longitude": -741722051
+ },
+ "name": "3387 Richmond Terrace, Staten Island, NY 10303, USA"
+}, {
+ "location": {
+ "latitude": 413069058,
+ "longitude": -744597778
+ },
+ "name": "261 Van Sickle Road, Goshen, NY 10924, USA"
+}, {
+ "location": {
+ "latitude": 418465462,
+ "longitude": -746859398
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 411733222,
+ "longitude": -744228360
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 410248224,
+ "longitude": -747127767
+ },
+ "name": "3 Hasta Way, Newton, NJ 07860, USA"
+}]
\ No newline at end of file
diff --git a/examples/csharp/route_guide/RouteGuideClient/App.config b/examples/csharp/route_guide/RouteGuideClient/App.config
new file mode 100644
index 00000000000..8e15646352e
--- /dev/null
+++ b/examples/csharp/route_guide/RouteGuideClient/App.config
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/csharp/route_guide/RouteGuideClient/Program.cs b/examples/csharp/route_guide/RouteGuideClient/Program.cs
new file mode 100644
index 00000000000..0352c780201
--- /dev/null
+++ b/examples/csharp/route_guide/RouteGuideClient/Program.cs
@@ -0,0 +1,223 @@
+using Grpc.Core;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace examples
+{
+ class Program
+ {
+ ///
+ /// Sample client code that makes gRPC calls to the server.
+ ///
+ public class RouteGuideClient
+ {
+ readonly RouteGuide.IRouteGuideClient client;
+
+ public RouteGuideClient(RouteGuide.IRouteGuideClient client)
+ {
+ this.client = client;
+ }
+
+ ///
+ /// Blocking unary call example. Calls GetFeature and prints the response.
+ ///
+ public void GetFeature(int lat, int lon)
+ {
+ try
+ {
+ Log("*** GetFeature: lat={0} lon={1}", lat, lon);
+
+ Point request = Point.CreateBuilder().SetLatitude(lat).SetLongitude(lon).Build();
+
+ Feature feature = client.GetFeature(request);
+ if (RouteGuideUtil.Exists(feature))
+ {
+ Log("Found feature called \"{0}\" at {1}, {2}",
+ feature.Name,
+ RouteGuideUtil.GetLatitude(feature.Location),
+ RouteGuideUtil.GetLongitude(feature.Location));
+ }
+ else
+ {
+ Log("Found no feature at {0}, {1}",
+ RouteGuideUtil.GetLatitude(feature.Location),
+ RouteGuideUtil.GetLongitude(feature.Location));
+ }
+ }
+ catch (RpcException e)
+ {
+ Log("RPC failed " + e);
+ throw e;
+ }
+ }
+
+
+ ///
+ /// Server-streaming example. Calls listFeatures with a rectangle of interest. Prints each response feature as it arrives.
+ ///
+ public async Task ListFeatures(int lowLat, int lowLon, int hiLat, int hiLon)
+ {
+ try
+ {
+ Log("*** ListFeatures: lowLat={0} lowLon={1} hiLat={2} hiLon={3}", lowLat, lowLon, hiLat,
+ hiLon);
+
+ Rectangle request =
+ Rectangle.CreateBuilder()
+ .SetLo(Point.CreateBuilder().SetLatitude(lowLat).SetLongitude(lowLon).Build())
+ .SetHi(Point.CreateBuilder().SetLatitude(hiLat).SetLongitude(hiLon).Build()).Build();
+
+ using (var call = client.ListFeatures(request))
+ {
+ StringBuilder responseLog = new StringBuilder("Result: ");
+
+ while (await call.ResponseStream.MoveNext())
+ {
+ Feature feature = call.ResponseStream.Current;
+ responseLog.Append(feature.ToString());
+ }
+ Log(responseLog.ToString());
+ }
+ }
+ catch (RpcException e)
+ {
+ Log("RPC failed " + e);
+ throw e;
+ }
+ }
+
+ ///
+ /// Client-streaming example. Sends numPoints randomly chosen points from features
+ /// with a variable delay in between. Prints the statistics when they are sent from the server.
+ ///
+ public async Task RecordRoute(List features, int numPoints)
+ {
+ try
+ {
+ Log("*** RecordRoute");
+ using (var call = client.RecordRoute())
+ {
+ // Send numPoints points randomly selected from the features list.
+ StringBuilder numMsg = new StringBuilder();
+ Random rand = new Random();
+ for (int i = 0; i < numPoints; ++i)
+ {
+ int index = rand.Next(features.Count);
+ Point point = features[index].Location;
+ Log("Visiting point {0}, {1}", RouteGuideUtil.GetLatitude(point),
+ RouteGuideUtil.GetLongitude(point));
+
+ await call.RequestStream.WriteAsync(point);
+
+ // A bit of delay before sending the next one.
+ await Task.Delay(rand.Next(1000) + 500);
+ }
+ await call.RequestStream.CompleteAsync();
+
+ RouteSummary summary = await call.Result;
+ Log("Finished trip with {0} points. Passed {1} features. "
+ + "Travelled {2} meters. It took {3} seconds.", summary.PointCount,
+ summary.FeatureCount, summary.Distance, summary.ElapsedTime);
+
+ Log("Finished RecordRoute");
+ }
+ }
+ catch (RpcException e)
+ {
+ Log("RPC failed", e);
+ throw e;
+ }
+ }
+
+ ///
+ /// Bi-directional streaming example. Send some chat messages, and print any
+ /// chat messages that are sent from the server.
+ ///
+ public async Task RouteChat()
+ {
+ try
+ {
+ Log("*** RouteChat");
+ var requests =
+ new List { NewNote("First message", 0, 0), NewNote("Second message", 0, 1), NewNote("Third message", 1, 0), NewNote("Fourth message", 1, 1) };
+
+ using (var call = client.RouteChat())
+ {
+ var responseReaderTask = Task.Run(async () =>
+ {
+ while (await call.ResponseStream.MoveNext())
+ {
+ var note = call.ResponseStream.Current;
+ Log("Got message \"{0}\" at {1}, {2}", note.Message,
+ note.Location.Latitude, note.Location.Longitude);
+ }
+ });
+
+ foreach (RouteNote request in requests)
+ {
+ Log("Sending message \"{0}\" at {1}, {2}", request.Message,
+ request.Location.Latitude, request.Location.Longitude);
+
+ await call.RequestStream.WriteAsync(request);
+ }
+ await call.RequestStream.CompleteAsync();
+ await responseReaderTask;
+
+ Log("Finished RouteChat");
+ }
+ }
+ catch (RpcException e)
+ {
+ Log("RPC failed", e);
+ throw e;
+ }
+ }
+
+ private void Log(string s, params object[] args)
+ {
+ Console.WriteLine(string.Format(s, args));
+ }
+
+ private void Log(string s)
+ {
+ Console.WriteLine(s);
+ }
+
+ private RouteNote NewNote(string message, int lat, int lon)
+ {
+ return RouteNote.CreateBuilder().SetMessage(message).SetLocation(
+ Point.CreateBuilder().SetLatitude(lat).SetLongitude(lat).Build()).Build();
+ }
+ }
+
+ static void Main(string[] args)
+ {
+ GrpcEnvironment.Initialize();
+
+ using (Channel channel = new Channel("127.0.0.1:50052"))
+ {
+ var client = new RouteGuideClient(RouteGuide.NewStub(channel));
+
+ // Looking for a valid feature
+ client.GetFeature(409146138, -746188906);
+
+ // Feature missing.
+ client.GetFeature(0, 0);
+
+ // Looking for features between 40, -75 and 42, -73.
+ client.ListFeatures(400000000, -750000000, 420000000, -730000000).Wait();
+
+ // Record a few randomly selected points from the features file.
+ client.RecordRoute(RouteGuideUtil.ParseFeatures(RouteGuideUtil.DefaultFeaturesFile), 10).Wait();
+
+ // Send and receive some notes.
+ client.RouteChat().Wait();
+ }
+
+ GrpcEnvironment.Shutdown();
+ }
+ }
+}
diff --git a/examples/csharp/route_guide/RouteGuideClient/Properties/AssemblyInfo.cs b/examples/csharp/route_guide/RouteGuideClient/Properties/AssemblyInfo.cs
new file mode 100644
index 00000000000..a17e164a788
--- /dev/null
+++ b/examples/csharp/route_guide/RouteGuideClient/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("RouteGuideClient")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("RouteGuideClient")]
+[assembly: AssemblyCopyright("Copyright © 2015")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("914644eb-47cd-4a37-9fba-5e62dd432333")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/examples/csharp/route_guide/RouteGuideClient/RouteGuideClient.csproj b/examples/csharp/route_guide/RouteGuideClient/RouteGuideClient.csproj
new file mode 100644
index 00000000000..78034a9145e
--- /dev/null
+++ b/examples/csharp/route_guide/RouteGuideClient/RouteGuideClient.csproj
@@ -0,0 +1,100 @@
+
+
+
+
+
+
+
+ Debug
+ AnyCPU
+ {D47BE663-4DE3-4206-B7A8-EA3FA066DADC}
+ Exe
+ Properties
+ RouteGuideClient
+ RouteGuideClient
+ v4.5
+ 512
+ 794416d0
+
+
+ AnyCPU
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ AnyCPU
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+ ..\packages\Google.ProtocolBuffers.2.4.1.555\lib\net40\Google.ProtocolBuffers.dll
+
+
+ ..\packages\Google.ProtocolBuffers.2.4.1.555\lib\net40\Google.ProtocolBuffers.Serialization.dll
+
+
+ False
+ ..\packages\Grpc.Core.0.6.0\lib\net45\Grpc.Core.dll
+
+
+
+ False
+ ..\packages\System.Collections.Immutable.1.1.36\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll
+
+
+
+ ..\packages\Ix-Async.1.2.3\lib\net45\System.Interactive.Async.dll
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {49954d9c-5f17-4662-96b2-73be833dd81a}
+ RouteGuide
+
+
+
+
+
+ This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/csharp/route_guide/RouteGuideClient/packages.config b/examples/csharp/route_guide/RouteGuideClient/packages.config
new file mode 100644
index 00000000000..5922553bc37
--- /dev/null
+++ b/examples/csharp/route_guide/RouteGuideClient/packages.config
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/csharp/route_guide/RouteGuideServer/App.config b/examples/csharp/route_guide/RouteGuideServer/App.config
new file mode 100644
index 00000000000..8e15646352e
--- /dev/null
+++ b/examples/csharp/route_guide/RouteGuideServer/App.config
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/csharp/route_guide/RouteGuideServer/Program.cs b/examples/csharp/route_guide/RouteGuideServer/Program.cs
new file mode 100644
index 00000000000..e00b4d67238
--- /dev/null
+++ b/examples/csharp/route_guide/RouteGuideServer/Program.cs
@@ -0,0 +1,30 @@
+using Grpc.Core;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace examples
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ var features = RouteGuideUtil.ParseFeatures(RouteGuideUtil.DefaultFeaturesFile);
+ GrpcEnvironment.Initialize();
+
+ Server server = new Server();
+ server.AddServiceDefinition(RouteGuide.BindService(new RouteGuideImpl(features)));
+ int port = server.AddListeningPort("localhost", 50052);
+ server.Start();
+
+ Console.WriteLine("RouteGuide server listening on port " + port);
+ Console.WriteLine("Press any key to stop the server...");
+ Console.ReadKey();
+
+ server.ShutdownAsync().Wait();
+ GrpcEnvironment.Shutdown();
+ }
+ }
+}
diff --git a/examples/csharp/route_guide/RouteGuideServer/Properties/AssemblyInfo.cs b/examples/csharp/route_guide/RouteGuideServer/Properties/AssemblyInfo.cs
new file mode 100644
index 00000000000..a161b1d6027
--- /dev/null
+++ b/examples/csharp/route_guide/RouteGuideServer/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("RouteGuideServer")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("RouteGuideServer")]
+[assembly: AssemblyCopyright("Copyright © 2015")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("908bdeef-05cc-42bf-9498-c4c573df8925")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/examples/csharp/route_guide/RouteGuideServer/RouteGuideImpl.cs b/examples/csharp/route_guide/RouteGuideServer/RouteGuideImpl.cs
new file mode 100644
index 00000000000..0bdf386fc33
--- /dev/null
+++ b/examples/csharp/route_guide/RouteGuideServer/RouteGuideImpl.cs
@@ -0,0 +1,184 @@
+using System;
+using System.Collections.Concurrent;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace examples
+{
+ ///
+ /// Example implementation of RouteGuide server.
+ ///
+ public class RouteGuideImpl : RouteGuide.IRouteGuide
+ {
+ readonly List features;
+ private readonly ConcurrentDictionary> routeNotes =
+ new ConcurrentDictionary>();
+
+ public RouteGuideImpl(List features)
+ {
+ this.features = features;
+ }
+
+ ///
+ /// Gets the feature at the requested point. If no feature at that location
+ /// exists, an unnammed feature is returned at the provided location.
+ ///
+ public Task GetFeature(Grpc.Core.ServerCallContext context, Point request)
+ {
+ return Task.FromResult(CheckFeature(request));
+ }
+
+ ///
+ /// Gets all features contained within the given bounding rectangle.
+ ///
+ public async Task ListFeatures(Grpc.Core.ServerCallContext context, Rectangle request, Grpc.Core.IServerStreamWriter responseStream)
+ {
+ int left = Math.Min(request.Lo.Longitude, request.Hi.Longitude);
+ int right = Math.Max(request.Lo.Longitude, request.Hi.Longitude);
+ int top = Math.Max(request.Lo.Latitude, request.Hi.Latitude);
+ int bottom = Math.Min(request.Lo.Latitude, request.Hi.Latitude);
+
+ foreach (var feature in features)
+ {
+ if (!RouteGuideUtil.Exists(feature))
+ {
+ continue;
+ }
+
+ int lat = feature.Location.Latitude;
+ int lon = feature.Location.Longitude;
+ if (lon >= left && lon <= right && lat >= bottom && lat <= top)
+ {
+ await responseStream.WriteAsync(feature);
+ }
+ }
+ }
+
+ ///
+ /// Gets a stream of points, and responds with statistics about the "trip": number of points,
+ /// number of known features visited, total distance traveled, and total time spent.
+ ///
+ public async Task RecordRoute(Grpc.Core.ServerCallContext context, Grpc.Core.IAsyncStreamReader requestStream)
+ {
+ int pointCount = 0;
+ int featureCount = 0;
+ int distance = 0;
+ Point previous = null;
+ var stopwatch = new Stopwatch();
+ stopwatch.Start();
+
+ while (await requestStream.MoveNext())
+ {
+ var point = requestStream.Current;
+ pointCount++;
+ if (RouteGuideUtil.Exists(CheckFeature(point)))
+ {
+ featureCount++;
+ }
+ if (previous != null)
+ {
+ distance += (int) CalcDistance(previous, point);
+ }
+ previous = point;
+ }
+
+ stopwatch.Stop();
+ return RouteSummary.CreateBuilder().SetPointCount(pointCount)
+ .SetFeatureCount(featureCount).SetDistance(distance)
+ .SetElapsedTime((int) (stopwatch.ElapsedMilliseconds / 1000)).Build();
+ }
+
+ ///
+ /// Receives a stream of message/location pairs, and responds with a stream of all previous
+ /// messages at each of those locations.
+ ///
+ public async Task RouteChat(Grpc.Core.ServerCallContext context, Grpc.Core.IAsyncStreamReader requestStream, Grpc.Core.IServerStreamWriter responseStream)
+ {
+ while (await requestStream.MoveNext())
+ {
+ var note = requestStream.Current;
+ List notes = GetOrCreateNotes(note.Location);
+
+ List prevNotes;
+ lock (notes)
+ {
+ prevNotes = new List(notes);
+ }
+
+ foreach (var prevNote in prevNotes)
+ {
+ await responseStream.WriteAsync(prevNote);
+ }
+
+ lock (notes)
+ {
+ notes.Add(note);
+ }
+ }
+ }
+
+
+ ///
+ /// Get the notes list for the given location. If missing, create it.
+ ///
+ private List GetOrCreateNotes(Point location)
+ {
+ List notes = new List();
+ routeNotes.TryAdd(location, notes);
+ return routeNotes[location];
+ }
+
+ ///
+ /// Gets the feature at the given point.
+ ///
+ /// the location to check
+ /// The feature object at the point Note that an empty name indicates no feature.
+ private Feature CheckFeature(Point location)
+ {
+ foreach (var feature in features)
+ {
+ if (feature.Location.Latitude == location.Latitude
+ && feature.Location.Longitude == location.Longitude)
+ {
+ return feature;
+ }
+ }
+
+ // No feature was found, return an unnamed feature.
+ return Feature.CreateBuilder().SetName("").SetLocation(location).Build();
+ }
+
+ ///
+ /// Calculate the distance between two points using the "haversine" formula.
+ /// This code was taken from http://www.movable-type.co.uk/scripts/latlong.html.
+ ///
+ /// the starting point
+ /// the end point
+ /// the distance between the points in meters
+ private static double CalcDistance(Point start, Point end)
+ {
+ double lat1 = RouteGuideUtil.GetLatitude(start);
+ double lat2 = RouteGuideUtil.GetLatitude(end);
+ double lon1 = RouteGuideUtil.GetLongitude(start);
+ double lon2 = RouteGuideUtil.GetLongitude(end);
+ int r = 6371000; // metres
+ double φ1 = ToRadians(lat1);
+ double φ2 = ToRadians(lat2);
+ double Δφ = ToRadians(lat2 - lat1);
+ double Δλ = ToRadians(lon2 - lon1);
+
+ double a = Math.Sin(Δφ / 2) * Math.Sin(Δφ / 2) + Math.Cos(φ1) * Math.Cos(φ2) * Math.Sin(Δλ / 2) * Math.Sin(Δλ / 2);
+ double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
+
+ return r * c;
+ }
+
+ private static double ToRadians(double val)
+ {
+ return (Math.PI / 180) * val;
+ }
+ }
+}
diff --git a/examples/csharp/route_guide/RouteGuideServer/RouteGuideServer.csproj b/examples/csharp/route_guide/RouteGuideServer/RouteGuideServer.csproj
new file mode 100644
index 00000000000..9ac1cfbf4d8
--- /dev/null
+++ b/examples/csharp/route_guide/RouteGuideServer/RouteGuideServer.csproj
@@ -0,0 +1,101 @@
+
+
+
+
+
+
+
+ Debug
+ AnyCPU
+ {4B7C7794-BE24-4477-ACE7-18259EB73D27}
+ Exe
+ Properties
+ RouteGuideServer
+ RouteGuideServer
+ v4.5
+ 512
+ 74781d8b
+
+
+ AnyCPU
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ AnyCPU
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+ ..\packages\Google.ProtocolBuffers.2.4.1.555\lib\net40\Google.ProtocolBuffers.dll
+
+
+ ..\packages\Google.ProtocolBuffers.2.4.1.555\lib\net40\Google.ProtocolBuffers.Serialization.dll
+
+
+ False
+ ..\packages\Grpc.Core.0.6.0\lib\net45\Grpc.Core.dll
+
+
+
+ False
+ ..\packages\System.Collections.Immutable.1.1.36\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll
+
+
+
+ ..\packages\Ix-Async.1.2.3\lib\net45\System.Interactive.Async.dll
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {49954d9c-5f17-4662-96b2-73be833dd81a}
+ RouteGuide
+
+
+
+
+
+ This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/csharp/route_guide/RouteGuideServer/packages.config b/examples/csharp/route_guide/RouteGuideServer/packages.config
new file mode 100644
index 00000000000..5922553bc37
--- /dev/null
+++ b/examples/csharp/route_guide/RouteGuideServer/packages.config
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/node/.gitignore b/examples/node/.gitignore
new file mode 100644
index 00000000000..3d06f5db7b3
--- /dev/null
+++ b/examples/node/.gitignore
@@ -0,0 +1,3 @@
+*~
+node_modules
+npm-debug.log
\ No newline at end of file
diff --git a/examples/node/README.md b/examples/node/README.md
new file mode 100644
index 00000000000..045fe51ede9
--- /dev/null
+++ b/examples/node/README.md
@@ -0,0 +1,60 @@
+gRPC in 3 minutes (Node.js)
+===========================
+
+PREREQUISITES
+-------------
+
+- `node`: This requires Node 10.x or greater.
+- [homebrew][] on Mac OS X, [linuxbrew][] on Linux. These simplify the installation of the gRPC C core.
+
+INSTALL
+-------
+ - On Mac OS X, install [homebrew][]. On Linux, install [linuxbrew][]. Run the following command to install gRPC Node.js.
+
+ ```sh
+ $ curl -fsSL https://goo.gl/getgrpc | bash -s nodejs
+ ```
+ This will download and run the [gRPC install script][], then install the latest version of gRPC Nodejs npm package.
+ - Clone this repository
+
+ ```sh
+ $ git clone https://github.com/grpc/grpc.git
+ ```
+
+ - Install this package's dependencies
+
+ ```sh
+ $ cd examples/node
+ $ npm install
+ ```
+
+TRY IT!
+-------
+
+ - Run the server
+
+ ```sh
+ $ # from this directory (grpc_common/node).
+ $ node ./greeter_server.js &
+ ```
+
+ - Run the client
+
+ ```sh
+ $ # from this directory
+ $ node ./greeter_client.js
+ ```
+
+NOTE
+----
+This directory has a copy of `helloworld.proto` because it currently depends on
+some Protocol Buffer 2.0 syntax that is deprecated in Protocol Buffer 3.0.
+
+TUTORIAL
+--------
+You can find a more detailed tutorial in [gRPC Basics: Node.js][]
+
+[homebrew]:http://brew.sh
+[linuxbrew]:https://github.com/Homebrew/linuxbrew#installation
+[gRPC install script]:https://raw.githubusercontent.com/grpc/homebrew-grpc/master/scripts/install
+[gRPC Basics: Node.js]:https://github.com/grpc/grpc/blob/master/examples/node/route_guide/README.md
diff --git a/examples/node/greeter_client.js b/examples/node/greeter_client.js
new file mode 100644
index 00000000000..ab7050ab213
--- /dev/null
+++ b/examples/node/greeter_client.js
@@ -0,0 +1,52 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+var PROTO_PATH = __dirname + '/helloworld.proto';
+
+var grpc = require('grpc');
+var hello_proto = grpc.load(PROTO_PATH).helloworld;
+
+function main() {
+ var client = new hello_proto.Greeter('localhost:50051');
+ var user;
+ if (process.argv.length >= 3) {
+ user = process.argv[2];
+ } else {
+ user = 'world';
+ }
+ client.sayHello({name: user}, function(err, response) {
+ console.log('Greeting:', response.message);
+ });
+}
+
+main();
diff --git a/examples/node/greeter_server.js b/examples/node/greeter_server.js
new file mode 100644
index 00000000000..2fb95f0f90e
--- /dev/null
+++ b/examples/node/greeter_server.js
@@ -0,0 +1,63 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+var PROTO_PATH = __dirname + '/helloworld.proto';
+
+var grpc = require('grpc');
+var hello_proto = grpc.load(PROTO_PATH).helloworld;
+
+var Server = grpc.buildServer([hello_proto.Greeter.service]);
+
+/**
+ * Implements the SayHello RPC method.
+ */
+function sayHello(call, callback) {
+ callback(null, {message: 'Hello ' + call.request.name});
+}
+
+/**
+ * Starts an RPC server that receives requests for the Greeter service at the
+ * sample server port
+ */
+function main() {
+ var server = new Server({
+ "helloworld.Greeter": {
+ sayHello: sayHello
+ }
+ });
+
+ server.bind('0.0.0.0:50051');
+ server.listen();
+}
+
+main();
diff --git a/examples/node/helloworld.proto b/examples/node/helloworld.proto
new file mode 100644
index 00000000000..a52c947f895
--- /dev/null
+++ b/examples/node/helloworld.proto
@@ -0,0 +1,50 @@
+// Copyright 2015, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+syntax = "proto3";
+
+option java_package = "ex.grpc";
+
+package helloworld;
+
+// The greeting service definition.
+service Greeter {
+ // Sends a greeting
+ rpc SayHello (HelloRequest) returns (HelloReply) {}
+}
+
+// The request message containing the user's name.
+message HelloRequest {
+ optional string name = 1;
+}
+
+// The response message containing the greetings
+message HelloReply {
+ optional string message = 1;
+}
diff --git a/examples/node/package.json b/examples/node/package.json
new file mode 100644
index 00000000000..caf539518f1
--- /dev/null
+++ b/examples/node/package.json
@@ -0,0 +1,10 @@
+{
+ "name": "grpc-demo",
+ "version": "0.5.0",
+ "dependencies": {
+ "async": "^0.9.0",
+ "grpc": "~0.9.0",
+ "minimist": "^1.1.0",
+ "underscore": "^1.8.2"
+ }
+}
diff --git a/examples/node/route_guide/README.md b/examples/node/route_guide/README.md
new file mode 100644
index 00000000000..2efc5a5da52
--- /dev/null
+++ b/examples/node/route_guide/README.md
@@ -0,0 +1,362 @@
+#gRPC Basics: Node.js
+
+This tutorial provides a basic Node.js programmer's introduction to working with gRPC. By walking through this example you'll learn how to:
+
+- Define a service in a .proto file.
+- Use the Node.js gRPC API to write a simple client and server for your service.
+
+It assumes that you have read the [Getting started](https://github.com/grpc/grpc/tree/master/examples) guide and are familiar with [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). Note that the example in this tutorial uses the proto3 version of the protocol buffers language, which is currently in alpha release:you can find out more in the [proto3 language guide](https://developers.google.com/protocol-buffers/docs/proto3) and see the [release notes](https://github.com/google/protobuf/releases) for the new version in the protocol buffers Github repository.
+
+This isn't a comprehensive guide to using gRPC in Node.js: more reference documentation is coming soon.
+
+## Why use gRPC?
+
+Our example is a simple route mapping application that lets clients get information about features on their route, create a summary of their route, and exchange route information such as traffic updates with the server and other clients.
+
+With gRPC we can define our service once in a .proto file and implement clients and servers in any of gRPC's supported languages, which in turn can be run in environments ranging from servers inside Google to your own tablet - all the complexity of communication between different languages and environments is handled for you by gRPC. We also get all the advantages of working with protocol buffers, including efficient serialization, a simple IDL, and easy interface updating.
+
+## Example code and setup
+
+The example code for our tutorial is in [examples/node/route_guide](examples/node/route_guide). To download the example, clone this repository by running the following command:
+```shell
+$ git clone https://github.com/grpc/grpc.git
+```
+
+Then change your current directory to `examples/node/route_guide`:
+```shell
+$ cd examples/node/route_guide
+```
+
+You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [the Node.js quick start guide](examples/node).
+
+
+## Defining the service
+
+Our first step (as you'll know from [Getting started](https://github.com/grpc/grpc/tree/master/examples)) is to define the gRPC *service* and the method *request* and *response* types using [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). You can see the complete .proto file in [`examples/protos/route_guide.proto`](examples/protos/route_guide.proto).
+
+To define a service, you specify a named `service` in your .proto file:
+
+```protobuf
+service RouteGuide {
+ ...
+}
+```
+
+Then you define `rpc` methods inside your service definition, specifying their request and response types. gRPC lets you define four kinds of service method, all of which are used in the `RouteGuide` service:
+
+- A *simple RPC* where the client sends a request to the server using the stub and waits for a response to come back, just like a normal function call.
+```protobuf
+ // Obtains the feature at a given position.
+ rpc GetFeature(Point) returns (Feature) {}
+```
+
+- A *server-side streaming RPC* where the client sends a request to the server and gets a stream to read a sequence of messages back. The client reads from the returned stream until there are no more messages. As you can see in our example, you specify a server-side streaming method by placing the `stream` keyword before the *response* type.
+```protobuf
+ // Obtains the Features available within the given Rectangle. Results are
+ // streamed rather than returned at once (e.g. in a response message with a
+ // repeated field), as the rectangle may cover a large area and contain a
+ // huge number of features.
+ rpc ListFeatures(Rectangle) returns (stream Feature) {}
+```
+
+- A *client-side streaming RPC* where the client writes a sequence of messages and sends them to the server, again using a provided stream. Once the client has finished writing the messages, it waits for the server to read them all and return its response. You specify a server-side streaming method by placing the `stream` keyword before the *request* type.
+```protobuf
+ // Accepts a stream of Points on a route being traversed, returning a
+ // RouteSummary when traversal is completed.
+ rpc RecordRoute(stream Point) returns (RouteSummary) {}
+```
+
+- A *bidirectional streaming RPC* where both sides send a sequence of messages using a read-write stream. The two streams operate independently, so clients and servers can read and write in whatever order they like: for example, the server could wait to receive all the client messages before writing its responses, or it could alternately read a message then write a message, or some other combination of reads and writes. The order of messages in each stream is preserved. You specify this type of method by placing the `stream` keyword before both the request and the response.
+```protobuf
+ // Accepts a stream of RouteNotes sent while a route is being traversed,
+ // while receiving other RouteNotes (e.g. from other users).
+ rpc RouteChat(stream RouteNote) returns (stream RouteNote) {}
+```
+
+Our .proto file also contains protocol buffer message type definitions for all the request and response types used in our service methods - for example, here's the `Point` message type:
+```protobuf
+// Points are represented as latitude-longitude pairs in the E7 representation
+// (degrees multiplied by 10**7 and rounded to the nearest integer).
+// Latitudes should be in the range +/- 90 degrees and longitude should be in
+// the range +/- 180 degrees (inclusive).
+message Point {
+ int32 latitude = 1;
+ int32 longitude = 2;
+}
+```
+
+
+## Loading service descriptors from proto files
+
+The Node.js library dynamically generates service descriptors and client stub definitions from `.proto` files loaded at runtime.
+
+To load a `.proto` file, simply `require` the gRPC library, then use its `load()` method:
+
+```node
+var grpc = require('grpc');
+var protoDescriptor = grpc.load(__dirname + '/route_guide.proto');
+// The protoDescriptor object has the full package hierarchy
+var example = protoDescriptor.examples;
+```
+
+Once you've done this, the stub constructor is in the `examples` namespace (`protoDescriptor.examples.RouteGuide`) and the service descriptor (which is used to create a server) is a property of the stub (`protoDescriptor.examples.RouteGuide.service`);
+
+
+## Creating the server
+
+First let's look at how we create a `RouteGuide` server. If you're only interested in creating gRPC clients, you can skip this section and go straight to [Creating the client](#client) (though you might find it interesting anyway!).
+
+There are two parts to making our `RouteGuide` service do its job:
+- Implementing the service interface generated from our service definition: doing the actual "work" of our service.
+- Running a gRPC server to listen for requests from clients and return the service responses.
+
+You can find our example `RouteGuide` server in [examples/node/route_guide/route_guide_server.js](examples/node/route_guide/route_guide_server.js). Let's take a closer look at how it works.
+
+### Implementing RouteGuide
+
+As you can see, our server has a `Server` constructor generated from the `RouteGuide.service` descriptor object
+
+```node
+var Server = grpc.buildServer([examples.RouteGuide.service]);
+```
+In this case we're implementing the *asynchronous* version of `RouteGuide`, which provides our default gRPC server behaviour.
+
+The functions in `route_guide_server.js` implement all our service methods. Let's look at the simplest type first, `getFeature`, which just gets a `Point` from the client and returns the corresponding feature information from its database in a `Feature`.
+
+```node
+function checkFeature(point) {
+ var feature;
+ // Check if there is already a feature object for the given point
+ for (var i = 0; i < feature_list.length; i++) {
+ feature = feature_list[i];
+ if (feature.location.latitude === point.latitude &&
+ feature.location.longitude === point.longitude) {
+ return feature;
+ }
+ }
+ var name = '';
+ feature = {
+ name: name,
+ location: point
+ };
+ return feature;
+}
+function getFeature(call, callback) {
+ callback(null, checkFeature(call.request));
+}
+```
+
+The method is passed a call object for the RPC, which has the `Point` parameter as a property, and a callback to which we can pass our returned `Feature`. In the method body we populate a `Feature` corresponding to the given point and pass it to the callback, with a null first parameter to indicate that there is no error.
+
+Now let's look at something a bit more complicated - a streaming RPC. `listFeatures` is a server-side streaming RPC, so we need to send back multiple `Feature`s to our client.
+
+```node
+function listFeatures(call) {
+ var lo = call.request.lo;
+ var hi = call.request.hi;
+ var left = _.min([lo.longitude, hi.longitude]);
+ var right = _.max([lo.longitude, hi.longitude]);
+ var top = _.max([lo.latitude, hi.latitude]);
+ var bottom = _.min([lo.latitude, hi.latitude]);
+ // For each feature, check if it is in the given bounding box
+ _.each(feature_list, function(feature) {
+ if (feature.name === '') {
+ return;
+ }
+ if (feature.location.longitude >= left &&
+ feature.location.longitude <= right &&
+ feature.location.latitude >= bottom &&
+ feature.location.latitude <= top) {
+ call.write(feature);
+ }
+ });
+ call.end();
+}
+```
+
+As you can see, instead of getting the call object and callback in our method parameters, this time we get a `call` object that implements the `Writable` interface. In the method, we create as many `Feature` objects as we need to return, writing them to the `call` using its `write()` method. Finally, we call `call.end()` to indicate that we have sent all messages.
+
+If you look at the client-side streaming method `RecordRoute` you'll see it's quite similar to the unary call, except this time the `call` parameter implements the `Reader` interface. The `call`'s `'data'` event fires every time there is new data, and the `'end'` event fires when all data has been read. Like the unary case, we respond by calling the callback
+
+```node
+call.on('data', function(point) {
+ // Process user data
+});
+call.on('end', function() {
+ callback(null, result);
+});
+```
+
+Finally, let's look at our bidirectional streaming RPC `RouteChat()`.
+
+```node
+function routeChat(call) {
+ call.on('data', function(note) {
+ var key = pointKey(note.location);
+ /* For each note sent, respond with all previous notes that correspond to
+ * the same point */
+ if (route_notes.hasOwnProperty(key)) {
+ _.each(route_notes[key], function(note) {
+ call.write(note);
+ });
+ } else {
+ route_notes[key] = [];
+ }
+ // Then add the new note to the list
+ route_notes[key].push(JSON.parse(JSON.stringify(note)));
+ });
+ call.on('end', function() {
+ call.end();
+ });
+}
+```
+
+This time we get a `call` implementing `Duplex` that can be used to read *and* write messages. The syntax for reading and writing here is exactly the same as for our client-streaming and server-streaming methods. Although each side will always get the other's messages in the order they were written, both the client and server can read and write in any order — the streams operate completely independently.
+
+### Starting the server
+
+Once we've implemented all our methods, we also need to start up a gRPC server so that clients can actually use our service. The following snippet shows how we do this for our `RouteGuide` service:
+
+```node
+function getServer() {
+ return new Server({
+ 'examples.RouteGuide' : {
+ getFeature: getFeature,
+ listFeatures: listFeatures,
+ recordRoute: recordRoute,
+ routeChat: routeChat
+ }
+ });
+}
+var routeServer = getServer();
+routeServer.bind('0.0.0.0:50051');
+routeServer.listen();
+```
+
+As you can see, we build and start our server with the following steps:
+
+ 1. Create a `Server` constructor from the `RouteGuide` service descriptor.
+ 2. Implement the service methods.
+ 3. Create an instance of the server by calling the `Server` constructor with the method implementations.
+ 4. Specify the address and port we want to use to listen for client requests using the instance's `bind()` method.
+ 5. Call `listen()` on the instance to start the RPC server.
+
+
+## Creating the client
+
+In this section, we'll look at creating a Node.js client for our `RouteGuide` service. You can see our complete example client code in [examples/node/route_guide/route_guide_client.js](examples/node/route_guide/route_guide_client.js).
+
+### Creating a stub
+
+To call service methods, we first need to create a *stub*. To do this, we just need to call the RouteGuide stub constructor, specifying the server address and port.
+
+```node
+new example.RouteGuide('localhost:50051');
+```
+
+### Calling service methods
+
+Now let's look at how we call our service methods. Note that all of these methods are asynchronous: they use either events or callbacks to retrieve results.
+
+#### Simple RPC
+
+Calling the simple RPC `GetFeature` is nearly as straightforward as calling a local asynchronous method.
+
+```node
+var point = {latitude: 409146138, longitude: -746188906};
+stub.getFeature(point, function(err, feature) {
+ if (err) {
+ // process error
+ } else {
+ // process feature
+ }
+});
+```
+
+As you can see, we create and populate a request object. Finally, we call the method on the stub, passing it the request and callback. If there is no error, then we can read the response information from the server from our response object.
+
+```node
+ console.log('Found feature called "' + feature.name + '" at ' +
+ feature.location.latitude/COORD_FACTOR + ', ' +
+ feature.location.longitude/COORD_FACTOR);
+```
+
+#### Streaming RPCs
+
+Now let's look at our streaming methods. If you've already read [Creating the server](#server) some of this may look very familiar - streaming RPCs are implemented in a similar way on both sides. Here's where we call the server-side streaming method `ListFeatures`, which returns a stream of geographical `Feature`s:
+
+```node
+var call = client.listFeatures(rectangle);
+ call.on('data', function(feature) {
+ console.log('Found feature called "' + feature.name + '" at ' +
+ feature.location.latitude/COORD_FACTOR + ', ' +
+ feature.location.longitude/COORD_FACTOR);
+ });
+ call.on('end', function() {
+ // The server has finished sending
+ });
+ call.on('status', function(status) {
+ // process status
+ });
+```
+
+Instead of passing the method a request and callback, we pass it a request and get a `Readable` stream object back. The client can use the `Readable`'s `'data'` event to read the server's responses. This event fires with each `Feature` message object until there are no more messages: the `'end'` event indicates that the call is done. Finally, the status event fires when the server sends the status.
+
+The client-side streaming method `RecordRoute` is similar, except there we pass the method a callback and get back a `Writable`.
+
+```node
+ var call = client.recordRoute(function(error, stats) {
+ if (error) {
+ callback(error);
+ }
+ console.log('Finished trip with', stats.point_count, 'points');
+ console.log('Passed', stats.feature_count, 'features');
+ console.log('Travelled', stats.distance, 'meters');
+ console.log('It took', stats.elapsed_time, 'seconds');
+ });
+ function pointSender(lat, lng) {
+ return function(callback) {
+ console.log('Visiting point ' + lat/COORD_FACTOR + ', ' +
+ lng/COORD_FACTOR);
+ call.write({
+ latitude: lat,
+ longitude: lng
+ });
+ _.delay(callback, _.random(500, 1500));
+ };
+ }
+ var point_senders = [];
+ for (var i = 0; i < num_points; i++) {
+ var rand_point = feature_list[_.random(0, feature_list.length - 1)];
+ point_senders[i] = pointSender(rand_point.location.latitude,
+ rand_point.location.longitude);
+ }
+ async.series(point_senders, function() {
+ call.end();
+ });
+```
+
+Once we've finished writing our client's requests to the stream using `write()`, we need to call `end()` on the stream to let gRPC know that we've finished writing. If the status is `OK`, the `stats` object will be populated with the server's response.
+
+Finally, let's look at our bidirectional streaming RPC `routeChat()`. In this case, we just pass a context to the method and get back a `Duplex` stream object, which we can use to both write and read messages.
+
+```node
+var call = client.routeChat();
+```
+
+The syntax for reading and writing here is exactly the same as for our client-streaming and server-streaming methods. Although each side will always get the other's messages in the order they were written, both the client and server can read and write in any order — the streams operate completely independently.
+
+## Try it out!
+
+Build client and server:
+```shell
+$ npm install
+```
+Run the server, which will listen on port 50051:
+```shell
+$ node ./route_guide_server.js --db_path=route_guide_db.json
+```
+Run the client (in a different terminal):
+```shell
+$ node ./route_guide_client.js --db_path=route_guide_db.json
+```
diff --git a/examples/node/route_guide/route_guide.proto b/examples/node/route_guide/route_guide.proto
new file mode 100644
index 00000000000..442112823e5
--- /dev/null
+++ b/examples/node/route_guide/route_guide.proto
@@ -0,0 +1,120 @@
+// Copyright 2015, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+syntax = "proto3";
+
+option java_package = "io.grpc.examples";
+
+package examples;
+
+// Interface exported by the server.
+service RouteGuide {
+ // A simple RPC.
+ //
+ // Obtains the feature at a given position.
+ rpc GetFeature(Point) returns (Feature) {}
+
+ // A server-to-client streaming RPC.
+ //
+ // Obtains the Features available within the given Rectangle. Results are
+ // streamed rather than returned at once (e.g. in a response message with a
+ // repeated field), as the rectangle may cover a large area and contain a
+ // huge number of features.
+ rpc ListFeatures(Rectangle) returns (stream Feature) {}
+
+ // A client-to-server streaming RPC.
+ //
+ // Accepts a stream of Points on a route being traversed, returning a
+ // RouteSummary when traversal is completed.
+ rpc RecordRoute(stream Point) returns (RouteSummary) {}
+
+ // A Bidirectional streaming RPC.
+ //
+ // Accepts a stream of RouteNotes sent while a route is being traversed,
+ // while receiving other RouteNotes (e.g. from other users).
+ rpc RouteChat(stream RouteNote) returns (stream RouteNote) {}
+}
+
+// Points are represented as latitude-longitude pairs in the E7 representation
+// (degrees multiplied by 10**7 and rounded to the nearest integer).
+// Latitudes should be in the range +/- 90 degrees and longitude should be in
+// the range +/- 180 degrees (inclusive).
+message Point {
+ optional int32 latitude = 1;
+ optional int32 longitude = 2;
+}
+
+// A latitude-longitude rectangle, represented as two diagonally opposite
+// points "lo" and "hi".
+message Rectangle {
+ // One corner of the rectangle.
+ optional Point lo = 1;
+
+ // The other corner of the rectangle.
+ optional Point hi = 2;
+}
+
+// A feature names something at a given point.
+//
+// If a feature could not be named, the name is empty.
+message Feature {
+ // The name of the feature.
+ optional string name = 1;
+
+ // The point where the feature is detected.
+ optional Point location = 2;
+}
+
+// A RouteNote is a message sent while at a given point.
+message RouteNote {
+ // The location from which the message is sent.
+ optional Point location = 1;
+
+ // The message to be sent.
+ optional string message = 2;
+}
+
+// A RouteSummary is received in response to a RecordRoute rpc.
+//
+// It contains the number of individual points received, the number of
+// detected features, and the total distance covered as the cumulative sum of
+// the distance between each point.
+message RouteSummary {
+ // The number of points received.
+ optional int32 point_count = 1;
+
+ // The number of known features passed while traversing the route.
+ optional int32 feature_count = 2;
+
+ // The distance covered in metres.
+ optional int32 distance = 3;
+
+ // The duration of the traversal in seconds.
+ optional int32 elapsed_time = 4;
+}
diff --git a/examples/node/route_guide/route_guide_client.js b/examples/node/route_guide/route_guide_client.js
new file mode 100644
index 00000000000..60c47a429d6
--- /dev/null
+++ b/examples/node/route_guide/route_guide_client.js
@@ -0,0 +1,231 @@
+// Copyright 2015, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+var async = require('async');
+var fs = require('fs');
+var parseArgs = require('minimist');
+var path = require('path');
+var _ = require('underscore');
+var grpc = require('grpc');
+var examples = grpc.load(__dirname + '/route_guide.proto').examples;
+var client = new examples.RouteGuide('localhost:50051');
+
+var COORD_FACTOR = 1e7;
+
+/**
+ * Run the getFeature demo. Calls getFeature with a point known to have a
+ * feature and a point known not to have a feature.
+ * @param {function} callback Called when this demo is complete
+ */
+function runGetFeature(callback) {
+ var next = _.after(2, callback);
+ function featureCallback(error, feature) {
+ if (error) {
+ callback(error);
+ }
+ if (feature.name === '') {
+ console.log('Found no feature at ' +
+ feature.location.latitude/COORD_FACTOR + ', ' +
+ feature.location.longitude/COORD_FACTOR);
+ } else {
+ console.log('Found feature called "' + feature.name + '" at ' +
+ feature.location.latitude/COORD_FACTOR + ', ' +
+ feature.location.longitude/COORD_FACTOR);
+ }
+ next();
+ }
+ var point1 = {
+ latitude: 409146138,
+ longitude: -746188906
+ };
+ var point2 = {
+ latitude: 0,
+ longitude: 0
+ };
+ client.getFeature(point1, featureCallback);
+ client.getFeature(point2, featureCallback);
+}
+
+/**
+ * Run the listFeatures demo. Calls listFeatures with a rectangle containing all
+ * of the features in the pre-generated database. Prints each response as it
+ * comes in.
+ * @param {function} callback Called when this demo is complete
+ */
+function runListFeatures(callback) {
+ var rectangle = {
+ lo: {
+ latitude: 400000000,
+ longitude: -750000000
+ },
+ hi: {
+ latitude: 420000000,
+ longitude: -730000000
+ }
+ };
+ console.log('Looking for features between 40, -75 and 42, -73');
+ var call = client.listFeatures(rectangle);
+ call.on('data', function(feature) {
+ console.log('Found feature called "' + feature.name + '" at ' +
+ feature.location.latitude/COORD_FACTOR + ', ' +
+ feature.location.longitude/COORD_FACTOR);
+ });
+ call.on('end', callback);
+}
+
+/**
+ * Run the recordRoute demo. Sends several randomly chosen points from the
+ * pre-generated feature database with a variable delay in between. Prints the
+ * statistics when they are sent from the server.
+ * @param {function} callback Called when this demo is complete
+ */
+function runRecordRoute(callback) {
+ var argv = parseArgs(process.argv, {
+ string: 'db_path'
+ });
+ fs.readFile(path.resolve(argv.db_path), function(err, data) {
+ if (err) callback(err);
+ var feature_list = JSON.parse(data);
+
+ var num_points = 10;
+ var call = client.recordRoute(function(error, stats) {
+ if (error) {
+ callback(error);
+ }
+ console.log('Finished trip with', stats.point_count, 'points');
+ console.log('Passed', stats.feature_count, 'features');
+ console.log('Travelled', stats.distance, 'meters');
+ console.log('It took', stats.elapsed_time, 'seconds');
+ callback();
+ });
+ /**
+ * Constructs a function that asynchronously sends the given point and then
+ * delays sending its callback
+ * @param {number} lat The latitude to send
+ * @param {number} lng The longitude to send
+ * @return {function(function)} The function that sends the point
+ */
+ function pointSender(lat, lng) {
+ /**
+ * Sends the point, then calls the callback after a delay
+ * @param {function} callback Called when complete
+ */
+ return function(callback) {
+ console.log('Visiting point ' + lat/COORD_FACTOR + ', ' +
+ lng/COORD_FACTOR);
+ call.write({
+ latitude: lat,
+ longitude: lng
+ });
+ _.delay(callback, _.random(500, 1500));
+ };
+ }
+ var point_senders = [];
+ for (var i = 0; i < num_points; i++) {
+ var rand_point = feature_list[_.random(0, feature_list.length - 1)];
+ point_senders[i] = pointSender(rand_point.location.latitude,
+ rand_point.location.longitude);
+ }
+ async.series(point_senders, function() {
+ call.end();
+ });
+ });
+}
+
+/**
+ * Run the routeChat demo. Send some chat messages, and print any chat messages
+ * that are sent from the server.
+ * @param {function} callback Called when the demo is complete
+ */
+function runRouteChat(callback) {
+ var call = client.routeChat();
+ call.on('data', function(note) {
+ console.log('Got message "' + note.message + '" at ' +
+ note.location.latitude + ', ' + note.location.longitude);
+ });
+
+ call.on('end', callback);
+
+ var notes = [{
+ location: {
+ latitude: 0,
+ longitude: 0
+ },
+ message: 'First message'
+ }, {
+ location: {
+ latitude: 0,
+ longitude: 1
+ },
+ message: 'Second message'
+ }, {
+ location: {
+ latitude: 1,
+ longitude: 0
+ },
+ message: 'Third message'
+ }, {
+ location: {
+ latitude: 0,
+ longitude: 0
+ },
+ message: 'Fourth message'
+ }];
+ for (var i = 0; i < notes.length; i++) {
+ var note = notes[i];
+ console.log('Sending message "' + note.message + '" at ' +
+ note.location.latitude + ', ' + note.location.longitude);
+ call.write(note);
+ }
+ call.end();
+}
+
+/**
+ * Run all of the demos in order
+ */
+function main() {
+ async.series([
+ runGetFeature,
+ runListFeatures,
+ runRecordRoute,
+ runRouteChat
+ ]);
+}
+
+if (require.main === module) {
+ main();
+}
+
+exports.runGetFeature = runGetFeature;
+
+exports.runListFeatures = runListFeatures;
+
+exports.runRecordRoute = runRecordRoute;
+
+exports.runRouteChat = runRouteChat;
diff --git a/examples/node/route_guide/route_guide_db.json b/examples/node/route_guide/route_guide_db.json
new file mode 100644
index 00000000000..9d6a980ab7d
--- /dev/null
+++ b/examples/node/route_guide/route_guide_db.json
@@ -0,0 +1,601 @@
+[{
+ "location": {
+ "latitude": 407838351,
+ "longitude": -746143763
+ },
+ "name": "Patriots Path, Mendham, NJ 07945, USA"
+}, {
+ "location": {
+ "latitude": 408122808,
+ "longitude": -743999179
+ },
+ "name": "101 New Jersey 10, Whippany, NJ 07981, USA"
+}, {
+ "location": {
+ "latitude": 413628156,
+ "longitude": -749015468
+ },
+ "name": "U.S. 6, Shohola, PA 18458, USA"
+}, {
+ "location": {
+ "latitude": 419999544,
+ "longitude": -740371136
+ },
+ "name": "5 Conners Road, Kingston, NY 12401, USA"
+}, {
+ "location": {
+ "latitude": 414008389,
+ "longitude": -743951297
+ },
+ "name": "Mid Hudson Psychiatric Center, New Hampton, NY 10958, USA"
+}, {
+ "location": {
+ "latitude": 419611318,
+ "longitude": -746524769
+ },
+ "name": "287 Flugertown Road, Livingston Manor, NY 12758, USA"
+}, {
+ "location": {
+ "latitude": 406109563,
+ "longitude": -742186778
+ },
+ "name": "4001 Tremley Point Road, Linden, NJ 07036, USA"
+}, {
+ "location": {
+ "latitude": 416802456,
+ "longitude": -742370183
+ },
+ "name": "352 South Mountain Road, Wallkill, NY 12589, USA"
+}, {
+ "location": {
+ "latitude": 412950425,
+ "longitude": -741077389
+ },
+ "name": "Bailey Turn Road, Harriman, NY 10926, USA"
+}, {
+ "location": {
+ "latitude": 412144655,
+ "longitude": -743949739
+ },
+ "name": "193-199 Wawayanda Road, Hewitt, NJ 07421, USA"
+}, {
+ "location": {
+ "latitude": 415736605,
+ "longitude": -742847522
+ },
+ "name": "406-496 Ward Avenue, Pine Bush, NY 12566, USA"
+}, {
+ "location": {
+ "latitude": 413843930,
+ "longitude": -740501726
+ },
+ "name": "162 Merrill Road, Highland Mills, NY 10930, USA"
+}, {
+ "location": {
+ "latitude": 410873075,
+ "longitude": -744459023
+ },
+ "name": "Clinton Road, West Milford, NJ 07480, USA"
+}, {
+ "location": {
+ "latitude": 412346009,
+ "longitude": -744026814
+ },
+ "name": "16 Old Brook Lane, Warwick, NY 10990, USA"
+}, {
+ "location": {
+ "latitude": 402948455,
+ "longitude": -747903913
+ },
+ "name": "3 Drake Lane, Pennington, NJ 08534, USA"
+}, {
+ "location": {
+ "latitude": 406337092,
+ "longitude": -740122226
+ },
+ "name": "6324 8th Avenue, Brooklyn, NY 11220, USA"
+}, {
+ "location": {
+ "latitude": 406421967,
+ "longitude": -747727624
+ },
+ "name": "1 Merck Access Road, Whitehouse Station, NJ 08889, USA"
+}, {
+ "location": {
+ "latitude": 416318082,
+ "longitude": -749677716
+ },
+ "name": "78-98 Schalck Road, Narrowsburg, NY 12764, USA"
+}, {
+ "location": {
+ "latitude": 415301720,
+ "longitude": -748416257
+ },
+ "name": "282 Lakeview Drive Road, Highland Lake, NY 12743, USA"
+}, {
+ "location": {
+ "latitude": 402647019,
+ "longitude": -747071791
+ },
+ "name": "330 Evelyn Avenue, Hamilton Township, NJ 08619, USA"
+}, {
+ "location": {
+ "latitude": 412567807,
+ "longitude": -741058078
+ },
+ "name": "New York State Reference Route 987E, Southfields, NY 10975, USA"
+}, {
+ "location": {
+ "latitude": 416855156,
+ "longitude": -744420597
+ },
+ "name": "103-271 Tempaloni Road, Ellenville, NY 12428, USA"
+}, {
+ "location": {
+ "latitude": 404663628,
+ "longitude": -744820157
+ },
+ "name": "1300 Airport Road, North Brunswick Township, NJ 08902, USA"
+}, {
+ "location": {
+ "latitude": 407113723,
+ "longitude": -749746483
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 402133926,
+ "longitude": -743613249
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 400273442,
+ "longitude": -741220915
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 411236786,
+ "longitude": -744070769
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 411633782,
+ "longitude": -746784970
+ },
+ "name": "211-225 Plains Road, Augusta, NJ 07822, USA"
+}, {
+ "location": {
+ "latitude": 415830701,
+ "longitude": -742952812
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 413447164,
+ "longitude": -748712898
+ },
+ "name": "165 Pedersen Ridge Road, Milford, PA 18337, USA"
+}, {
+ "location": {
+ "latitude": 405047245,
+ "longitude": -749800722
+ },
+ "name": "100-122 Locktown Road, Frenchtown, NJ 08825, USA"
+}, {
+ "location": {
+ "latitude": 418858923,
+ "longitude": -746156790
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 417951888,
+ "longitude": -748484944
+ },
+ "name": "650-652 Willi Hill Road, Swan Lake, NY 12783, USA"
+}, {
+ "location": {
+ "latitude": 407033786,
+ "longitude": -743977337
+ },
+ "name": "26 East 3rd Street, New Providence, NJ 07974, USA"
+}, {
+ "location": {
+ "latitude": 417548014,
+ "longitude": -740075041
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 410395868,
+ "longitude": -744972325
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 404615353,
+ "longitude": -745129803
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 406589790,
+ "longitude": -743560121
+ },
+ "name": "611 Lawrence Avenue, Westfield, NJ 07090, USA"
+}, {
+ "location": {
+ "latitude": 414653148,
+ "longitude": -740477477
+ },
+ "name": "18 Lannis Avenue, New Windsor, NY 12553, USA"
+}, {
+ "location": {
+ "latitude": 405957808,
+ "longitude": -743255336
+ },
+ "name": "82-104 Amherst Avenue, Colonia, NJ 07067, USA"
+}, {
+ "location": {
+ "latitude": 411733589,
+ "longitude": -741648093
+ },
+ "name": "170 Seven Lakes Drive, Sloatsburg, NY 10974, USA"
+}, {
+ "location": {
+ "latitude": 412676291,
+ "longitude": -742606606
+ },
+ "name": "1270 Lakes Road, Monroe, NY 10950, USA"
+}, {
+ "location": {
+ "latitude": 409224445,
+ "longitude": -748286738
+ },
+ "name": "509-535 Alphano Road, Great Meadows, NJ 07838, USA"
+}, {
+ "location": {
+ "latitude": 406523420,
+ "longitude": -742135517
+ },
+ "name": "652 Garden Street, Elizabeth, NJ 07202, USA"
+}, {
+ "location": {
+ "latitude": 401827388,
+ "longitude": -740294537
+ },
+ "name": "349 Sea Spray Court, Neptune City, NJ 07753, USA"
+}, {
+ "location": {
+ "latitude": 410564152,
+ "longitude": -743685054
+ },
+ "name": "13-17 Stanley Street, West Milford, NJ 07480, USA"
+}, {
+ "location": {
+ "latitude": 408472324,
+ "longitude": -740726046
+ },
+ "name": "47 Industrial Avenue, Teterboro, NJ 07608, USA"
+}, {
+ "location": {
+ "latitude": 412452168,
+ "longitude": -740214052
+ },
+ "name": "5 White Oak Lane, Stony Point, NY 10980, USA"
+}, {
+ "location": {
+ "latitude": 409146138,
+ "longitude": -746188906
+ },
+ "name": "Berkshire Valley Management Area Trail, Jefferson, NJ, USA"
+}, {
+ "location": {
+ "latitude": 404701380,
+ "longitude": -744781745
+ },
+ "name": "1007 Jersey Avenue, New Brunswick, NJ 08901, USA"
+}, {
+ "location": {
+ "latitude": 409642566,
+ "longitude": -746017679
+ },
+ "name": "6 East Emerald Isle Drive, Lake Hopatcong, NJ 07849, USA"
+}, {
+ "location": {
+ "latitude": 408031728,
+ "longitude": -748645385
+ },
+ "name": "1358-1474 New Jersey 57, Port Murray, NJ 07865, USA"
+}, {
+ "location": {
+ "latitude": 413700272,
+ "longitude": -742135189
+ },
+ "name": "367 Prospect Road, Chester, NY 10918, USA"
+}, {
+ "location": {
+ "latitude": 404310607,
+ "longitude": -740282632
+ },
+ "name": "10 Simon Lake Drive, Atlantic Highlands, NJ 07716, USA"
+}, {
+ "location": {
+ "latitude": 409319800,
+ "longitude": -746201391
+ },
+ "name": "11 Ward Street, Mount Arlington, NJ 07856, USA"
+}, {
+ "location": {
+ "latitude": 406685311,
+ "longitude": -742108603
+ },
+ "name": "300-398 Jefferson Avenue, Elizabeth, NJ 07201, USA"
+}, {
+ "location": {
+ "latitude": 419018117,
+ "longitude": -749142781
+ },
+ "name": "43 Dreher Road, Roscoe, NY 12776, USA"
+}, {
+ "location": {
+ "latitude": 412856162,
+ "longitude": -745148837
+ },
+ "name": "Swan Street, Pine Island, NY 10969, USA"
+}, {
+ "location": {
+ "latitude": 416560744,
+ "longitude": -746721964
+ },
+ "name": "66 Pleasantview Avenue, Monticello, NY 12701, USA"
+}, {
+ "location": {
+ "latitude": 405314270,
+ "longitude": -749836354
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 414219548,
+ "longitude": -743327440
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 415534177,
+ "longitude": -742900616
+ },
+ "name": "565 Winding Hills Road, Montgomery, NY 12549, USA"
+}, {
+ "location": {
+ "latitude": 406898530,
+ "longitude": -749127080
+ },
+ "name": "231 Rocky Run Road, Glen Gardner, NJ 08826, USA"
+}, {
+ "location": {
+ "latitude": 407586880,
+ "longitude": -741670168
+ },
+ "name": "100 Mount Pleasant Avenue, Newark, NJ 07104, USA"
+}, {
+ "location": {
+ "latitude": 400106455,
+ "longitude": -742870190
+ },
+ "name": "517-521 Huntington Drive, Manchester Township, NJ 08759, USA"
+}, {
+ "location": {
+ "latitude": 400066188,
+ "longitude": -746793294
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 418803880,
+ "longitude": -744102673
+ },
+ "name": "40 Mountain Road, Napanoch, NY 12458, USA"
+}, {
+ "location": {
+ "latitude": 414204288,
+ "longitude": -747895140
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 414777405,
+ "longitude": -740615601
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 415464475,
+ "longitude": -747175374
+ },
+ "name": "48 North Road, Forestburgh, NY 12777, USA"
+}, {
+ "location": {
+ "latitude": 404062378,
+ "longitude": -746376177
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 405688272,
+ "longitude": -749285130
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 400342070,
+ "longitude": -748788996
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 401809022,
+ "longitude": -744157964
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 404226644,
+ "longitude": -740517141
+ },
+ "name": "9 Thompson Avenue, Leonardo, NJ 07737, USA"
+}, {
+ "location": {
+ "latitude": 410322033,
+ "longitude": -747871659
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 407100674,
+ "longitude": -747742727
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 418811433,
+ "longitude": -741718005
+ },
+ "name": "213 Bush Road, Stone Ridge, NY 12484, USA"
+}, {
+ "location": {
+ "latitude": 415034302,
+ "longitude": -743850945
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 411349992,
+ "longitude": -743694161
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 404839914,
+ "longitude": -744759616
+ },
+ "name": "1-17 Bergen Court, New Brunswick, NJ 08901, USA"
+}, {
+ "location": {
+ "latitude": 414638017,
+ "longitude": -745957854
+ },
+ "name": "35 Oakland Valley Road, Cuddebackville, NY 12729, USA"
+}, {
+ "location": {
+ "latitude": 412127800,
+ "longitude": -740173578
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 401263460,
+ "longitude": -747964303
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 412843391,
+ "longitude": -749086026
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 418512773,
+ "longitude": -743067823
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 404318328,
+ "longitude": -740835638
+ },
+ "name": "42-102 Main Street, Belford, NJ 07718, USA"
+}, {
+ "location": {
+ "latitude": 419020746,
+ "longitude": -741172328
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 404080723,
+ "longitude": -746119569
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 401012643,
+ "longitude": -744035134
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 404306372,
+ "longitude": -741079661
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 403966326,
+ "longitude": -748519297
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 405002031,
+ "longitude": -748407866
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 409532885,
+ "longitude": -742200683
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 416851321,
+ "longitude": -742674555
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 406411633,
+ "longitude": -741722051
+ },
+ "name": "3387 Richmond Terrace, Staten Island, NY 10303, USA"
+}, {
+ "location": {
+ "latitude": 413069058,
+ "longitude": -744597778
+ },
+ "name": "261 Van Sickle Road, Goshen, NY 10924, USA"
+}, {
+ "location": {
+ "latitude": 418465462,
+ "longitude": -746859398
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 411733222,
+ "longitude": -744228360
+ },
+ "name": ""
+}, {
+ "location": {
+ "latitude": 410248224,
+ "longitude": -747127767
+ },
+ "name": "3 Hasta Way, Newton, NJ 07860, USA"
+}]
diff --git a/examples/node/route_guide/route_guide_server.js b/examples/node/route_guide/route_guide_server.js
new file mode 100644
index 00000000000..5dd84126543
--- /dev/null
+++ b/examples/node/route_guide/route_guide_server.js
@@ -0,0 +1,249 @@
+// Copyright 2015, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+var fs = require('fs');
+var parseArgs = require('minimist');
+var path = require('path');
+var _ = require('underscore');
+var grpc = require('grpc');
+var examples = grpc.load(__dirname + '/route_guide.proto').examples;
+
+var Server = grpc.buildServer([examples.RouteGuide.service]);
+
+var COORD_FACTOR = 1e7;
+
+/**
+ * For simplicity, a point is a record type that looks like
+ * {latitude: number, longitude: number}, and a feature is a record type that
+ * looks like {name: string, location: point}. feature objects with name===''
+ * are points with no feature.
+ */
+
+/**
+ * List of feature objects at points that have been requested so far.
+ */
+var feature_list = [];
+
+/**
+ * Get a feature object at the given point, or creates one if it does not exist.
+ * @param {point} point The point to check
+ * @return {feature} The feature object at the point. Note that an empty name
+ * indicates no feature
+ */
+function checkFeature(point) {
+ var feature;
+ // Check if there is already a feature object for the given point
+ for (var i = 0; i < feature_list.length; i++) {
+ feature = feature_list[i];
+ if (feature.location.latitude === point.latitude &&
+ feature.location.longitude === point.longitude) {
+ return feature;
+ }
+ }
+ var name = '';
+ feature = {
+ name: name,
+ location: point
+ };
+ return feature;
+}
+
+/**
+ * getFeature request handler. Gets a request with a point, and responds with a
+ * feature object indicating whether there is a feature at that point.
+ * @param {EventEmitter} call Call object for the handler to process
+ * @param {function(Error, feature)} callback Response callback
+ */
+function getFeature(call, callback) {
+ callback(null, checkFeature(call.request));
+}
+
+/**
+ * listFeatures request handler. Gets a request with two points, and responds
+ * with a stream of all features in the bounding box defined by those points.
+ * @param {Writable} call Writable stream for responses with an additional
+ * request property for the request value.
+ */
+function listFeatures(call) {
+ var lo = call.request.lo;
+ var hi = call.request.hi;
+ var left = _.min([lo.longitude, hi.longitude]);
+ var right = _.max([lo.longitude, hi.longitude]);
+ var top = _.max([lo.latitude, hi.latitude]);
+ var bottom = _.min([lo.latitude, hi.latitude]);
+ // For each feature, check if it is in the given bounding box
+ _.each(feature_list, function(feature) {
+ if (feature.name === '') {
+ return;
+ }
+ if (feature.location.longitude >= left &&
+ feature.location.longitude <= right &&
+ feature.location.latitude >= bottom &&
+ feature.location.latitude <= top) {
+ call.write(feature);
+ }
+ });
+ call.end();
+}
+
+/**
+ * Calculate the distance between two points using the "haversine" formula.
+ * This code was taken from http://www.movable-type.co.uk/scripts/latlong.html.
+ * @param start The starting point
+ * @param end The end point
+ * @return The distance between the points in meters
+ */
+function getDistance(start, end) {
+ function toRadians(num) {
+ return num * Math.PI / 180;
+ }
+ var lat1 = start.latitude / COORD_FACTOR;
+ var lat2 = end.latitude / COORD_FACTOR;
+ var lon1 = start.longitude / COORD_FACTOR;
+ var lon2 = end.longitude / COORD_FACTOR;
+ var R = 6371000; // metres
+ var φ1 = toRadians(lat1);
+ var φ2 = toRadians(lat2);
+ var Δφ = toRadians(lat2-lat1);
+ var Δλ = toRadians(lon2-lon1);
+
+ var a = Math.sin(Δφ/2) * Math.sin(Δφ/2) +
+ Math.cos(φ1) * Math.cos(φ2) *
+ Math.sin(Δλ/2) * Math.sin(Δλ/2);
+ var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
+
+ return R * c;
+}
+
+/**
+ * recordRoute handler. Gets a stream of points, and responds with statistics
+ * about the "trip": number of points, number of known features visited, total
+ * distance traveled, and total time spent.
+ * @param {Readable} call The request point stream.
+ * @param {function(Error, routeSummary)} callback The callback to pass the
+ * response to
+ */
+function recordRoute(call, callback) {
+ var point_count = 0;
+ var feature_count = 0;
+ var distance = 0;
+ var previous = null;
+ // Start a timer
+ var start_time = process.hrtime();
+ call.on('data', function(point) {
+ point_count += 1;
+ if (checkFeature(point).name !== '') {
+ feature_count += 1;
+ }
+ /* For each point after the first, add the incremental distance from the
+ * previous point to the total distance value */
+ if (previous != null) {
+ distance += getDistance(previous, point);
+ }
+ previous = point;
+ });
+ call.on('end', function() {
+ callback(null, {
+ point_count: point_count,
+ feature_count: feature_count,
+ // Cast the distance to an integer
+ distance: distance|0,
+ // End the timer
+ elapsed_time: process.hrtime(start_time)[0]
+ });
+ });
+}
+
+var route_notes = {};
+
+/**
+ * Turn the point into a dictionary key.
+ * @param {point} point The point to use
+ * @return {string} The key for an object
+ */
+function pointKey(point) {
+ return point.latitude + ' ' + point.longitude;
+}
+
+/**
+ * routeChat handler. Receives a stream of message/location pairs, and responds
+ * with a stream of all previous messages at each of those locations.
+ * @param {Duplex} call The stream for incoming and outgoing messages
+ */
+function routeChat(call) {
+ call.on('data', function(note) {
+ var key = pointKey(note.location);
+ /* For each note sent, respond with all previous notes that correspond to
+ * the same point */
+ if (route_notes.hasOwnProperty(key)) {
+ _.each(route_notes[key], function(note) {
+ call.write(note);
+ });
+ } else {
+ route_notes[key] = [];
+ }
+ // Then add the new note to the list
+ route_notes[key].push(JSON.parse(JSON.stringify(note)));
+ });
+ call.on('end', function() {
+ call.end();
+ });
+}
+
+/**
+ * Get a new server with the handler functions in this file bound to the methods
+ * it serves.
+ * @return {Server} The new server object
+ */
+function getServer() {
+ return new Server({
+ 'examples.RouteGuide' : {
+ getFeature: getFeature,
+ listFeatures: listFeatures,
+ recordRoute: recordRoute,
+ routeChat: routeChat
+ }
+ });
+}
+
+if (require.main === module) {
+ // If this is run as a script, start a server on an unused port
+ var routeServer = getServer();
+ routeServer.bind('0.0.0.0:50051');
+ var argv = parseArgs(process.argv, {
+ string: 'db_path'
+ });
+ fs.readFile(path.resolve(argv.db_path), function(err, data) {
+ if (err) throw err;
+ feature_list = JSON.parse(data);
+ routeServer.listen();
+ });
+}
+
+exports.getServer = getServer;
diff --git a/examples/objective-c/auth_sample/AuthSample.xcodeproj/project.pbxproj b/examples/objective-c/auth_sample/AuthSample.xcodeproj/project.pbxproj
new file mode 100644
index 00000000000..51a39c578c7
--- /dev/null
+++ b/examples/objective-c/auth_sample/AuthSample.xcodeproj/project.pbxproj
@@ -0,0 +1,366 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 46;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ 63E1E9821B28CB2100EF0978 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 63E1E9811B28CB2100EF0978 /* main.m */; };
+ 63E1E9851B28CB2100EF0978 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 63E1E9841B28CB2100EF0978 /* AppDelegate.m */; };
+ 63E1E9881B28CB2100EF0978 /* SelectUserViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 63E1E9871B28CB2100EF0978 /* SelectUserViewController.m */; };
+ 63E1E98B1B28CB2100EF0978 /* MakeRPCViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 63E1E98A1B28CB2100EF0978 /* MakeRPCViewController.m */; };
+ 63E1E98E1B28CB2100EF0978 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 63E1E98C1B28CB2100EF0978 /* Main.storyboard */; };
+ 63E1E9901B28CB2100EF0978 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 63E1E98F1B28CB2100EF0978 /* Images.xcassets */; };
+ 63F5DE481B28F5C100CDD07E /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 63F5DE471B28F5C100CDD07E /* GoogleService-Info.plist */; };
+ 832213142AB24DB816D02635 /* libPods-AuthSample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F217A6ECA7F5BD1D5FB5071B /* libPods-AuthSample.a */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXFileReference section */
+ 63E1E97C1B28CB2100EF0978 /* AuthSample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AuthSample.app; sourceTree = BUILT_PRODUCTS_DIR; };
+ 63E1E9801B28CB2100EF0978 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
+ 63E1E9811B28CB2100EF0978 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; };
+ 63E1E9831B28CB2100EF0978 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; };
+ 63E1E9841B28CB2100EF0978 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; };
+ 63E1E9861B28CB2100EF0978 /* SelectUserViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SelectUserViewController.h; sourceTree = ""; };
+ 63E1E9871B28CB2100EF0978 /* SelectUserViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SelectUserViewController.m; sourceTree = ""; };
+ 63E1E9891B28CB2100EF0978 /* MakeRPCViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MakeRPCViewController.h; sourceTree = ""; };
+ 63E1E98A1B28CB2100EF0978 /* MakeRPCViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MakeRPCViewController.m; sourceTree = ""; };
+ 63E1E98D1B28CB2100EF0978 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
+ 63E1E98F1B28CB2100EF0978 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; };
+ 63F5DE471B28F5C100CDD07E /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = ""; };
+ A387D6CECBCF2EAF2983033A /* Pods-AuthSample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AuthSample.debug.xcconfig"; path = "Pods/Target Support Files/Pods-AuthSample/Pods-AuthSample.debug.xcconfig"; sourceTree = ""; };
+ B444176735DA81FBE4B8B80C /* Pods-AuthSample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AuthSample.release.xcconfig"; path = "Pods/Target Support Files/Pods-AuthSample/Pods-AuthSample.release.xcconfig"; sourceTree = ""; };
+ F217A6ECA7F5BD1D5FB5071B /* libPods-AuthSample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-AuthSample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ 63E1E9791B28CB2000EF0978 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 832213142AB24DB816D02635 /* libPods-AuthSample.a in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ 021FA0E0B3F5D3D477DDAC10 /* Pods */ = {
+ isa = PBXGroup;
+ children = (
+ A387D6CECBCF2EAF2983033A /* Pods-AuthSample.debug.xcconfig */,
+ B444176735DA81FBE4B8B80C /* Pods-AuthSample.release.xcconfig */,
+ );
+ name = Pods;
+ sourceTree = "";
+ };
+ 4F443572636F3D60F26E870D /* Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ F217A6ECA7F5BD1D5FB5071B /* libPods-AuthSample.a */,
+ );
+ name = Frameworks;
+ sourceTree = "";
+ };
+ 63E1E9731B28CB2000EF0978 = {
+ isa = PBXGroup;
+ children = (
+ 63E1E97E1B28CB2100EF0978 /* AuthSample */,
+ 63E1E97D1B28CB2100EF0978 /* Products */,
+ 021FA0E0B3F5D3D477DDAC10 /* Pods */,
+ 4F443572636F3D60F26E870D /* Frameworks */,
+ );
+ sourceTree = "";
+ };
+ 63E1E97D1B28CB2100EF0978 /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ 63E1E97C1B28CB2100EF0978 /* AuthSample.app */,
+ );
+ name = Products;
+ sourceTree = "";
+ };
+ 63E1E97E1B28CB2100EF0978 /* AuthSample */ = {
+ isa = PBXGroup;
+ children = (
+ 63E1E9861B28CB2100EF0978 /* SelectUserViewController.h */,
+ 63E1E9871B28CB2100EF0978 /* SelectUserViewController.m */,
+ 63E1E9891B28CB2100EF0978 /* MakeRPCViewController.h */,
+ 63E1E98A1B28CB2100EF0978 /* MakeRPCViewController.m */,
+ 63E1E97F1B28CB2100EF0978 /* Supporting Files */,
+ );
+ name = AuthSample;
+ sourceTree = SOURCE_ROOT;
+ };
+ 63E1E97F1B28CB2100EF0978 /* Supporting Files */ = {
+ isa = PBXGroup;
+ children = (
+ 63E1E98C1B28CB2100EF0978 /* Main.storyboard */,
+ 63F5DE471B28F5C100CDD07E /* GoogleService-Info.plist */,
+ 63E1E98F1B28CB2100EF0978 /* Images.xcassets */,
+ 63E1E9801B28CB2100EF0978 /* Info.plist */,
+ 63E1E9831B28CB2100EF0978 /* AppDelegate.h */,
+ 63E1E9841B28CB2100EF0978 /* AppDelegate.m */,
+ 63E1E9811B28CB2100EF0978 /* main.m */,
+ );
+ name = "Supporting Files";
+ path = Misc;
+ sourceTree = "";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+ 63E1E97B1B28CB2000EF0978 /* AuthSample */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 63E1E9A21B28CB2100EF0978 /* Build configuration list for PBXNativeTarget "AuthSample" */;
+ buildPhases = (
+ DAABBA7B5788A39108D7CA83 /* Check Pods Manifest.lock */,
+ 63E1E9781B28CB2000EF0978 /* Sources */,
+ 63E1E9791B28CB2000EF0978 /* Frameworks */,
+ 63E1E97A1B28CB2000EF0978 /* Resources */,
+ AEFCCC69DD59CE8F6EB769D7 /* Copy Pods Resources */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = AuthSample;
+ productName = AuthSample;
+ productReference = 63E1E97C1B28CB2100EF0978 /* AuthSample.app */;
+ productType = "com.apple.product-type.application";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ 63E1E9741B28CB2000EF0978 /* Project object */ = {
+ isa = PBXProject;
+ attributes = {
+ LastUpgradeCheck = 0630;
+ ORGANIZATIONNAME = gRPC;
+ TargetAttributes = {
+ 63E1E97B1B28CB2000EF0978 = {
+ CreatedOnToolsVersion = 6.3.1;
+ };
+ };
+ };
+ buildConfigurationList = 63E1E9771B28CB2000EF0978 /* Build configuration list for PBXProject "AuthSample" */;
+ compatibilityVersion = "Xcode 3.2";
+ developmentRegion = English;
+ hasScannedForEncodings = 0;
+ knownRegions = (
+ en,
+ Base,
+ );
+ mainGroup = 63E1E9731B28CB2000EF0978;
+ productRefGroup = 63E1E97D1B28CB2100EF0978 /* Products */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ 63E1E97B1B28CB2000EF0978 /* AuthSample */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXResourcesBuildPhase section */
+ 63E1E97A1B28CB2000EF0978 /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 63E1E98E1B28CB2100EF0978 /* Main.storyboard in Resources */,
+ 63E1E9901B28CB2100EF0978 /* Images.xcassets in Resources */,
+ 63F5DE481B28F5C100CDD07E /* GoogleService-Info.plist in Resources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXResourcesBuildPhase section */
+
+/* Begin PBXShellScriptBuildPhase section */
+ AEFCCC69DD59CE8F6EB769D7 /* Copy Pods Resources */ = {
+ isa = PBXShellScriptBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ inputPaths = (
+ );
+ name = "Copy Pods Resources";
+ outputPaths = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ shellPath = /bin/sh;
+ shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-AuthSample/Pods-AuthSample-resources.sh\"\n";
+ showEnvVarsInLog = 0;
+ };
+ DAABBA7B5788A39108D7CA83 /* Check Pods Manifest.lock */ = {
+ isa = PBXShellScriptBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ inputPaths = (
+ );
+ name = "Check Pods Manifest.lock";
+ outputPaths = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ shellPath = /bin/sh;
+ shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
+ showEnvVarsInLog = 0;
+ };
+/* End PBXShellScriptBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+ 63E1E9781B28CB2000EF0978 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 63E1E98B1B28CB2100EF0978 /* MakeRPCViewController.m in Sources */,
+ 63E1E9851B28CB2100EF0978 /* AppDelegate.m in Sources */,
+ 63E1E9881B28CB2100EF0978 /* SelectUserViewController.m in Sources */,
+ 63E1E9821B28CB2100EF0978 /* main.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin PBXVariantGroup section */
+ 63E1E98C1B28CB2100EF0978 /* Main.storyboard */ = {
+ isa = PBXVariantGroup;
+ children = (
+ 63E1E98D1B28CB2100EF0978 /* Base */,
+ );
+ name = Main.storyboard;
+ sourceTree = "