From 7c7e9c339603652621184131daad9a50ca1d78a7 Mon Sep 17 00:00:00 2001 From: Yang Gao Date: Fri, 20 Feb 2015 10:34:02 -0800 Subject: [PATCH 01/12] Fork code from helloworld and generate code --- cpp/route_guide/Makefile | 47 + cpp/route_guide/route_guide.pb.cc | 1736 +++++++++++++++++++++++++ cpp/route_guide/route_guide.pb.h | 929 +++++++++++++ cpp/route_guide/route_guide_client.cc | 91 ++ cpp/route_guide/route_guide_server.cc | 84 ++ 5 files changed, 2887 insertions(+) create mode 100644 cpp/route_guide/Makefile create mode 100644 cpp/route_guide/route_guide.pb.cc create mode 100644 cpp/route_guide/route_guide.pb.h create mode 100644 cpp/route_guide/route_guide_client.cc create mode 100644 cpp/route_guide/route_guide_server.cc diff --git a/cpp/route_guide/Makefile b/cpp/route_guide/Makefile new file mode 100644 index 0000000..b9579e0 --- /dev/null +++ b/cpp/route_guide/Makefile @@ -0,0 +1,47 @@ +# +# 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 -lgrpc++ -lprotobuf -lpthread -ldl + +all: greeter_client greeter_server + +greeter_client: helloworld.pb.o greeter_client.o + $(CXX) $(CPPFLAGS) $^ $(LDFLAGS) -o $@ + +greeter_server: helloworld.pb.o greeter_server.o + $(CXX) $(CPPFLAGS) $^ $(LDFLAGS) -o $@ + +clean: + rm -f *.o greeter_client greeter_server + diff --git a/cpp/route_guide/route_guide.pb.cc b/cpp/route_guide/route_guide.pb.cc new file mode 100644 index 0000000..6f4a1e7 --- /dev/null +++ b/cpp/route_guide/route_guide.pb.cc @@ -0,0 +1,1736 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: route_guide.proto + +#define INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION +#include "route_guide.pb.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +// @@protoc_insertion_point(includes) + +namespace examples { + +namespace { + +const ::google::protobuf::Descriptor* Point_descriptor_ = NULL; +const ::google::protobuf::internal::GeneratedMessageReflection* + Point_reflection_ = NULL; +const ::google::protobuf::Descriptor* Rectangle_descriptor_ = NULL; +const ::google::protobuf::internal::GeneratedMessageReflection* + Rectangle_reflection_ = NULL; +const ::google::protobuf::Descriptor* Feature_descriptor_ = NULL; +const ::google::protobuf::internal::GeneratedMessageReflection* + Feature_reflection_ = NULL; +const ::google::protobuf::Descriptor* RouteNote_descriptor_ = NULL; +const ::google::protobuf::internal::GeneratedMessageReflection* + RouteNote_reflection_ = NULL; +const ::google::protobuf::Descriptor* RouteSummary_descriptor_ = NULL; +const ::google::protobuf::internal::GeneratedMessageReflection* + RouteSummary_reflection_ = NULL; + +} // namespace + + +void protobuf_AssignDesc_route_5fguide_2eproto() { + protobuf_AddDesc_route_5fguide_2eproto(); + const ::google::protobuf::FileDescriptor* file = + ::google::protobuf::DescriptorPool::generated_pool()->FindFileByName( + "route_guide.proto"); + GOOGLE_CHECK(file != NULL); + Point_descriptor_ = file->message_type(0); + static const int Point_offsets_[2] = { + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Point, latitude_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Point, longitude_), + }; + Point_reflection_ = + ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( + Point_descriptor_, + Point::default_instance_, + Point_offsets_, + -1, + -1, + -1, + sizeof(Point), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Point, _internal_metadata_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Point, _is_default_instance_)); + Rectangle_descriptor_ = file->message_type(1); + static const int Rectangle_offsets_[2] = { + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Rectangle, lo_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Rectangle, hi_), + }; + Rectangle_reflection_ = + ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( + Rectangle_descriptor_, + Rectangle::default_instance_, + Rectangle_offsets_, + -1, + -1, + -1, + sizeof(Rectangle), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Rectangle, _internal_metadata_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Rectangle, _is_default_instance_)); + Feature_descriptor_ = file->message_type(2); + static const int Feature_offsets_[2] = { + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Feature, name_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Feature, location_), + }; + Feature_reflection_ = + ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( + Feature_descriptor_, + Feature::default_instance_, + Feature_offsets_, + -1, + -1, + -1, + sizeof(Feature), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Feature, _internal_metadata_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Feature, _is_default_instance_)); + RouteNote_descriptor_ = file->message_type(3); + static const int RouteNote_offsets_[2] = { + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(RouteNote, location_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(RouteNote, message_), + }; + RouteNote_reflection_ = + ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( + RouteNote_descriptor_, + RouteNote::default_instance_, + RouteNote_offsets_, + -1, + -1, + -1, + sizeof(RouteNote), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(RouteNote, _internal_metadata_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(RouteNote, _is_default_instance_)); + RouteSummary_descriptor_ = file->message_type(4); + static const int RouteSummary_offsets_[4] = { + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(RouteSummary, point_count_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(RouteSummary, feature_count_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(RouteSummary, distance_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(RouteSummary, elapsed_time_), + }; + RouteSummary_reflection_ = + ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( + RouteSummary_descriptor_, + RouteSummary::default_instance_, + RouteSummary_offsets_, + -1, + -1, + -1, + sizeof(RouteSummary), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(RouteSummary, _internal_metadata_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(RouteSummary, _is_default_instance_)); +} + +namespace { + +GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_); +inline void protobuf_AssignDescriptorsOnce() { + ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_, + &protobuf_AssignDesc_route_5fguide_2eproto); +} + +void protobuf_RegisterTypes(const ::std::string&) { + protobuf_AssignDescriptorsOnce(); + ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( + Point_descriptor_, &Point::default_instance()); + ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( + Rectangle_descriptor_, &Rectangle::default_instance()); + ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( + Feature_descriptor_, &Feature::default_instance()); + ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( + RouteNote_descriptor_, &RouteNote::default_instance()); + ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( + RouteSummary_descriptor_, &RouteSummary::default_instance()); +} + +} // namespace + +void protobuf_ShutdownFile_route_5fguide_2eproto() { + delete Point::default_instance_; + delete Point_reflection_; + delete Rectangle::default_instance_; + delete Rectangle_reflection_; + delete Feature::default_instance_; + delete Feature_reflection_; + delete RouteNote::default_instance_; + delete RouteNote_reflection_; + delete RouteSummary::default_instance_; + delete RouteSummary_reflection_; +} + +void protobuf_AddDesc_route_5fguide_2eproto() { + static bool already_here = false; + if (already_here) return; + already_here = true; + GOOGLE_PROTOBUF_VERIFY_VERSION; + + ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( + "\n\021route_guide.proto\022\010examples\",\n\005Point\022\020" + "\n\010latitude\030\001 \001(\005\022\021\n\tlongitude\030\002 \001(\005\"E\n\tR" + "ectangle\022\033\n\002lo\030\001 \001(\0132\017.examples.Point\022\033\n" + "\002hi\030\002 \001(\0132\017.examples.Point\":\n\007Feature\022\014\n" + "\004name\030\001 \001(\t\022!\n\010location\030\002 \001(\0132\017.examples" + ".Point\"\?\n\tRouteNote\022!\n\010location\030\001 \001(\0132\017." + "examples.Point\022\017\n\007message\030\002 \001(\t\"b\n\014Route" + "Summary\022\023\n\013point_count\030\001 \001(\005\022\025\n\rfeature_" + "count\030\002 \001(\005\022\020\n\010distance\030\003 \001(\005\022\024\n\014elapsed" + "_time\030\004 \001(\0052\365\001\n\nRouteGuide\0222\n\nGetFeature" + "\022\017.examples.Point\032\021.examples.Feature\"\000\022:" + "\n\014ListFeatures\022\023.examples.Rectangle\032\021.ex" + "amples.Feature\"\0000\001\022:\n\013RecordRoute\022\017.exam" + "ples.Point\032\026.examples.RouteSummary\"\000(\001\022;" + "\n\tRouteChat\022\023.examples.RouteNote\032\023.examp" + "les.RouteNote\"\000(\0010\001B\t\n\007ex.grpcb\006proto3", 638); + ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( + "route_guide.proto", &protobuf_RegisterTypes); + Point::default_instance_ = new Point(); + Rectangle::default_instance_ = new Rectangle(); + Feature::default_instance_ = new Feature(); + RouteNote::default_instance_ = new RouteNote(); + RouteSummary::default_instance_ = new RouteSummary(); + Point::default_instance_->InitAsDefaultInstance(); + Rectangle::default_instance_->InitAsDefaultInstance(); + Feature::default_instance_->InitAsDefaultInstance(); + RouteNote::default_instance_->InitAsDefaultInstance(); + RouteSummary::default_instance_->InitAsDefaultInstance(); + ::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_route_5fguide_2eproto); +} + +// Force AddDescriptors() to be called at static initialization time. +struct StaticDescriptorInitializer_route_5fguide_2eproto { + StaticDescriptorInitializer_route_5fguide_2eproto() { + protobuf_AddDesc_route_5fguide_2eproto(); + } +} static_descriptor_initializer_route_5fguide_2eproto_; + +namespace { + +static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD; +static void MergeFromFail(int line) { + GOOGLE_CHECK(false) << __FILE__ << ":" << line; +} + +} // namespace + + +// =================================================================== + +#ifndef _MSC_VER +const int Point::kLatitudeFieldNumber; +const int Point::kLongitudeFieldNumber; +#endif // !_MSC_VER + +Point::Point() + : ::google::protobuf::Message() , _internal_metadata_(NULL) { + SharedCtor(); + // @@protoc_insertion_point(constructor:examples.Point) +} + +void Point::InitAsDefaultInstance() { + _is_default_instance_ = true; +} + +Point::Point(const Point& from) + : ::google::protobuf::Message(), + _internal_metadata_(NULL) { + SharedCtor(); + MergeFrom(from); + // @@protoc_insertion_point(copy_constructor:examples.Point) +} + +void Point::SharedCtor() { + _is_default_instance_ = false; + _cached_size_ = 0; + latitude_ = 0; + longitude_ = 0; +} + +Point::~Point() { + // @@protoc_insertion_point(destructor:examples.Point) + SharedDtor(); +} + +void Point::SharedDtor() { + if (this != default_instance_) { + } +} + +void Point::SetCachedSize(int size) const { + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); +} +const ::google::protobuf::Descriptor* Point::descriptor() { + protobuf_AssignDescriptorsOnce(); + return Point_descriptor_; +} + +const Point& Point::default_instance() { + if (default_instance_ == NULL) protobuf_AddDesc_route_5fguide_2eproto(); + return *default_instance_; +} + +Point* Point::default_instance_ = NULL; + +Point* Point::New(::google::protobuf::Arena* arena) const { + Point* n = new Point; + if (arena != NULL) { + arena->Own(n); + } + return n; +} + +void Point::Clear() { +#define OFFSET_OF_FIELD_(f) (reinterpret_cast( \ + &reinterpret_cast(16)->f) - \ + reinterpret_cast(16)) + +#define ZR_(first, last) do { \ + size_t f = OFFSET_OF_FIELD_(first); \ + size_t n = OFFSET_OF_FIELD_(last) - f + sizeof(last); \ + ::memset(&first, 0, n); \ + } while (0) + + ZR_(latitude_, longitude_); + +#undef OFFSET_OF_FIELD_ +#undef ZR_ + +} + +bool Point::MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) { +#define DO_(EXPRESSION) if (!(EXPRESSION)) goto failure + ::google::protobuf::uint32 tag; + // @@protoc_insertion_point(parse_start:examples.Point) + for (;;) { + ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127); + tag = p.first; + if (!p.second) goto handle_unusual; + switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { + // optional int32 latitude = 1; + case 1: { + if (tag == 8) { + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( + input, &latitude_))); + + } else { + goto handle_unusual; + } + if (input->ExpectTag(16)) goto parse_longitude; + break; + } + + // optional int32 longitude = 2; + case 2: { + if (tag == 16) { + parse_longitude: + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( + input, &longitude_))); + + } else { + goto handle_unusual; + } + if (input->ExpectAtEnd()) goto success; + break; + } + + default: { + handle_unusual: + if (tag == 0 || + ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == + ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + goto success; + } + DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + break; + } + } + } +success: + // @@protoc_insertion_point(parse_success:examples.Point) + return true; +failure: + // @@protoc_insertion_point(parse_failure:examples.Point) + return false; +#undef DO_ +} + +void Point::SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const { + // @@protoc_insertion_point(serialize_start:examples.Point) + // optional int32 latitude = 1; + if (this->latitude() != 0) { + ::google::protobuf::internal::WireFormatLite::WriteInt32(1, this->latitude(), output); + } + + // optional int32 longitude = 2; + if (this->longitude() != 0) { + ::google::protobuf::internal::WireFormatLite::WriteInt32(2, this->longitude(), output); + } + + // @@protoc_insertion_point(serialize_end:examples.Point) +} + +::google::protobuf::uint8* Point::SerializeWithCachedSizesToArray( + ::google::protobuf::uint8* target) const { + // @@protoc_insertion_point(serialize_to_array_start:examples.Point) + // optional int32 latitude = 1; + if (this->latitude() != 0) { + target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(1, this->latitude(), target); + } + + // optional int32 longitude = 2; + if (this->longitude() != 0) { + target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(2, this->longitude(), target); + } + + // @@protoc_insertion_point(serialize_to_array_end:examples.Point) + return target; +} + +int Point::ByteSize() const { + int total_size = 0; + + // optional int32 latitude = 1; + if (this->latitude() != 0) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::Int32Size( + this->latitude()); + } + + // optional int32 longitude = 2; + if (this->longitude() != 0) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::Int32Size( + this->longitude()); + } + + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = total_size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); + return total_size; +} + +void Point::MergeFrom(const ::google::protobuf::Message& from) { + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const Point* source = + ::google::protobuf::internal::dynamic_cast_if_available( + &from); + if (source == NULL) { + ::google::protobuf::internal::ReflectionOps::Merge(from, this); + } else { + MergeFrom(*source); + } +} + +void Point::MergeFrom(const Point& from) { + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (from.latitude() != 0) { + set_latitude(from.latitude()); + } + if (from.longitude() != 0) { + set_longitude(from.longitude()); + } +} + +void Point::CopyFrom(const ::google::protobuf::Message& from) { + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +void Point::CopyFrom(const Point& from) { + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool Point::IsInitialized() const { + + return true; +} + +void Point::Swap(Point* other) { + if (other == this) return; + InternalSwap(other); +} +void Point::InternalSwap(Point* other) { + std::swap(latitude_, other->latitude_); + std::swap(longitude_, other->longitude_); + _internal_metadata_.Swap(&other->_internal_metadata_); + std::swap(_cached_size_, other->_cached_size_); +} + +::google::protobuf::Metadata Point::GetMetadata() const { + protobuf_AssignDescriptorsOnce(); + ::google::protobuf::Metadata metadata; + metadata.descriptor = Point_descriptor_; + metadata.reflection = Point_reflection_; + return metadata; +} + + +// =================================================================== + +#ifndef _MSC_VER +const int Rectangle::kLoFieldNumber; +const int Rectangle::kHiFieldNumber; +#endif // !_MSC_VER + +Rectangle::Rectangle() + : ::google::protobuf::Message() , _internal_metadata_(NULL) { + SharedCtor(); + // @@protoc_insertion_point(constructor:examples.Rectangle) +} + +void Rectangle::InitAsDefaultInstance() { + _is_default_instance_ = true; + lo_ = const_cast< ::examples::Point*>(&::examples::Point::default_instance()); + hi_ = const_cast< ::examples::Point*>(&::examples::Point::default_instance()); +} + +Rectangle::Rectangle(const Rectangle& from) + : ::google::protobuf::Message(), + _internal_metadata_(NULL) { + SharedCtor(); + MergeFrom(from); + // @@protoc_insertion_point(copy_constructor:examples.Rectangle) +} + +void Rectangle::SharedCtor() { + _is_default_instance_ = false; + _cached_size_ = 0; + lo_ = NULL; + hi_ = NULL; +} + +Rectangle::~Rectangle() { + // @@protoc_insertion_point(destructor:examples.Rectangle) + SharedDtor(); +} + +void Rectangle::SharedDtor() { + if (this != default_instance_) { + delete lo_; + delete hi_; + } +} + +void Rectangle::SetCachedSize(int size) const { + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); +} +const ::google::protobuf::Descriptor* Rectangle::descriptor() { + protobuf_AssignDescriptorsOnce(); + return Rectangle_descriptor_; +} + +const Rectangle& Rectangle::default_instance() { + if (default_instance_ == NULL) protobuf_AddDesc_route_5fguide_2eproto(); + return *default_instance_; +} + +Rectangle* Rectangle::default_instance_ = NULL; + +Rectangle* Rectangle::New(::google::protobuf::Arena* arena) const { + Rectangle* n = new Rectangle; + if (arena != NULL) { + arena->Own(n); + } + return n; +} + +void Rectangle::Clear() { + if (lo_ != NULL) delete lo_; + lo_ = NULL; + if (hi_ != NULL) delete hi_; + hi_ = NULL; +} + +bool Rectangle::MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) { +#define DO_(EXPRESSION) if (!(EXPRESSION)) goto failure + ::google::protobuf::uint32 tag; + // @@protoc_insertion_point(parse_start:examples.Rectangle) + for (;;) { + ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127); + tag = p.first; + if (!p.second) goto handle_unusual; + switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { + // optional .examples.Point lo = 1; + case 1: { + if (tag == 10) { + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + input, mutable_lo())); + } else { + goto handle_unusual; + } + if (input->ExpectTag(18)) goto parse_hi; + break; + } + + // optional .examples.Point hi = 2; + case 2: { + if (tag == 18) { + parse_hi: + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + input, mutable_hi())); + } else { + goto handle_unusual; + } + if (input->ExpectAtEnd()) goto success; + break; + } + + default: { + handle_unusual: + if (tag == 0 || + ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == + ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + goto success; + } + DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + break; + } + } + } +success: + // @@protoc_insertion_point(parse_success:examples.Rectangle) + return true; +failure: + // @@protoc_insertion_point(parse_failure:examples.Rectangle) + return false; +#undef DO_ +} + +void Rectangle::SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const { + // @@protoc_insertion_point(serialize_start:examples.Rectangle) + // optional .examples.Point lo = 1; + if (this->has_lo()) { + ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( + 1, *this->lo_, output); + } + + // optional .examples.Point hi = 2; + if (this->has_hi()) { + ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( + 2, *this->hi_, output); + } + + // @@protoc_insertion_point(serialize_end:examples.Rectangle) +} + +::google::protobuf::uint8* Rectangle::SerializeWithCachedSizesToArray( + ::google::protobuf::uint8* target) const { + // @@protoc_insertion_point(serialize_to_array_start:examples.Rectangle) + // optional .examples.Point lo = 1; + if (this->has_lo()) { + target = ::google::protobuf::internal::WireFormatLite:: + WriteMessageNoVirtualToArray( + 1, *this->lo_, target); + } + + // optional .examples.Point hi = 2; + if (this->has_hi()) { + target = ::google::protobuf::internal::WireFormatLite:: + WriteMessageNoVirtualToArray( + 2, *this->hi_, target); + } + + // @@protoc_insertion_point(serialize_to_array_end:examples.Rectangle) + return target; +} + +int Rectangle::ByteSize() const { + int total_size = 0; + + // optional .examples.Point lo = 1; + if (this->has_lo()) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + *this->lo_); + } + + // optional .examples.Point hi = 2; + if (this->has_hi()) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + *this->hi_); + } + + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = total_size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); + return total_size; +} + +void Rectangle::MergeFrom(const ::google::protobuf::Message& from) { + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const Rectangle* source = + ::google::protobuf::internal::dynamic_cast_if_available( + &from); + if (source == NULL) { + ::google::protobuf::internal::ReflectionOps::Merge(from, this); + } else { + MergeFrom(*source); + } +} + +void Rectangle::MergeFrom(const Rectangle& from) { + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (from.has_lo()) { + mutable_lo()->::examples::Point::MergeFrom(from.lo()); + } + if (from.has_hi()) { + mutable_hi()->::examples::Point::MergeFrom(from.hi()); + } +} + +void Rectangle::CopyFrom(const ::google::protobuf::Message& from) { + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +void Rectangle::CopyFrom(const Rectangle& from) { + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool Rectangle::IsInitialized() const { + + return true; +} + +void Rectangle::Swap(Rectangle* other) { + if (other == this) return; + InternalSwap(other); +} +void Rectangle::InternalSwap(Rectangle* other) { + std::swap(lo_, other->lo_); + std::swap(hi_, other->hi_); + _internal_metadata_.Swap(&other->_internal_metadata_); + std::swap(_cached_size_, other->_cached_size_); +} + +::google::protobuf::Metadata Rectangle::GetMetadata() const { + protobuf_AssignDescriptorsOnce(); + ::google::protobuf::Metadata metadata; + metadata.descriptor = Rectangle_descriptor_; + metadata.reflection = Rectangle_reflection_; + return metadata; +} + + +// =================================================================== + +#ifndef _MSC_VER +const int Feature::kNameFieldNumber; +const int Feature::kLocationFieldNumber; +#endif // !_MSC_VER + +Feature::Feature() + : ::google::protobuf::Message() , _internal_metadata_(NULL) { + SharedCtor(); + // @@protoc_insertion_point(constructor:examples.Feature) +} + +void Feature::InitAsDefaultInstance() { + _is_default_instance_ = true; + location_ = const_cast< ::examples::Point*>(&::examples::Point::default_instance()); +} + +Feature::Feature(const Feature& from) + : ::google::protobuf::Message(), + _internal_metadata_(NULL) { + SharedCtor(); + MergeFrom(from); + // @@protoc_insertion_point(copy_constructor:examples.Feature) +} + +void Feature::SharedCtor() { + _is_default_instance_ = false; + ::google::protobuf::internal::GetEmptyString(); + _cached_size_ = 0; + name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + location_ = NULL; +} + +Feature::~Feature() { + // @@protoc_insertion_point(destructor:examples.Feature) + SharedDtor(); +} + +void Feature::SharedDtor() { + name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + if (this != default_instance_) { + delete location_; + } +} + +void Feature::SetCachedSize(int size) const { + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); +} +const ::google::protobuf::Descriptor* Feature::descriptor() { + protobuf_AssignDescriptorsOnce(); + return Feature_descriptor_; +} + +const Feature& Feature::default_instance() { + if (default_instance_ == NULL) protobuf_AddDesc_route_5fguide_2eproto(); + return *default_instance_; +} + +Feature* Feature::default_instance_ = NULL; + +Feature* Feature::New(::google::protobuf::Arena* arena) const { + Feature* n = new Feature; + if (arena != NULL) { + arena->Own(n); + } + return n; +} + +void Feature::Clear() { + name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + if (location_ != NULL) delete location_; + location_ = NULL; +} + +bool Feature::MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) { +#define DO_(EXPRESSION) if (!(EXPRESSION)) goto failure + ::google::protobuf::uint32 tag; + // @@protoc_insertion_point(parse_start:examples.Feature) + for (;;) { + ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127); + tag = p.first; + if (!p.second) goto handle_unusual; + switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { + // optional string name = 1; + case 1: { + if (tag == 10) { + DO_(::google::protobuf::internal::WireFormatLite::ReadString( + input, this->mutable_name())); + ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( + this->name().data(), this->name().length(), + ::google::protobuf::internal::WireFormat::PARSE, + "examples.Feature.name"); + } else { + goto handle_unusual; + } + if (input->ExpectTag(18)) goto parse_location; + break; + } + + // optional .examples.Point location = 2; + case 2: { + if (tag == 18) { + parse_location: + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + input, mutable_location())); + } else { + goto handle_unusual; + } + if (input->ExpectAtEnd()) goto success; + break; + } + + default: { + handle_unusual: + if (tag == 0 || + ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == + ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + goto success; + } + DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + break; + } + } + } +success: + // @@protoc_insertion_point(parse_success:examples.Feature) + return true; +failure: + // @@protoc_insertion_point(parse_failure:examples.Feature) + return false; +#undef DO_ +} + +void Feature::SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const { + // @@protoc_insertion_point(serialize_start:examples.Feature) + // optional string name = 1; + if (this->name().size() > 0) { + ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( + this->name().data(), this->name().length(), + ::google::protobuf::internal::WireFormat::SERIALIZE, + "examples.Feature.name"); + ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased( + 1, this->name(), output); + } + + // optional .examples.Point location = 2; + if (this->has_location()) { + ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( + 2, *this->location_, output); + } + + // @@protoc_insertion_point(serialize_end:examples.Feature) +} + +::google::protobuf::uint8* Feature::SerializeWithCachedSizesToArray( + ::google::protobuf::uint8* target) const { + // @@protoc_insertion_point(serialize_to_array_start:examples.Feature) + // optional string name = 1; + if (this->name().size() > 0) { + ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( + this->name().data(), this->name().length(), + ::google::protobuf::internal::WireFormat::SERIALIZE, + "examples.Feature.name"); + target = + ::google::protobuf::internal::WireFormatLite::WriteStringToArray( + 1, this->name(), target); + } + + // optional .examples.Point location = 2; + if (this->has_location()) { + target = ::google::protobuf::internal::WireFormatLite:: + WriteMessageNoVirtualToArray( + 2, *this->location_, target); + } + + // @@protoc_insertion_point(serialize_to_array_end:examples.Feature) + return target; +} + +int Feature::ByteSize() const { + int total_size = 0; + + // optional string name = 1; + if (this->name().size() > 0) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::StringSize( + this->name()); + } + + // optional .examples.Point location = 2; + if (this->has_location()) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + *this->location_); + } + + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = total_size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); + return total_size; +} + +void Feature::MergeFrom(const ::google::protobuf::Message& from) { + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const Feature* source = + ::google::protobuf::internal::dynamic_cast_if_available( + &from); + if (source == NULL) { + ::google::protobuf::internal::ReflectionOps::Merge(from, this); + } else { + MergeFrom(*source); + } +} + +void Feature::MergeFrom(const Feature& from) { + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (from.name().size() > 0) { + + name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_); + } + if (from.has_location()) { + mutable_location()->::examples::Point::MergeFrom(from.location()); + } +} + +void Feature::CopyFrom(const ::google::protobuf::Message& from) { + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +void Feature::CopyFrom(const Feature& from) { + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool Feature::IsInitialized() const { + + return true; +} + +void Feature::Swap(Feature* other) { + if (other == this) return; + InternalSwap(other); +} +void Feature::InternalSwap(Feature* other) { + name_.Swap(&other->name_); + std::swap(location_, other->location_); + _internal_metadata_.Swap(&other->_internal_metadata_); + std::swap(_cached_size_, other->_cached_size_); +} + +::google::protobuf::Metadata Feature::GetMetadata() const { + protobuf_AssignDescriptorsOnce(); + ::google::protobuf::Metadata metadata; + metadata.descriptor = Feature_descriptor_; + metadata.reflection = Feature_reflection_; + return metadata; +} + + +// =================================================================== + +#ifndef _MSC_VER +const int RouteNote::kLocationFieldNumber; +const int RouteNote::kMessageFieldNumber; +#endif // !_MSC_VER + +RouteNote::RouteNote() + : ::google::protobuf::Message() , _internal_metadata_(NULL) { + SharedCtor(); + // @@protoc_insertion_point(constructor:examples.RouteNote) +} + +void RouteNote::InitAsDefaultInstance() { + _is_default_instance_ = true; + location_ = const_cast< ::examples::Point*>(&::examples::Point::default_instance()); +} + +RouteNote::RouteNote(const RouteNote& from) + : ::google::protobuf::Message(), + _internal_metadata_(NULL) { + SharedCtor(); + MergeFrom(from); + // @@protoc_insertion_point(copy_constructor:examples.RouteNote) +} + +void RouteNote::SharedCtor() { + _is_default_instance_ = false; + ::google::protobuf::internal::GetEmptyString(); + _cached_size_ = 0; + location_ = NULL; + message_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} + +RouteNote::~RouteNote() { + // @@protoc_insertion_point(destructor:examples.RouteNote) + SharedDtor(); +} + +void RouteNote::SharedDtor() { + message_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + if (this != default_instance_) { + delete location_; + } +} + +void RouteNote::SetCachedSize(int size) const { + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); +} +const ::google::protobuf::Descriptor* RouteNote::descriptor() { + protobuf_AssignDescriptorsOnce(); + return RouteNote_descriptor_; +} + +const RouteNote& RouteNote::default_instance() { + if (default_instance_ == NULL) protobuf_AddDesc_route_5fguide_2eproto(); + return *default_instance_; +} + +RouteNote* RouteNote::default_instance_ = NULL; + +RouteNote* RouteNote::New(::google::protobuf::Arena* arena) const { + RouteNote* n = new RouteNote; + if (arena != NULL) { + arena->Own(n); + } + return n; +} + +void RouteNote::Clear() { + if (location_ != NULL) delete location_; + location_ = NULL; + message_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} + +bool RouteNote::MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) { +#define DO_(EXPRESSION) if (!(EXPRESSION)) goto failure + ::google::protobuf::uint32 tag; + // @@protoc_insertion_point(parse_start:examples.RouteNote) + for (;;) { + ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127); + tag = p.first; + if (!p.second) goto handle_unusual; + switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { + // optional .examples.Point location = 1; + case 1: { + if (tag == 10) { + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + input, mutable_location())); + } else { + goto handle_unusual; + } + if (input->ExpectTag(18)) goto parse_message; + break; + } + + // optional string message = 2; + case 2: { + if (tag == 18) { + parse_message: + DO_(::google::protobuf::internal::WireFormatLite::ReadString( + input, this->mutable_message())); + ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( + this->message().data(), this->message().length(), + ::google::protobuf::internal::WireFormat::PARSE, + "examples.RouteNote.message"); + } else { + goto handle_unusual; + } + if (input->ExpectAtEnd()) goto success; + break; + } + + default: { + handle_unusual: + if (tag == 0 || + ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == + ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + goto success; + } + DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + break; + } + } + } +success: + // @@protoc_insertion_point(parse_success:examples.RouteNote) + return true; +failure: + // @@protoc_insertion_point(parse_failure:examples.RouteNote) + return false; +#undef DO_ +} + +void RouteNote::SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const { + // @@protoc_insertion_point(serialize_start:examples.RouteNote) + // optional .examples.Point location = 1; + if (this->has_location()) { + ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( + 1, *this->location_, output); + } + + // optional string message = 2; + if (this->message().size() > 0) { + ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( + this->message().data(), this->message().length(), + ::google::protobuf::internal::WireFormat::SERIALIZE, + "examples.RouteNote.message"); + ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased( + 2, this->message(), output); + } + + // @@protoc_insertion_point(serialize_end:examples.RouteNote) +} + +::google::protobuf::uint8* RouteNote::SerializeWithCachedSizesToArray( + ::google::protobuf::uint8* target) const { + // @@protoc_insertion_point(serialize_to_array_start:examples.RouteNote) + // optional .examples.Point location = 1; + if (this->has_location()) { + target = ::google::protobuf::internal::WireFormatLite:: + WriteMessageNoVirtualToArray( + 1, *this->location_, target); + } + + // optional string message = 2; + if (this->message().size() > 0) { + ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( + this->message().data(), this->message().length(), + ::google::protobuf::internal::WireFormat::SERIALIZE, + "examples.RouteNote.message"); + target = + ::google::protobuf::internal::WireFormatLite::WriteStringToArray( + 2, this->message(), target); + } + + // @@protoc_insertion_point(serialize_to_array_end:examples.RouteNote) + return target; +} + +int RouteNote::ByteSize() const { + int total_size = 0; + + // optional .examples.Point location = 1; + if (this->has_location()) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + *this->location_); + } + + // optional string message = 2; + if (this->message().size() > 0) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::StringSize( + this->message()); + } + + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = total_size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); + return total_size; +} + +void RouteNote::MergeFrom(const ::google::protobuf::Message& from) { + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const RouteNote* source = + ::google::protobuf::internal::dynamic_cast_if_available( + &from); + if (source == NULL) { + ::google::protobuf::internal::ReflectionOps::Merge(from, this); + } else { + MergeFrom(*source); + } +} + +void RouteNote::MergeFrom(const RouteNote& from) { + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (from.has_location()) { + mutable_location()->::examples::Point::MergeFrom(from.location()); + } + if (from.message().size() > 0) { + + message_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.message_); + } +} + +void RouteNote::CopyFrom(const ::google::protobuf::Message& from) { + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +void RouteNote::CopyFrom(const RouteNote& from) { + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool RouteNote::IsInitialized() const { + + return true; +} + +void RouteNote::Swap(RouteNote* other) { + if (other == this) return; + InternalSwap(other); +} +void RouteNote::InternalSwap(RouteNote* other) { + std::swap(location_, other->location_); + message_.Swap(&other->message_); + _internal_metadata_.Swap(&other->_internal_metadata_); + std::swap(_cached_size_, other->_cached_size_); +} + +::google::protobuf::Metadata RouteNote::GetMetadata() const { + protobuf_AssignDescriptorsOnce(); + ::google::protobuf::Metadata metadata; + metadata.descriptor = RouteNote_descriptor_; + metadata.reflection = RouteNote_reflection_; + return metadata; +} + + +// =================================================================== + +#ifndef _MSC_VER +const int RouteSummary::kPointCountFieldNumber; +const int RouteSummary::kFeatureCountFieldNumber; +const int RouteSummary::kDistanceFieldNumber; +const int RouteSummary::kElapsedTimeFieldNumber; +#endif // !_MSC_VER + +RouteSummary::RouteSummary() + : ::google::protobuf::Message() , _internal_metadata_(NULL) { + SharedCtor(); + // @@protoc_insertion_point(constructor:examples.RouteSummary) +} + +void RouteSummary::InitAsDefaultInstance() { + _is_default_instance_ = true; +} + +RouteSummary::RouteSummary(const RouteSummary& from) + : ::google::protobuf::Message(), + _internal_metadata_(NULL) { + SharedCtor(); + MergeFrom(from); + // @@protoc_insertion_point(copy_constructor:examples.RouteSummary) +} + +void RouteSummary::SharedCtor() { + _is_default_instance_ = false; + _cached_size_ = 0; + point_count_ = 0; + feature_count_ = 0; + distance_ = 0; + elapsed_time_ = 0; +} + +RouteSummary::~RouteSummary() { + // @@protoc_insertion_point(destructor:examples.RouteSummary) + SharedDtor(); +} + +void RouteSummary::SharedDtor() { + if (this != default_instance_) { + } +} + +void RouteSummary::SetCachedSize(int size) const { + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); +} +const ::google::protobuf::Descriptor* RouteSummary::descriptor() { + protobuf_AssignDescriptorsOnce(); + return RouteSummary_descriptor_; +} + +const RouteSummary& RouteSummary::default_instance() { + if (default_instance_ == NULL) protobuf_AddDesc_route_5fguide_2eproto(); + return *default_instance_; +} + +RouteSummary* RouteSummary::default_instance_ = NULL; + +RouteSummary* RouteSummary::New(::google::protobuf::Arena* arena) const { + RouteSummary* n = new RouteSummary; + if (arena != NULL) { + arena->Own(n); + } + return n; +} + +void RouteSummary::Clear() { +#define OFFSET_OF_FIELD_(f) (reinterpret_cast( \ + &reinterpret_cast(16)->f) - \ + reinterpret_cast(16)) + +#define ZR_(first, last) do { \ + size_t f = OFFSET_OF_FIELD_(first); \ + size_t n = OFFSET_OF_FIELD_(last) - f + sizeof(last); \ + ::memset(&first, 0, n); \ + } while (0) + + ZR_(point_count_, elapsed_time_); + +#undef OFFSET_OF_FIELD_ +#undef ZR_ + +} + +bool RouteSummary::MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) { +#define DO_(EXPRESSION) if (!(EXPRESSION)) goto failure + ::google::protobuf::uint32 tag; + // @@protoc_insertion_point(parse_start:examples.RouteSummary) + for (;;) { + ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127); + tag = p.first; + if (!p.second) goto handle_unusual; + switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { + // optional int32 point_count = 1; + case 1: { + if (tag == 8) { + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( + input, &point_count_))); + + } else { + goto handle_unusual; + } + if (input->ExpectTag(16)) goto parse_feature_count; + break; + } + + // optional int32 feature_count = 2; + case 2: { + if (tag == 16) { + parse_feature_count: + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( + input, &feature_count_))); + + } else { + goto handle_unusual; + } + if (input->ExpectTag(24)) goto parse_distance; + break; + } + + // optional int32 distance = 3; + case 3: { + if (tag == 24) { + parse_distance: + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( + input, &distance_))); + + } else { + goto handle_unusual; + } + if (input->ExpectTag(32)) goto parse_elapsed_time; + break; + } + + // optional int32 elapsed_time = 4; + case 4: { + if (tag == 32) { + parse_elapsed_time: + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( + input, &elapsed_time_))); + + } else { + goto handle_unusual; + } + if (input->ExpectAtEnd()) goto success; + break; + } + + default: { + handle_unusual: + if (tag == 0 || + ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == + ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + goto success; + } + DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + break; + } + } + } +success: + // @@protoc_insertion_point(parse_success:examples.RouteSummary) + return true; +failure: + // @@protoc_insertion_point(parse_failure:examples.RouteSummary) + return false; +#undef DO_ +} + +void RouteSummary::SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const { + // @@protoc_insertion_point(serialize_start:examples.RouteSummary) + // optional int32 point_count = 1; + if (this->point_count() != 0) { + ::google::protobuf::internal::WireFormatLite::WriteInt32(1, this->point_count(), output); + } + + // optional int32 feature_count = 2; + if (this->feature_count() != 0) { + ::google::protobuf::internal::WireFormatLite::WriteInt32(2, this->feature_count(), output); + } + + // optional int32 distance = 3; + if (this->distance() != 0) { + ::google::protobuf::internal::WireFormatLite::WriteInt32(3, this->distance(), output); + } + + // optional int32 elapsed_time = 4; + if (this->elapsed_time() != 0) { + ::google::protobuf::internal::WireFormatLite::WriteInt32(4, this->elapsed_time(), output); + } + + // @@protoc_insertion_point(serialize_end:examples.RouteSummary) +} + +::google::protobuf::uint8* RouteSummary::SerializeWithCachedSizesToArray( + ::google::protobuf::uint8* target) const { + // @@protoc_insertion_point(serialize_to_array_start:examples.RouteSummary) + // optional int32 point_count = 1; + if (this->point_count() != 0) { + target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(1, this->point_count(), target); + } + + // optional int32 feature_count = 2; + if (this->feature_count() != 0) { + target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(2, this->feature_count(), target); + } + + // optional int32 distance = 3; + if (this->distance() != 0) { + target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(3, this->distance(), target); + } + + // optional int32 elapsed_time = 4; + if (this->elapsed_time() != 0) { + target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(4, this->elapsed_time(), target); + } + + // @@protoc_insertion_point(serialize_to_array_end:examples.RouteSummary) + return target; +} + +int RouteSummary::ByteSize() const { + int total_size = 0; + + // optional int32 point_count = 1; + if (this->point_count() != 0) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::Int32Size( + this->point_count()); + } + + // optional int32 feature_count = 2; + if (this->feature_count() != 0) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::Int32Size( + this->feature_count()); + } + + // optional int32 distance = 3; + if (this->distance() != 0) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::Int32Size( + this->distance()); + } + + // optional int32 elapsed_time = 4; + if (this->elapsed_time() != 0) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::Int32Size( + this->elapsed_time()); + } + + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = total_size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); + return total_size; +} + +void RouteSummary::MergeFrom(const ::google::protobuf::Message& from) { + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const RouteSummary* source = + ::google::protobuf::internal::dynamic_cast_if_available( + &from); + if (source == NULL) { + ::google::protobuf::internal::ReflectionOps::Merge(from, this); + } else { + MergeFrom(*source); + } +} + +void RouteSummary::MergeFrom(const RouteSummary& from) { + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (from.point_count() != 0) { + set_point_count(from.point_count()); + } + if (from.feature_count() != 0) { + set_feature_count(from.feature_count()); + } + if (from.distance() != 0) { + set_distance(from.distance()); + } + if (from.elapsed_time() != 0) { + set_elapsed_time(from.elapsed_time()); + } +} + +void RouteSummary::CopyFrom(const ::google::protobuf::Message& from) { + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +void RouteSummary::CopyFrom(const RouteSummary& from) { + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool RouteSummary::IsInitialized() const { + + return true; +} + +void RouteSummary::Swap(RouteSummary* other) { + if (other == this) return; + InternalSwap(other); +} +void RouteSummary::InternalSwap(RouteSummary* other) { + std::swap(point_count_, other->point_count_); + std::swap(feature_count_, other->feature_count_); + std::swap(distance_, other->distance_); + std::swap(elapsed_time_, other->elapsed_time_); + _internal_metadata_.Swap(&other->_internal_metadata_); + std::swap(_cached_size_, other->_cached_size_); +} + +::google::protobuf::Metadata RouteSummary::GetMetadata() const { + protobuf_AssignDescriptorsOnce(); + ::google::protobuf::Metadata metadata; + metadata.descriptor = RouteSummary_descriptor_; + metadata.reflection = RouteSummary_reflection_; + return metadata; +} + + +static const char* RouteGuide_method_names[] = { + "/examples.RouteGuide/GetFeature", + "/examples.RouteGuide/ListFeatures", + "/examples.RouteGuide/RecordRoute", + "/examples.RouteGuide/RouteChat", +}; + +RouteGuide::Stub* RouteGuide::NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel) { + RouteGuide::Stub* stub = new RouteGuide::Stub(); + stub->set_channel(channel); + return stub; +}; + +::grpc::Status RouteGuide::Stub::GetFeature(::grpc::ClientContext* context, const ::examples::Point& request, ::examples::Feature* response) { + return ::grpc::BlockingUnaryCall(channel(),::grpc::RpcMethod(RouteGuide_method_names[0]), context, request, response); +} + +::grpc::ClientAsyncResponseReader< ::examples::Feature>* RouteGuide::Stub::GetFeature(::grpc::ClientContext* context, const ::examples::Point& request, ::grpc::CompletionQueue* cq, void* tag) { + return new ::grpc::ClientAsyncResponseReader< ::examples::Feature>(channel(), cq, ::grpc::RpcMethod(RouteGuide_method_names[0]), context, request, tag); +} + +::grpc::ClientReader< ::examples::Feature>* RouteGuide::Stub::ListFeatures(::grpc::ClientContext* context, const ::examples::Rectangle& request) { + return new ::grpc::ClientReader< ::examples::Feature>(channel(),::grpc::RpcMethod(RouteGuide_method_names[1], ::grpc::RpcMethod::RpcType::SERVER_STREAMING), context, request); +} + +::grpc::ClientAsyncReader< ::examples::Feature>* RouteGuide::Stub::ListFeatures(::grpc::ClientContext* context, const ::examples::Rectangle& request, ::grpc::CompletionQueue* cq, void* tag) { + return new ::grpc::ClientAsyncReader< ::examples::Feature>(channel(), cq, ::grpc::RpcMethod(RouteGuide_method_names[1], ::grpc::RpcMethod::RpcType::SERVER_STREAMING), context, request, tag); +} + +::grpc::ClientWriter< ::examples::Point>* RouteGuide::Stub::RecordRoute(::grpc::ClientContext* context, ::examples::RouteSummary* response) { + return new ::grpc::ClientWriter< ::examples::Point>(channel(),::grpc::RpcMethod(RouteGuide_method_names[2], ::grpc::RpcMethod::RpcType::CLIENT_STREAMING), context, response); +} + +::grpc::ClientAsyncWriter< ::examples::Point>* RouteGuide::Stub::RecordRoute(::grpc::ClientContext* context, ::examples::RouteSummary* response, ::grpc::CompletionQueue* cq, void* tag) { + return new ::grpc::ClientAsyncWriter< ::examples::Point>(channel(), cq, ::grpc::RpcMethod(RouteGuide_method_names[2], ::grpc::RpcMethod::RpcType::CLIENT_STREAMING), context, response, tag); +} + +::grpc::ClientReaderWriter< ::examples::RouteNote, ::examples::RouteNote>* RouteGuide::Stub::RouteChat(::grpc::ClientContext* context) { + return new ::grpc::ClientReaderWriter< ::examples::RouteNote, ::examples::RouteNote>(channel(),::grpc::RpcMethod(RouteGuide_method_names[3], ::grpc::RpcMethod::RpcType::BIDI_STREAMING), context); +} + +::grpc::ClientAsyncReaderWriter< ::examples::RouteNote, ::examples::RouteNote>* RouteGuide::Stub::RouteChat(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) { + return new ::grpc::ClientAsyncReaderWriter< ::examples::RouteNote, ::examples::RouteNote>(channel(), cq, ::grpc::RpcMethod(RouteGuide_method_names[3], ::grpc::RpcMethod::RpcType::BIDI_STREAMING), context, tag); +} + +RouteGuide::AsyncService::AsyncService(::grpc::CompletionQueue* cq) : ::grpc::AsynchronousService(cq, RouteGuide_method_names, 4) {} + +RouteGuide::Service::~Service() { + delete service_; +} + +::grpc::Status RouteGuide::Service::GetFeature(::grpc::ServerContext* context, const ::examples::Point* request, ::examples::Feature* response) { + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED); +} + +void RouteGuide::AsyncService::RequestGetFeature(::grpc::ServerContext* context, ::examples::Point* request, ::grpc::ServerAsyncResponseWriter< ::examples::Feature>* response, ::grpc::CompletionQueue* cq, void* tag) { + AsynchronousService::RequestAsyncUnary(0, context, request, response, cq, tag); +} + +::grpc::Status RouteGuide::Service::ListFeatures(::grpc::ServerContext* context, const ::examples::Rectangle* request, ::grpc::ServerWriter< ::examples::Feature>* writer) { + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED); +} + +void RouteGuide::AsyncService::RequestListFeatures(::grpc::ServerContext* context, ::examples::Rectangle* request, ::grpc::ServerAsyncWriter< ::examples::Feature>* writer, ::grpc::CompletionQueue* cq, void* tag) { + AsynchronousService::RequestServerStreaming(1, context, request, writer, cq, tag); +} + +::grpc::Status RouteGuide::Service::RecordRoute(::grpc::ServerContext* context, ::grpc::ServerReader< ::examples::Point>* reader, ::examples::RouteSummary* response) { + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED); +} + +void RouteGuide::AsyncService::RequestRecordRoute(::grpc::ServerContext* context, ::grpc::ServerAsyncReader< ::examples::RouteSummary, ::examples::Point>* reader, ::grpc::CompletionQueue* cq, void* tag) { + AsynchronousService::RequestClientStreaming(2, context, reader, cq, tag); +} + +::grpc::Status RouteGuide::Service::RouteChat(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::examples::RouteNote, ::examples::RouteNote>* stream) { + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED); +} + +void RouteGuide::AsyncService::RequestRouteChat(::grpc::ServerContext* context, ::grpc::ServerAsyncReaderWriter< ::examples::RouteNote, ::examples::RouteNote>* stream, ::grpc::CompletionQueue* cq, void *tag) { + AsynchronousService::RequestBidiStreaming(3, context, stream, cq, tag); +} + +::grpc::RpcService* RouteGuide::Service::service() { + if (service_ != nullptr) { + return service_; + } + service_ = new ::grpc::RpcService(); + service_->AddMethod(new ::grpc::RpcServiceMethod( + RouteGuide_method_names[0], + ::grpc::RpcMethod::NORMAL_RPC, + new ::grpc::RpcMethodHandler< RouteGuide::Service, ::examples::Point, ::examples::Feature>( + std::function< ::grpc::Status(RouteGuide::Service*, ::grpc::ServerContext*, const ::examples::Point*, ::examples::Feature*)>(&RouteGuide::Service::GetFeature), this), + new ::examples::Point, new ::examples::Feature)); + service_->AddMethod(new ::grpc::RpcServiceMethod( + RouteGuide_method_names[1], + ::grpc::RpcMethod::SERVER_STREAMING, + new ::grpc::ServerStreamingHandler< RouteGuide::Service, ::examples::Rectangle, ::examples::Feature>( + std::function< ::grpc::Status(RouteGuide::Service*, ::grpc::ServerContext*, const ::examples::Rectangle*, ::grpc::ServerWriter< ::examples::Feature>*)>(&RouteGuide::Service::ListFeatures), this), + new ::examples::Rectangle, new ::examples::Feature)); + service_->AddMethod(new ::grpc::RpcServiceMethod( + RouteGuide_method_names[2], + ::grpc::RpcMethod::CLIENT_STREAMING, + new ::grpc::ClientStreamingHandler< RouteGuide::Service, ::examples::Point, ::examples::RouteSummary>( + std::function< ::grpc::Status(RouteGuide::Service*, ::grpc::ServerContext*, ::grpc::ServerReader< ::examples::Point>*, ::examples::RouteSummary*)>(&RouteGuide::Service::RecordRoute), this), + new ::examples::Point, new ::examples::RouteSummary)); + service_->AddMethod(new ::grpc::RpcServiceMethod( + RouteGuide_method_names[3], + ::grpc::RpcMethod::BIDI_STREAMING, + new ::grpc::BidiStreamingHandler< RouteGuide::Service, ::examples::RouteNote, ::examples::RouteNote>( + std::function< ::grpc::Status(RouteGuide::Service*, ::grpc::ServerContext*, ::grpc::ServerReaderWriter< ::examples::RouteNote, ::examples::RouteNote>*)>(&RouteGuide::Service::RouteChat), this), + new ::examples::RouteNote, new ::examples::RouteNote)); + return service_; +} + + +// @@protoc_insertion_point(namespace_scope) + +} // namespace examples + +// @@protoc_insertion_point(global_scope) diff --git a/cpp/route_guide/route_guide.pb.h b/cpp/route_guide/route_guide.pb.h new file mode 100644 index 0000000..7689003 --- /dev/null +++ b/cpp/route_guide/route_guide.pb.h @@ -0,0 +1,929 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: route_guide.proto + +#ifndef PROTOBUF_route_5fguide_2eproto__INCLUDED +#define PROTOBUF_route_5fguide_2eproto__INCLUDED + +#include + +#include + +#if GOOGLE_PROTOBUF_VERSION < 3000000 +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 3000000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace grpc { +class CompletionQueue; +class ChannelInterface; +class RpcService; +class ServerContext; +template class ClientAsyncResponseReader; +template class ServerAsyncResponseWriter; +template class ClientWriter; +template class ServerReader; +template class ClientAsyncWriter; +template class ServerAsyncReader; +template class ClientReader; +template class ServerWriter; +template class ClientAsyncReader; +template class ServerAsyncWriter; +template +class ClientReaderWriter; +template +class ServerReaderWriter; +template +class ClientAsyncReaderWriter; +template +class ServerAsyncReaderWriter; +} // namespace grpc +// @@protoc_insertion_point(includes) + +namespace examples { + +// Internal implementation detail -- do not call these. +void protobuf_AddDesc_route_5fguide_2eproto(); +void protobuf_AssignDesc_route_5fguide_2eproto(); +void protobuf_ShutdownFile_route_5fguide_2eproto(); + +class Point; +class Rectangle; +class Feature; +class RouteNote; +class RouteSummary; + +// =================================================================== + +class Point : public ::google::protobuf::Message { + public: + Point(); + virtual ~Point(); + + Point(const Point& from); + + inline Point& operator=(const Point& from) { + CopyFrom(from); + return *this; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const Point& default_instance(); + + void Swap(Point* other); + + // implements Message ---------------------------------------------- + + inline Point* New() const { return New(NULL); } + + Point* New(::google::protobuf::Arena* arena) const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const Point& from); + void MergeFrom(const Point& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + void InternalSwap(Point* other); + private: + inline ::google::protobuf::Arena* GetArenaNoVirtual() const { + return _internal_metadata_.arena(); + } + inline void* MaybeArenaPtr() const { + return _internal_metadata_.raw_arena_ptr(); + } + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 latitude = 1; + inline void clear_latitude(); + static const int kLatitudeFieldNumber = 1; + inline ::google::protobuf::int32 latitude() const; + inline void set_latitude(::google::protobuf::int32 value); + + // optional int32 longitude = 2; + inline void clear_longitude(); + static const int kLongitudeFieldNumber = 2; + inline ::google::protobuf::int32 longitude() const; + inline void set_longitude(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:examples.Point) + private: + + ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; + bool _is_default_instance_; + ::google::protobuf::int32 latitude_; + ::google::protobuf::int32 longitude_; + mutable int _cached_size_; + friend void protobuf_AddDesc_route_5fguide_2eproto(); + friend void protobuf_AssignDesc_route_5fguide_2eproto(); + friend void protobuf_ShutdownFile_route_5fguide_2eproto(); + + void InitAsDefaultInstance(); + static Point* default_instance_; +}; +// ------------------------------------------------------------------- + +class Rectangle : public ::google::protobuf::Message { + public: + Rectangle(); + virtual ~Rectangle(); + + Rectangle(const Rectangle& from); + + inline Rectangle& operator=(const Rectangle& from) { + CopyFrom(from); + return *this; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const Rectangle& default_instance(); + + void Swap(Rectangle* other); + + // implements Message ---------------------------------------------- + + inline Rectangle* New() const { return New(NULL); } + + Rectangle* New(::google::protobuf::Arena* arena) const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const Rectangle& from); + void MergeFrom(const Rectangle& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + void InternalSwap(Rectangle* other); + private: + inline ::google::protobuf::Arena* GetArenaNoVirtual() const { + return _internal_metadata_.arena(); + } + inline void* MaybeArenaPtr() const { + return _internal_metadata_.raw_arena_ptr(); + } + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional .examples.Point lo = 1; + inline bool has_lo() const; + inline void clear_lo(); + static const int kLoFieldNumber = 1; + inline const ::examples::Point& lo() const; + inline ::examples::Point* mutable_lo(); + inline ::examples::Point* release_lo(); + inline void set_allocated_lo(::examples::Point* lo); + + // optional .examples.Point hi = 2; + inline bool has_hi() const; + inline void clear_hi(); + static const int kHiFieldNumber = 2; + inline const ::examples::Point& hi() const; + inline ::examples::Point* mutable_hi(); + inline ::examples::Point* release_hi(); + inline void set_allocated_hi(::examples::Point* hi); + + // @@protoc_insertion_point(class_scope:examples.Rectangle) + private: + + ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; + bool _is_default_instance_; + ::examples::Point* lo_; + ::examples::Point* hi_; + mutable int _cached_size_; + friend void protobuf_AddDesc_route_5fguide_2eproto(); + friend void protobuf_AssignDesc_route_5fguide_2eproto(); + friend void protobuf_ShutdownFile_route_5fguide_2eproto(); + + void InitAsDefaultInstance(); + static Rectangle* default_instance_; +}; +// ------------------------------------------------------------------- + +class Feature : public ::google::protobuf::Message { + public: + Feature(); + virtual ~Feature(); + + Feature(const Feature& from); + + inline Feature& operator=(const Feature& from) { + CopyFrom(from); + return *this; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const Feature& default_instance(); + + void Swap(Feature* other); + + // implements Message ---------------------------------------------- + + inline Feature* New() const { return New(NULL); } + + Feature* New(::google::protobuf::Arena* arena) const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const Feature& from); + void MergeFrom(const Feature& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + void InternalSwap(Feature* other); + private: + inline ::google::protobuf::Arena* GetArenaNoVirtual() const { + return _internal_metadata_.arena(); + } + inline void* MaybeArenaPtr() const { + return _internal_metadata_.raw_arena_ptr(); + } + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional string name = 1; + inline void clear_name(); + static const int kNameFieldNumber = 1; + inline const ::std::string& name() const; + inline void set_name(const ::std::string& value); + inline void set_name(const char* value); + inline void set_name(const char* value, size_t size); + inline ::std::string* mutable_name(); + inline ::std::string* release_name(); + inline void set_allocated_name(::std::string* name); + + // optional .examples.Point location = 2; + inline bool has_location() const; + inline void clear_location(); + static const int kLocationFieldNumber = 2; + inline const ::examples::Point& location() const; + inline ::examples::Point* mutable_location(); + inline ::examples::Point* release_location(); + inline void set_allocated_location(::examples::Point* location); + + // @@protoc_insertion_point(class_scope:examples.Feature) + private: + + ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; + bool _is_default_instance_; + ::google::protobuf::internal::ArenaStringPtr name_; + ::examples::Point* location_; + mutable int _cached_size_; + friend void protobuf_AddDesc_route_5fguide_2eproto(); + friend void protobuf_AssignDesc_route_5fguide_2eproto(); + friend void protobuf_ShutdownFile_route_5fguide_2eproto(); + + void InitAsDefaultInstance(); + static Feature* default_instance_; +}; +// ------------------------------------------------------------------- + +class RouteNote : public ::google::protobuf::Message { + public: + RouteNote(); + virtual ~RouteNote(); + + RouteNote(const RouteNote& from); + + inline RouteNote& operator=(const RouteNote& from) { + CopyFrom(from); + return *this; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const RouteNote& default_instance(); + + void Swap(RouteNote* other); + + // implements Message ---------------------------------------------- + + inline RouteNote* New() const { return New(NULL); } + + RouteNote* New(::google::protobuf::Arena* arena) const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const RouteNote& from); + void MergeFrom(const RouteNote& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + void InternalSwap(RouteNote* other); + private: + inline ::google::protobuf::Arena* GetArenaNoVirtual() const { + return _internal_metadata_.arena(); + } + inline void* MaybeArenaPtr() const { + return _internal_metadata_.raw_arena_ptr(); + } + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional .examples.Point location = 1; + inline bool has_location() const; + inline void clear_location(); + static const int kLocationFieldNumber = 1; + inline const ::examples::Point& location() const; + inline ::examples::Point* mutable_location(); + inline ::examples::Point* release_location(); + inline void set_allocated_location(::examples::Point* location); + + // optional string message = 2; + inline void clear_message(); + static const int kMessageFieldNumber = 2; + inline const ::std::string& message() const; + inline void set_message(const ::std::string& value); + inline void set_message(const char* value); + inline void set_message(const char* value, size_t size); + inline ::std::string* mutable_message(); + inline ::std::string* release_message(); + inline void set_allocated_message(::std::string* message); + + // @@protoc_insertion_point(class_scope:examples.RouteNote) + private: + + ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; + bool _is_default_instance_; + ::examples::Point* location_; + ::google::protobuf::internal::ArenaStringPtr message_; + mutable int _cached_size_; + friend void protobuf_AddDesc_route_5fguide_2eproto(); + friend void protobuf_AssignDesc_route_5fguide_2eproto(); + friend void protobuf_ShutdownFile_route_5fguide_2eproto(); + + void InitAsDefaultInstance(); + static RouteNote* default_instance_; +}; +// ------------------------------------------------------------------- + +class RouteSummary : public ::google::protobuf::Message { + public: + RouteSummary(); + virtual ~RouteSummary(); + + RouteSummary(const RouteSummary& from); + + inline RouteSummary& operator=(const RouteSummary& from) { + CopyFrom(from); + return *this; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const RouteSummary& default_instance(); + + void Swap(RouteSummary* other); + + // implements Message ---------------------------------------------- + + inline RouteSummary* New() const { return New(NULL); } + + RouteSummary* New(::google::protobuf::Arena* arena) const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const RouteSummary& from); + void MergeFrom(const RouteSummary& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + void InternalSwap(RouteSummary* other); + private: + inline ::google::protobuf::Arena* GetArenaNoVirtual() const { + return _internal_metadata_.arena(); + } + inline void* MaybeArenaPtr() const { + return _internal_metadata_.raw_arena_ptr(); + } + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 point_count = 1; + inline void clear_point_count(); + static const int kPointCountFieldNumber = 1; + inline ::google::protobuf::int32 point_count() const; + inline void set_point_count(::google::protobuf::int32 value); + + // optional int32 feature_count = 2; + inline void clear_feature_count(); + static const int kFeatureCountFieldNumber = 2; + inline ::google::protobuf::int32 feature_count() const; + inline void set_feature_count(::google::protobuf::int32 value); + + // optional int32 distance = 3; + inline void clear_distance(); + static const int kDistanceFieldNumber = 3; + inline ::google::protobuf::int32 distance() const; + inline void set_distance(::google::protobuf::int32 value); + + // optional int32 elapsed_time = 4; + inline void clear_elapsed_time(); + static const int kElapsedTimeFieldNumber = 4; + inline ::google::protobuf::int32 elapsed_time() const; + inline void set_elapsed_time(::google::protobuf::int32 value); + + // @@protoc_insertion_point(class_scope:examples.RouteSummary) + private: + + ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; + bool _is_default_instance_; + ::google::protobuf::int32 point_count_; + ::google::protobuf::int32 feature_count_; + ::google::protobuf::int32 distance_; + ::google::protobuf::int32 elapsed_time_; + mutable int _cached_size_; + friend void protobuf_AddDesc_route_5fguide_2eproto(); + friend void protobuf_AssignDesc_route_5fguide_2eproto(); + friend void protobuf_ShutdownFile_route_5fguide_2eproto(); + + void InitAsDefaultInstance(); + static RouteSummary* default_instance_; +}; +// =================================================================== + + +// =================================================================== + +// Point + +// optional int32 latitude = 1; +inline void Point::clear_latitude() { + latitude_ = 0; +} +inline ::google::protobuf::int32 Point::latitude() const { + // @@protoc_insertion_point(field_get:examples.Point.latitude) + return latitude_; +} +inline void Point::set_latitude(::google::protobuf::int32 value) { + + latitude_ = value; + // @@protoc_insertion_point(field_set:examples.Point.latitude) +} + +// optional int32 longitude = 2; +inline void Point::clear_longitude() { + longitude_ = 0; +} +inline ::google::protobuf::int32 Point::longitude() const { + // @@protoc_insertion_point(field_get:examples.Point.longitude) + return longitude_; +} +inline void Point::set_longitude(::google::protobuf::int32 value) { + + longitude_ = value; + // @@protoc_insertion_point(field_set:examples.Point.longitude) +} + +// ------------------------------------------------------------------- + +// Rectangle + +// optional .examples.Point lo = 1; +inline bool Rectangle::has_lo() const { + return !_is_default_instance_ && lo_ != NULL; +} +inline void Rectangle::clear_lo() { + if (lo_ != NULL) delete lo_; + lo_ = NULL; +} +inline const ::examples::Point& Rectangle::lo() const { + // @@protoc_insertion_point(field_get:examples.Rectangle.lo) + return lo_ != NULL ? *lo_ : *default_instance_->lo_; +} +inline ::examples::Point* Rectangle::mutable_lo() { + + if (lo_ == NULL) { + lo_ = new ::examples::Point; + } + // @@protoc_insertion_point(field_mutable:examples.Rectangle.lo) + return lo_; +} +inline ::examples::Point* Rectangle::release_lo() { + + ::examples::Point* temp = lo_; + lo_ = NULL; + return temp; +} +inline void Rectangle::set_allocated_lo(::examples::Point* lo) { + delete lo_; + lo_ = lo; + if (lo) { + + } else { + + } + // @@protoc_insertion_point(field_set_allocated:examples.Rectangle.lo) +} + +// optional .examples.Point hi = 2; +inline bool Rectangle::has_hi() const { + return !_is_default_instance_ && hi_ != NULL; +} +inline void Rectangle::clear_hi() { + if (hi_ != NULL) delete hi_; + hi_ = NULL; +} +inline const ::examples::Point& Rectangle::hi() const { + // @@protoc_insertion_point(field_get:examples.Rectangle.hi) + return hi_ != NULL ? *hi_ : *default_instance_->hi_; +} +inline ::examples::Point* Rectangle::mutable_hi() { + + if (hi_ == NULL) { + hi_ = new ::examples::Point; + } + // @@protoc_insertion_point(field_mutable:examples.Rectangle.hi) + return hi_; +} +inline ::examples::Point* Rectangle::release_hi() { + + ::examples::Point* temp = hi_; + hi_ = NULL; + return temp; +} +inline void Rectangle::set_allocated_hi(::examples::Point* hi) { + delete hi_; + hi_ = hi; + if (hi) { + + } else { + + } + // @@protoc_insertion_point(field_set_allocated:examples.Rectangle.hi) +} + +// ------------------------------------------------------------------- + +// Feature + +// optional string name = 1; +inline void Feature::clear_name() { + name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline const ::std::string& Feature::name() const { + // @@protoc_insertion_point(field_get:examples.Feature.name) + return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline void Feature::set_name(const ::std::string& value) { + + name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + // @@protoc_insertion_point(field_set:examples.Feature.name) +} +inline void Feature::set_name(const char* value) { + + name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); + // @@protoc_insertion_point(field_set_char:examples.Feature.name) +} +inline void Feature::set_name(const char* value, size_t size) { + + name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + ::std::string(reinterpret_cast(value), size)); + // @@protoc_insertion_point(field_set_pointer:examples.Feature.name) +} +inline ::std::string* Feature::mutable_name() { + + // @@protoc_insertion_point(field_mutable:examples.Feature.name) + return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline ::std::string* Feature::release_name() { + + return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline void Feature::set_allocated_name(::std::string* name) { + if (name != NULL) { + + } else { + + } + name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); + // @@protoc_insertion_point(field_set_allocated:examples.Feature.name) +} + +// optional .examples.Point location = 2; +inline bool Feature::has_location() const { + return !_is_default_instance_ && location_ != NULL; +} +inline void Feature::clear_location() { + if (location_ != NULL) delete location_; + location_ = NULL; +} +inline const ::examples::Point& Feature::location() const { + // @@protoc_insertion_point(field_get:examples.Feature.location) + return location_ != NULL ? *location_ : *default_instance_->location_; +} +inline ::examples::Point* Feature::mutable_location() { + + if (location_ == NULL) { + location_ = new ::examples::Point; + } + // @@protoc_insertion_point(field_mutable:examples.Feature.location) + return location_; +} +inline ::examples::Point* Feature::release_location() { + + ::examples::Point* temp = location_; + location_ = NULL; + return temp; +} +inline void Feature::set_allocated_location(::examples::Point* location) { + delete location_; + location_ = location; + if (location) { + + } else { + + } + // @@protoc_insertion_point(field_set_allocated:examples.Feature.location) +} + +// ------------------------------------------------------------------- + +// RouteNote + +// optional .examples.Point location = 1; +inline bool RouteNote::has_location() const { + return !_is_default_instance_ && location_ != NULL; +} +inline void RouteNote::clear_location() { + if (location_ != NULL) delete location_; + location_ = NULL; +} +inline const ::examples::Point& RouteNote::location() const { + // @@protoc_insertion_point(field_get:examples.RouteNote.location) + return location_ != NULL ? *location_ : *default_instance_->location_; +} +inline ::examples::Point* RouteNote::mutable_location() { + + if (location_ == NULL) { + location_ = new ::examples::Point; + } + // @@protoc_insertion_point(field_mutable:examples.RouteNote.location) + return location_; +} +inline ::examples::Point* RouteNote::release_location() { + + ::examples::Point* temp = location_; + location_ = NULL; + return temp; +} +inline void RouteNote::set_allocated_location(::examples::Point* location) { + delete location_; + location_ = location; + if (location) { + + } else { + + } + // @@protoc_insertion_point(field_set_allocated:examples.RouteNote.location) +} + +// optional string message = 2; +inline void RouteNote::clear_message() { + message_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline const ::std::string& RouteNote::message() const { + // @@protoc_insertion_point(field_get:examples.RouteNote.message) + return message_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline void RouteNote::set_message(const ::std::string& value) { + + message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + // @@protoc_insertion_point(field_set:examples.RouteNote.message) +} +inline void RouteNote::set_message(const char* value) { + + message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); + // @@protoc_insertion_point(field_set_char:examples.RouteNote.message) +} +inline void RouteNote::set_message(const char* value, size_t size) { + + message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + ::std::string(reinterpret_cast(value), size)); + // @@protoc_insertion_point(field_set_pointer:examples.RouteNote.message) +} +inline ::std::string* RouteNote::mutable_message() { + + // @@protoc_insertion_point(field_mutable:examples.RouteNote.message) + return message_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline ::std::string* RouteNote::release_message() { + + return message_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline void RouteNote::set_allocated_message(::std::string* message) { + if (message != NULL) { + + } else { + + } + message_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), message); + // @@protoc_insertion_point(field_set_allocated:examples.RouteNote.message) +} + +// ------------------------------------------------------------------- + +// RouteSummary + +// optional int32 point_count = 1; +inline void RouteSummary::clear_point_count() { + point_count_ = 0; +} +inline ::google::protobuf::int32 RouteSummary::point_count() const { + // @@protoc_insertion_point(field_get:examples.RouteSummary.point_count) + return point_count_; +} +inline void RouteSummary::set_point_count(::google::protobuf::int32 value) { + + point_count_ = value; + // @@protoc_insertion_point(field_set:examples.RouteSummary.point_count) +} + +// optional int32 feature_count = 2; +inline void RouteSummary::clear_feature_count() { + feature_count_ = 0; +} +inline ::google::protobuf::int32 RouteSummary::feature_count() const { + // @@protoc_insertion_point(field_get:examples.RouteSummary.feature_count) + return feature_count_; +} +inline void RouteSummary::set_feature_count(::google::protobuf::int32 value) { + + feature_count_ = value; + // @@protoc_insertion_point(field_set:examples.RouteSummary.feature_count) +} + +// optional int32 distance = 3; +inline void RouteSummary::clear_distance() { + distance_ = 0; +} +inline ::google::protobuf::int32 RouteSummary::distance() const { + // @@protoc_insertion_point(field_get:examples.RouteSummary.distance) + return distance_; +} +inline void RouteSummary::set_distance(::google::protobuf::int32 value) { + + distance_ = value; + // @@protoc_insertion_point(field_set:examples.RouteSummary.distance) +} + +// optional int32 elapsed_time = 4; +inline void RouteSummary::clear_elapsed_time() { + elapsed_time_ = 0; +} +inline ::google::protobuf::int32 RouteSummary::elapsed_time() const { + // @@protoc_insertion_point(field_get:examples.RouteSummary.elapsed_time) + return elapsed_time_; +} +inline void RouteSummary::set_elapsed_time(::google::protobuf::int32 value) { + + elapsed_time_ = value; + // @@protoc_insertion_point(field_set:examples.RouteSummary.elapsed_time) +} + + +class RouteGuide final { + public: + class Stub final : public ::grpc::InternalStub { + public: + ::grpc::Status GetFeature(::grpc::ClientContext* context, const ::examples::Point& request, ::examples::Feature* response); + ::grpc::ClientAsyncResponseReader< ::examples::Feature>* GetFeature(::grpc::ClientContext* context, const ::examples::Point& request, ::grpc::CompletionQueue* cq, void* tag); + ::grpc::ClientReader< ::examples::Feature>* ListFeatures(::grpc::ClientContext* context, const ::examples::Rectangle& request); + ::grpc::ClientAsyncReader< ::examples::Feature>* ListFeatures(::grpc::ClientContext* context, const ::examples::Rectangle& request, ::grpc::CompletionQueue* cq, void* tag); + ::grpc::ClientWriter< ::examples::Point>* RecordRoute(::grpc::ClientContext* context, ::examples::RouteSummary* response); + ::grpc::ClientAsyncWriter< ::examples::Point>* RecordRoute(::grpc::ClientContext* context, ::examples::RouteSummary* response, ::grpc::CompletionQueue* cq, void* tag); + ::grpc::ClientReaderWriter< ::examples::RouteNote, ::examples::RouteNote>* RouteChat(::grpc::ClientContext* context); + ::grpc::ClientAsyncReaderWriter< ::examples::RouteNote, ::examples::RouteNote>* RouteChat(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag); + }; + static Stub* NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel); + + class Service : public ::grpc::SynchronousService { + public: + Service() : service_(nullptr) {} + virtual ~Service(); + virtual ::grpc::Status GetFeature(::grpc::ServerContext* context, const ::examples::Point* request, ::examples::Feature* response); + virtual ::grpc::Status ListFeatures(::grpc::ServerContext* context, const ::examples::Rectangle* request, ::grpc::ServerWriter< ::examples::Feature>* writer); + virtual ::grpc::Status RecordRoute(::grpc::ServerContext* context, ::grpc::ServerReader< ::examples::Point>* reader, ::examples::RouteSummary* response); + virtual ::grpc::Status RouteChat(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::examples::RouteNote, ::examples::RouteNote>* stream); + ::grpc::RpcService* service() override final; + private: + ::grpc::RpcService* service_; + }; + class AsyncService final : public ::grpc::AsynchronousService { + public: + explicit AsyncService(::grpc::CompletionQueue* cq); + ~AsyncService() {}; + void RequestGetFeature(::grpc::ServerContext* context, ::examples::Point* request, ::grpc::ServerAsyncResponseWriter< ::examples::Feature>* response, ::grpc::CompletionQueue* cq, void *tag); + void RequestListFeatures(::grpc::ServerContext* context, ::examples::Rectangle* request, ::grpc::ServerAsyncWriter< ::examples::Feature>* writer, ::grpc::CompletionQueue* cq, void *tag); + void RequestRecordRoute(::grpc::ServerContext* context, ::grpc::ServerAsyncReader< ::examples::RouteSummary, ::examples::Point>* reader, ::grpc::CompletionQueue* cq, void *tag); + void RequestRouteChat(::grpc::ServerContext* context, ::grpc::ServerAsyncReaderWriter< ::examples::RouteNote, ::examples::RouteNote>* stream, ::grpc::CompletionQueue* cq, void *tag); + }; +}; + +// @@protoc_insertion_point(namespace_scope) + +} // namespace examples + +#ifndef SWIG +namespace google { +namespace protobuf { + + +} // namespace protobuf +} // namespace google +#endif // SWIG + +// @@protoc_insertion_point(global_scope) + +#endif // PROTOBUF_route_5fguide_2eproto__INCLUDED diff --git a/cpp/route_guide/route_guide_client.cc b/cpp/route_guide/route_guide_client.cc new file mode 100644 index 0000000..4a51f5e --- /dev/null +++ b/cpp/route_guide/route_guide_client.cc @@ -0,0 +1,91 @@ +/* + * + * 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 "helloworld.pb.h" + +using grpc::ChannelArguments; +using grpc::ChannelInterface; +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.IsOk()) { + return reply.message(); + } else { + return "Rpc failed"; + } + } + + void Shutdown() { stub_.reset(); } + + private: + std::unique_ptr stub_; +}; + +int main(int argc, char** argv) { + grpc_init(); + + GreeterClient greeter( + grpc::CreateChannel("localhost:50051", ChannelArguments())); + std::string user("world"); + std::string reply = greeter.SayHello(user); + std::cout << "Greeter received: " << reply << std::endl; + + greeter.Shutdown(); + + grpc_shutdown(); +} diff --git a/cpp/route_guide/route_guide_server.cc b/cpp/route_guide/route_guide_server.cc new file mode 100644 index 0000000..3a2ab60 --- /dev/null +++ b/cpp/route_guide/route_guide_server.cc @@ -0,0 +1,84 @@ +/* + * + * 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 "helloworld.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.AddPort(server_address); + builder.RegisterService(&service); + std::unique_ptr server(builder.BuildAndStart()); + std::cout << "Server listening on " << server_address << std::endl; + while (true) { + std::this_thread::sleep_for(std::chrono::seconds(5)); + } +} + +int main(int argc, char** argv) { + grpc_init(); + + RunServer(); + + grpc_shutdown(); + return 0; +} From bfad7921e122d83549f0b0947737273904bcc17f Mon Sep 17 00:00:00 2001 From: Yang Gao Date: Fri, 20 Feb 2015 11:30:46 -0800 Subject: [PATCH 02/12] makefile change --- cpp/route_guide/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cpp/route_guide/Makefile b/cpp/route_guide/Makefile index b9579e0..444841f 100644 --- a/cpp/route_guide/Makefile +++ b/cpp/route_guide/Makefile @@ -34,14 +34,14 @@ CPPFLAGS=-I/usr/local/include -pthread CXXFLAGS=-std=c++11 LDFLAGS=-L/usr/local/lib -lgrpc -lgrpc++ -lprotobuf -lpthread -ldl -all: greeter_client greeter_server +all: route_guide_client route_guide_server -greeter_client: helloworld.pb.o greeter_client.o +route_guide_client: route_guide.pb.o route_guide_client.o $(CXX) $(CPPFLAGS) $^ $(LDFLAGS) -o $@ -greeter_server: helloworld.pb.o greeter_server.o +route_guide_server: route_guide.pb.o route_guide_server.o $(CXX) $(CPPFLAGS) $^ $(LDFLAGS) -o $@ clean: - rm -f *.o greeter_client greeter_server + rm -f *.o route_guide_client route_guide_server From 5621545e4c66fabec705284c6bfa86d0223bb0a8 Mon Sep 17 00:00:00 2001 From: Yang Gao Date: Fri, 20 Feb 2015 16:01:15 -0800 Subject: [PATCH 03/12] Finish of a dummy client/server pair --- cpp/route_guide/Makefile | 79 +- cpp/route_guide/route_guide.pb.cc | 1736 ------------------------- cpp/route_guide/route_guide.pb.h | 929 ------------- cpp/route_guide/route_guide_client.cc | 99 +- cpp/route_guide/route_guide_server.cc | 37 +- 5 files changed, 177 insertions(+), 2703 deletions(-) delete mode 100644 cpp/route_guide/route_guide.pb.cc delete mode 100644 cpp/route_guide/route_guide.pb.h diff --git a/cpp/route_guide/Makefile b/cpp/route_guide/Makefile index 444841f..fae9a9d 100644 --- a/cpp/route_guide/Makefile +++ b/cpp/route_guide/Makefile @@ -29,19 +29,82 @@ # 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 -lgrpc++ -lprotobuf -lpthread -ldl +CXX = g++ +CPPFLAGS = -I/usr/local/include -pthread +CXXFLAGS = -std=c++11 +LDFLAGS = -L/usr/local/lib -lgpr -lgrpc -lgrpc++ -lprotobuf -lpthread -ldl +PROTOC = protoc +GRPC_CPP_PLUGIN = grpc_cpp_plugin +GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)` -all: route_guide_client route_guide_server +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_client.o - $(CXX) $(CPPFLAGS) $^ $(LDFLAGS) -o $@ + $(CXX) $^ $(LDFLAGS) -o $@ route_guide_server: route_guide.pb.o route_guide_server.o - $(CXX) $(CPPFLAGS) $^ $(LDFLAGS) -o $@ + $(CXX) $^ $(LDFLAGS) -o $@ + +%.pb.cc: %.proto + $(PROTOC) -I $(PROTOS_PATH) --cpp_out=. --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $< clean: - rm -f *.o route_guide_client route_guide_server + 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/cpp/route_guide/route_guide.pb.cc b/cpp/route_guide/route_guide.pb.cc deleted file mode 100644 index 6f4a1e7..0000000 --- a/cpp/route_guide/route_guide.pb.cc +++ /dev/null @@ -1,1736 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: route_guide.proto - -#define INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION -#include "route_guide.pb.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -// @@protoc_insertion_point(includes) - -namespace examples { - -namespace { - -const ::google::protobuf::Descriptor* Point_descriptor_ = NULL; -const ::google::protobuf::internal::GeneratedMessageReflection* - Point_reflection_ = NULL; -const ::google::protobuf::Descriptor* Rectangle_descriptor_ = NULL; -const ::google::protobuf::internal::GeneratedMessageReflection* - Rectangle_reflection_ = NULL; -const ::google::protobuf::Descriptor* Feature_descriptor_ = NULL; -const ::google::protobuf::internal::GeneratedMessageReflection* - Feature_reflection_ = NULL; -const ::google::protobuf::Descriptor* RouteNote_descriptor_ = NULL; -const ::google::protobuf::internal::GeneratedMessageReflection* - RouteNote_reflection_ = NULL; -const ::google::protobuf::Descriptor* RouteSummary_descriptor_ = NULL; -const ::google::protobuf::internal::GeneratedMessageReflection* - RouteSummary_reflection_ = NULL; - -} // namespace - - -void protobuf_AssignDesc_route_5fguide_2eproto() { - protobuf_AddDesc_route_5fguide_2eproto(); - const ::google::protobuf::FileDescriptor* file = - ::google::protobuf::DescriptorPool::generated_pool()->FindFileByName( - "route_guide.proto"); - GOOGLE_CHECK(file != NULL); - Point_descriptor_ = file->message_type(0); - static const int Point_offsets_[2] = { - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Point, latitude_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Point, longitude_), - }; - Point_reflection_ = - ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( - Point_descriptor_, - Point::default_instance_, - Point_offsets_, - -1, - -1, - -1, - sizeof(Point), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Point, _internal_metadata_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Point, _is_default_instance_)); - Rectangle_descriptor_ = file->message_type(1); - static const int Rectangle_offsets_[2] = { - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Rectangle, lo_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Rectangle, hi_), - }; - Rectangle_reflection_ = - ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( - Rectangle_descriptor_, - Rectangle::default_instance_, - Rectangle_offsets_, - -1, - -1, - -1, - sizeof(Rectangle), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Rectangle, _internal_metadata_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Rectangle, _is_default_instance_)); - Feature_descriptor_ = file->message_type(2); - static const int Feature_offsets_[2] = { - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Feature, name_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Feature, location_), - }; - Feature_reflection_ = - ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( - Feature_descriptor_, - Feature::default_instance_, - Feature_offsets_, - -1, - -1, - -1, - sizeof(Feature), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Feature, _internal_metadata_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Feature, _is_default_instance_)); - RouteNote_descriptor_ = file->message_type(3); - static const int RouteNote_offsets_[2] = { - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(RouteNote, location_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(RouteNote, message_), - }; - RouteNote_reflection_ = - ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( - RouteNote_descriptor_, - RouteNote::default_instance_, - RouteNote_offsets_, - -1, - -1, - -1, - sizeof(RouteNote), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(RouteNote, _internal_metadata_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(RouteNote, _is_default_instance_)); - RouteSummary_descriptor_ = file->message_type(4); - static const int RouteSummary_offsets_[4] = { - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(RouteSummary, point_count_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(RouteSummary, feature_count_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(RouteSummary, distance_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(RouteSummary, elapsed_time_), - }; - RouteSummary_reflection_ = - ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( - RouteSummary_descriptor_, - RouteSummary::default_instance_, - RouteSummary_offsets_, - -1, - -1, - -1, - sizeof(RouteSummary), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(RouteSummary, _internal_metadata_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(RouteSummary, _is_default_instance_)); -} - -namespace { - -GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_); -inline void protobuf_AssignDescriptorsOnce() { - ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_, - &protobuf_AssignDesc_route_5fguide_2eproto); -} - -void protobuf_RegisterTypes(const ::std::string&) { - protobuf_AssignDescriptorsOnce(); - ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - Point_descriptor_, &Point::default_instance()); - ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - Rectangle_descriptor_, &Rectangle::default_instance()); - ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - Feature_descriptor_, &Feature::default_instance()); - ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - RouteNote_descriptor_, &RouteNote::default_instance()); - ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - RouteSummary_descriptor_, &RouteSummary::default_instance()); -} - -} // namespace - -void protobuf_ShutdownFile_route_5fguide_2eproto() { - delete Point::default_instance_; - delete Point_reflection_; - delete Rectangle::default_instance_; - delete Rectangle_reflection_; - delete Feature::default_instance_; - delete Feature_reflection_; - delete RouteNote::default_instance_; - delete RouteNote_reflection_; - delete RouteSummary::default_instance_; - delete RouteSummary_reflection_; -} - -void protobuf_AddDesc_route_5fguide_2eproto() { - static bool already_here = false; - if (already_here) return; - already_here = true; - GOOGLE_PROTOBUF_VERIFY_VERSION; - - ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( - "\n\021route_guide.proto\022\010examples\",\n\005Point\022\020" - "\n\010latitude\030\001 \001(\005\022\021\n\tlongitude\030\002 \001(\005\"E\n\tR" - "ectangle\022\033\n\002lo\030\001 \001(\0132\017.examples.Point\022\033\n" - "\002hi\030\002 \001(\0132\017.examples.Point\":\n\007Feature\022\014\n" - "\004name\030\001 \001(\t\022!\n\010location\030\002 \001(\0132\017.examples" - ".Point\"\?\n\tRouteNote\022!\n\010location\030\001 \001(\0132\017." - "examples.Point\022\017\n\007message\030\002 \001(\t\"b\n\014Route" - "Summary\022\023\n\013point_count\030\001 \001(\005\022\025\n\rfeature_" - "count\030\002 \001(\005\022\020\n\010distance\030\003 \001(\005\022\024\n\014elapsed" - "_time\030\004 \001(\0052\365\001\n\nRouteGuide\0222\n\nGetFeature" - "\022\017.examples.Point\032\021.examples.Feature\"\000\022:" - "\n\014ListFeatures\022\023.examples.Rectangle\032\021.ex" - "amples.Feature\"\0000\001\022:\n\013RecordRoute\022\017.exam" - "ples.Point\032\026.examples.RouteSummary\"\000(\001\022;" - "\n\tRouteChat\022\023.examples.RouteNote\032\023.examp" - "les.RouteNote\"\000(\0010\001B\t\n\007ex.grpcb\006proto3", 638); - ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( - "route_guide.proto", &protobuf_RegisterTypes); - Point::default_instance_ = new Point(); - Rectangle::default_instance_ = new Rectangle(); - Feature::default_instance_ = new Feature(); - RouteNote::default_instance_ = new RouteNote(); - RouteSummary::default_instance_ = new RouteSummary(); - Point::default_instance_->InitAsDefaultInstance(); - Rectangle::default_instance_->InitAsDefaultInstance(); - Feature::default_instance_->InitAsDefaultInstance(); - RouteNote::default_instance_->InitAsDefaultInstance(); - RouteSummary::default_instance_->InitAsDefaultInstance(); - ::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_route_5fguide_2eproto); -} - -// Force AddDescriptors() to be called at static initialization time. -struct StaticDescriptorInitializer_route_5fguide_2eproto { - StaticDescriptorInitializer_route_5fguide_2eproto() { - protobuf_AddDesc_route_5fguide_2eproto(); - } -} static_descriptor_initializer_route_5fguide_2eproto_; - -namespace { - -static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD; -static void MergeFromFail(int line) { - GOOGLE_CHECK(false) << __FILE__ << ":" << line; -} - -} // namespace - - -// =================================================================== - -#ifndef _MSC_VER -const int Point::kLatitudeFieldNumber; -const int Point::kLongitudeFieldNumber; -#endif // !_MSC_VER - -Point::Point() - : ::google::protobuf::Message() , _internal_metadata_(NULL) { - SharedCtor(); - // @@protoc_insertion_point(constructor:examples.Point) -} - -void Point::InitAsDefaultInstance() { - _is_default_instance_ = true; -} - -Point::Point(const Point& from) - : ::google::protobuf::Message(), - _internal_metadata_(NULL) { - SharedCtor(); - MergeFrom(from); - // @@protoc_insertion_point(copy_constructor:examples.Point) -} - -void Point::SharedCtor() { - _is_default_instance_ = false; - _cached_size_ = 0; - latitude_ = 0; - longitude_ = 0; -} - -Point::~Point() { - // @@protoc_insertion_point(destructor:examples.Point) - SharedDtor(); -} - -void Point::SharedDtor() { - if (this != default_instance_) { - } -} - -void Point::SetCachedSize(int size) const { - GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = size; - GOOGLE_SAFE_CONCURRENT_WRITES_END(); -} -const ::google::protobuf::Descriptor* Point::descriptor() { - protobuf_AssignDescriptorsOnce(); - return Point_descriptor_; -} - -const Point& Point::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_route_5fguide_2eproto(); - return *default_instance_; -} - -Point* Point::default_instance_ = NULL; - -Point* Point::New(::google::protobuf::Arena* arena) const { - Point* n = new Point; - if (arena != NULL) { - arena->Own(n); - } - return n; -} - -void Point::Clear() { -#define OFFSET_OF_FIELD_(f) (reinterpret_cast( \ - &reinterpret_cast(16)->f) - \ - reinterpret_cast(16)) - -#define ZR_(first, last) do { \ - size_t f = OFFSET_OF_FIELD_(first); \ - size_t n = OFFSET_OF_FIELD_(last) - f + sizeof(last); \ - ::memset(&first, 0, n); \ - } while (0) - - ZR_(latitude_, longitude_); - -#undef OFFSET_OF_FIELD_ -#undef ZR_ - -} - -bool Point::MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input) { -#define DO_(EXPRESSION) if (!(EXPRESSION)) goto failure - ::google::protobuf::uint32 tag; - // @@protoc_insertion_point(parse_start:examples.Point) - for (;;) { - ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127); - tag = p.first; - if (!p.second) goto handle_unusual; - switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { - // optional int32 latitude = 1; - case 1: { - if (tag == 8) { - DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< - ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( - input, &latitude_))); - - } else { - goto handle_unusual; - } - if (input->ExpectTag(16)) goto parse_longitude; - break; - } - - // optional int32 longitude = 2; - case 2: { - if (tag == 16) { - parse_longitude: - DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< - ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( - input, &longitude_))); - - } else { - goto handle_unusual; - } - if (input->ExpectAtEnd()) goto success; - break; - } - - default: { - handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { - goto success; - } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); - break; - } - } - } -success: - // @@protoc_insertion_point(parse_success:examples.Point) - return true; -failure: - // @@protoc_insertion_point(parse_failure:examples.Point) - return false; -#undef DO_ -} - -void Point::SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const { - // @@protoc_insertion_point(serialize_start:examples.Point) - // optional int32 latitude = 1; - if (this->latitude() != 0) { - ::google::protobuf::internal::WireFormatLite::WriteInt32(1, this->latitude(), output); - } - - // optional int32 longitude = 2; - if (this->longitude() != 0) { - ::google::protobuf::internal::WireFormatLite::WriteInt32(2, this->longitude(), output); - } - - // @@protoc_insertion_point(serialize_end:examples.Point) -} - -::google::protobuf::uint8* Point::SerializeWithCachedSizesToArray( - ::google::protobuf::uint8* target) const { - // @@protoc_insertion_point(serialize_to_array_start:examples.Point) - // optional int32 latitude = 1; - if (this->latitude() != 0) { - target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(1, this->latitude(), target); - } - - // optional int32 longitude = 2; - if (this->longitude() != 0) { - target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(2, this->longitude(), target); - } - - // @@protoc_insertion_point(serialize_to_array_end:examples.Point) - return target; -} - -int Point::ByteSize() const { - int total_size = 0; - - // optional int32 latitude = 1; - if (this->latitude() != 0) { - total_size += 1 + - ::google::protobuf::internal::WireFormatLite::Int32Size( - this->latitude()); - } - - // optional int32 longitude = 2; - if (this->longitude() != 0) { - total_size += 1 + - ::google::protobuf::internal::WireFormatLite::Int32Size( - this->longitude()); - } - - GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; - GOOGLE_SAFE_CONCURRENT_WRITES_END(); - return total_size; -} - -void Point::MergeFrom(const ::google::protobuf::Message& from) { - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); - const Point* source = - ::google::protobuf::internal::dynamic_cast_if_available( - &from); - if (source == NULL) { - ::google::protobuf::internal::ReflectionOps::Merge(from, this); - } else { - MergeFrom(*source); - } -} - -void Point::MergeFrom(const Point& from) { - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); - if (from.latitude() != 0) { - set_latitude(from.latitude()); - } - if (from.longitude() != 0) { - set_longitude(from.longitude()); - } -} - -void Point::CopyFrom(const ::google::protobuf::Message& from) { - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -void Point::CopyFrom(const Point& from) { - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool Point::IsInitialized() const { - - return true; -} - -void Point::Swap(Point* other) { - if (other == this) return; - InternalSwap(other); -} -void Point::InternalSwap(Point* other) { - std::swap(latitude_, other->latitude_); - std::swap(longitude_, other->longitude_); - _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); -} - -::google::protobuf::Metadata Point::GetMetadata() const { - protobuf_AssignDescriptorsOnce(); - ::google::protobuf::Metadata metadata; - metadata.descriptor = Point_descriptor_; - metadata.reflection = Point_reflection_; - return metadata; -} - - -// =================================================================== - -#ifndef _MSC_VER -const int Rectangle::kLoFieldNumber; -const int Rectangle::kHiFieldNumber; -#endif // !_MSC_VER - -Rectangle::Rectangle() - : ::google::protobuf::Message() , _internal_metadata_(NULL) { - SharedCtor(); - // @@protoc_insertion_point(constructor:examples.Rectangle) -} - -void Rectangle::InitAsDefaultInstance() { - _is_default_instance_ = true; - lo_ = const_cast< ::examples::Point*>(&::examples::Point::default_instance()); - hi_ = const_cast< ::examples::Point*>(&::examples::Point::default_instance()); -} - -Rectangle::Rectangle(const Rectangle& from) - : ::google::protobuf::Message(), - _internal_metadata_(NULL) { - SharedCtor(); - MergeFrom(from); - // @@protoc_insertion_point(copy_constructor:examples.Rectangle) -} - -void Rectangle::SharedCtor() { - _is_default_instance_ = false; - _cached_size_ = 0; - lo_ = NULL; - hi_ = NULL; -} - -Rectangle::~Rectangle() { - // @@protoc_insertion_point(destructor:examples.Rectangle) - SharedDtor(); -} - -void Rectangle::SharedDtor() { - if (this != default_instance_) { - delete lo_; - delete hi_; - } -} - -void Rectangle::SetCachedSize(int size) const { - GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = size; - GOOGLE_SAFE_CONCURRENT_WRITES_END(); -} -const ::google::protobuf::Descriptor* Rectangle::descriptor() { - protobuf_AssignDescriptorsOnce(); - return Rectangle_descriptor_; -} - -const Rectangle& Rectangle::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_route_5fguide_2eproto(); - return *default_instance_; -} - -Rectangle* Rectangle::default_instance_ = NULL; - -Rectangle* Rectangle::New(::google::protobuf::Arena* arena) const { - Rectangle* n = new Rectangle; - if (arena != NULL) { - arena->Own(n); - } - return n; -} - -void Rectangle::Clear() { - if (lo_ != NULL) delete lo_; - lo_ = NULL; - if (hi_ != NULL) delete hi_; - hi_ = NULL; -} - -bool Rectangle::MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input) { -#define DO_(EXPRESSION) if (!(EXPRESSION)) goto failure - ::google::protobuf::uint32 tag; - // @@protoc_insertion_point(parse_start:examples.Rectangle) - for (;;) { - ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127); - tag = p.first; - if (!p.second) goto handle_unusual; - switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { - // optional .examples.Point lo = 1; - case 1: { - if (tag == 10) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, mutable_lo())); - } else { - goto handle_unusual; - } - if (input->ExpectTag(18)) goto parse_hi; - break; - } - - // optional .examples.Point hi = 2; - case 2: { - if (tag == 18) { - parse_hi: - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, mutable_hi())); - } else { - goto handle_unusual; - } - if (input->ExpectAtEnd()) goto success; - break; - } - - default: { - handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { - goto success; - } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); - break; - } - } - } -success: - // @@protoc_insertion_point(parse_success:examples.Rectangle) - return true; -failure: - // @@protoc_insertion_point(parse_failure:examples.Rectangle) - return false; -#undef DO_ -} - -void Rectangle::SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const { - // @@protoc_insertion_point(serialize_start:examples.Rectangle) - // optional .examples.Point lo = 1; - if (this->has_lo()) { - ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( - 1, *this->lo_, output); - } - - // optional .examples.Point hi = 2; - if (this->has_hi()) { - ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( - 2, *this->hi_, output); - } - - // @@protoc_insertion_point(serialize_end:examples.Rectangle) -} - -::google::protobuf::uint8* Rectangle::SerializeWithCachedSizesToArray( - ::google::protobuf::uint8* target) const { - // @@protoc_insertion_point(serialize_to_array_start:examples.Rectangle) - // optional .examples.Point lo = 1; - if (this->has_lo()) { - target = ::google::protobuf::internal::WireFormatLite:: - WriteMessageNoVirtualToArray( - 1, *this->lo_, target); - } - - // optional .examples.Point hi = 2; - if (this->has_hi()) { - target = ::google::protobuf::internal::WireFormatLite:: - WriteMessageNoVirtualToArray( - 2, *this->hi_, target); - } - - // @@protoc_insertion_point(serialize_to_array_end:examples.Rectangle) - return target; -} - -int Rectangle::ByteSize() const { - int total_size = 0; - - // optional .examples.Point lo = 1; - if (this->has_lo()) { - total_size += 1 + - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - *this->lo_); - } - - // optional .examples.Point hi = 2; - if (this->has_hi()) { - total_size += 1 + - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - *this->hi_); - } - - GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; - GOOGLE_SAFE_CONCURRENT_WRITES_END(); - return total_size; -} - -void Rectangle::MergeFrom(const ::google::protobuf::Message& from) { - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); - const Rectangle* source = - ::google::protobuf::internal::dynamic_cast_if_available( - &from); - if (source == NULL) { - ::google::protobuf::internal::ReflectionOps::Merge(from, this); - } else { - MergeFrom(*source); - } -} - -void Rectangle::MergeFrom(const Rectangle& from) { - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); - if (from.has_lo()) { - mutable_lo()->::examples::Point::MergeFrom(from.lo()); - } - if (from.has_hi()) { - mutable_hi()->::examples::Point::MergeFrom(from.hi()); - } -} - -void Rectangle::CopyFrom(const ::google::protobuf::Message& from) { - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -void Rectangle::CopyFrom(const Rectangle& from) { - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool Rectangle::IsInitialized() const { - - return true; -} - -void Rectangle::Swap(Rectangle* other) { - if (other == this) return; - InternalSwap(other); -} -void Rectangle::InternalSwap(Rectangle* other) { - std::swap(lo_, other->lo_); - std::swap(hi_, other->hi_); - _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); -} - -::google::protobuf::Metadata Rectangle::GetMetadata() const { - protobuf_AssignDescriptorsOnce(); - ::google::protobuf::Metadata metadata; - metadata.descriptor = Rectangle_descriptor_; - metadata.reflection = Rectangle_reflection_; - return metadata; -} - - -// =================================================================== - -#ifndef _MSC_VER -const int Feature::kNameFieldNumber; -const int Feature::kLocationFieldNumber; -#endif // !_MSC_VER - -Feature::Feature() - : ::google::protobuf::Message() , _internal_metadata_(NULL) { - SharedCtor(); - // @@protoc_insertion_point(constructor:examples.Feature) -} - -void Feature::InitAsDefaultInstance() { - _is_default_instance_ = true; - location_ = const_cast< ::examples::Point*>(&::examples::Point::default_instance()); -} - -Feature::Feature(const Feature& from) - : ::google::protobuf::Message(), - _internal_metadata_(NULL) { - SharedCtor(); - MergeFrom(from); - // @@protoc_insertion_point(copy_constructor:examples.Feature) -} - -void Feature::SharedCtor() { - _is_default_instance_ = false; - ::google::protobuf::internal::GetEmptyString(); - _cached_size_ = 0; - name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - location_ = NULL; -} - -Feature::~Feature() { - // @@protoc_insertion_point(destructor:examples.Feature) - SharedDtor(); -} - -void Feature::SharedDtor() { - name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { - delete location_; - } -} - -void Feature::SetCachedSize(int size) const { - GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = size; - GOOGLE_SAFE_CONCURRENT_WRITES_END(); -} -const ::google::protobuf::Descriptor* Feature::descriptor() { - protobuf_AssignDescriptorsOnce(); - return Feature_descriptor_; -} - -const Feature& Feature::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_route_5fguide_2eproto(); - return *default_instance_; -} - -Feature* Feature::default_instance_ = NULL; - -Feature* Feature::New(::google::protobuf::Arena* arena) const { - Feature* n = new Feature; - if (arena != NULL) { - arena->Own(n); - } - return n; -} - -void Feature::Clear() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (location_ != NULL) delete location_; - location_ = NULL; -} - -bool Feature::MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input) { -#define DO_(EXPRESSION) if (!(EXPRESSION)) goto failure - ::google::protobuf::uint32 tag; - // @@protoc_insertion_point(parse_start:examples.Feature) - for (;;) { - ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127); - tag = p.first; - if (!p.second) goto handle_unusual; - switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { - // optional string name = 1; - case 1: { - if (tag == 10) { - DO_(::google::protobuf::internal::WireFormatLite::ReadString( - input, this->mutable_name())); - ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( - this->name().data(), this->name().length(), - ::google::protobuf::internal::WireFormat::PARSE, - "examples.Feature.name"); - } else { - goto handle_unusual; - } - if (input->ExpectTag(18)) goto parse_location; - break; - } - - // optional .examples.Point location = 2; - case 2: { - if (tag == 18) { - parse_location: - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, mutable_location())); - } else { - goto handle_unusual; - } - if (input->ExpectAtEnd()) goto success; - break; - } - - default: { - handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { - goto success; - } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); - break; - } - } - } -success: - // @@protoc_insertion_point(parse_success:examples.Feature) - return true; -failure: - // @@protoc_insertion_point(parse_failure:examples.Feature) - return false; -#undef DO_ -} - -void Feature::SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const { - // @@protoc_insertion_point(serialize_start:examples.Feature) - // optional string name = 1; - if (this->name().size() > 0) { - ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( - this->name().data(), this->name().length(), - ::google::protobuf::internal::WireFormat::SERIALIZE, - "examples.Feature.name"); - ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased( - 1, this->name(), output); - } - - // optional .examples.Point location = 2; - if (this->has_location()) { - ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( - 2, *this->location_, output); - } - - // @@protoc_insertion_point(serialize_end:examples.Feature) -} - -::google::protobuf::uint8* Feature::SerializeWithCachedSizesToArray( - ::google::protobuf::uint8* target) const { - // @@protoc_insertion_point(serialize_to_array_start:examples.Feature) - // optional string name = 1; - if (this->name().size() > 0) { - ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( - this->name().data(), this->name().length(), - ::google::protobuf::internal::WireFormat::SERIALIZE, - "examples.Feature.name"); - target = - ::google::protobuf::internal::WireFormatLite::WriteStringToArray( - 1, this->name(), target); - } - - // optional .examples.Point location = 2; - if (this->has_location()) { - target = ::google::protobuf::internal::WireFormatLite:: - WriteMessageNoVirtualToArray( - 2, *this->location_, target); - } - - // @@protoc_insertion_point(serialize_to_array_end:examples.Feature) - return target; -} - -int Feature::ByteSize() const { - int total_size = 0; - - // optional string name = 1; - if (this->name().size() > 0) { - total_size += 1 + - ::google::protobuf::internal::WireFormatLite::StringSize( - this->name()); - } - - // optional .examples.Point location = 2; - if (this->has_location()) { - total_size += 1 + - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - *this->location_); - } - - GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; - GOOGLE_SAFE_CONCURRENT_WRITES_END(); - return total_size; -} - -void Feature::MergeFrom(const ::google::protobuf::Message& from) { - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); - const Feature* source = - ::google::protobuf::internal::dynamic_cast_if_available( - &from); - if (source == NULL) { - ::google::protobuf::internal::ReflectionOps::Merge(from, this); - } else { - MergeFrom(*source); - } -} - -void Feature::MergeFrom(const Feature& from) { - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); - if (from.name().size() > 0) { - - name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_); - } - if (from.has_location()) { - mutable_location()->::examples::Point::MergeFrom(from.location()); - } -} - -void Feature::CopyFrom(const ::google::protobuf::Message& from) { - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -void Feature::CopyFrom(const Feature& from) { - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool Feature::IsInitialized() const { - - return true; -} - -void Feature::Swap(Feature* other) { - if (other == this) return; - InternalSwap(other); -} -void Feature::InternalSwap(Feature* other) { - name_.Swap(&other->name_); - std::swap(location_, other->location_); - _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); -} - -::google::protobuf::Metadata Feature::GetMetadata() const { - protobuf_AssignDescriptorsOnce(); - ::google::protobuf::Metadata metadata; - metadata.descriptor = Feature_descriptor_; - metadata.reflection = Feature_reflection_; - return metadata; -} - - -// =================================================================== - -#ifndef _MSC_VER -const int RouteNote::kLocationFieldNumber; -const int RouteNote::kMessageFieldNumber; -#endif // !_MSC_VER - -RouteNote::RouteNote() - : ::google::protobuf::Message() , _internal_metadata_(NULL) { - SharedCtor(); - // @@protoc_insertion_point(constructor:examples.RouteNote) -} - -void RouteNote::InitAsDefaultInstance() { - _is_default_instance_ = true; - location_ = const_cast< ::examples::Point*>(&::examples::Point::default_instance()); -} - -RouteNote::RouteNote(const RouteNote& from) - : ::google::protobuf::Message(), - _internal_metadata_(NULL) { - SharedCtor(); - MergeFrom(from); - // @@protoc_insertion_point(copy_constructor:examples.RouteNote) -} - -void RouteNote::SharedCtor() { - _is_default_instance_ = false; - ::google::protobuf::internal::GetEmptyString(); - _cached_size_ = 0; - location_ = NULL; - message_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} - -RouteNote::~RouteNote() { - // @@protoc_insertion_point(destructor:examples.RouteNote) - SharedDtor(); -} - -void RouteNote::SharedDtor() { - message_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { - delete location_; - } -} - -void RouteNote::SetCachedSize(int size) const { - GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = size; - GOOGLE_SAFE_CONCURRENT_WRITES_END(); -} -const ::google::protobuf::Descriptor* RouteNote::descriptor() { - protobuf_AssignDescriptorsOnce(); - return RouteNote_descriptor_; -} - -const RouteNote& RouteNote::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_route_5fguide_2eproto(); - return *default_instance_; -} - -RouteNote* RouteNote::default_instance_ = NULL; - -RouteNote* RouteNote::New(::google::protobuf::Arena* arena) const { - RouteNote* n = new RouteNote; - if (arena != NULL) { - arena->Own(n); - } - return n; -} - -void RouteNote::Clear() { - if (location_ != NULL) delete location_; - location_ = NULL; - message_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} - -bool RouteNote::MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input) { -#define DO_(EXPRESSION) if (!(EXPRESSION)) goto failure - ::google::protobuf::uint32 tag; - // @@protoc_insertion_point(parse_start:examples.RouteNote) - for (;;) { - ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127); - tag = p.first; - if (!p.second) goto handle_unusual; - switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { - // optional .examples.Point location = 1; - case 1: { - if (tag == 10) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, mutable_location())); - } else { - goto handle_unusual; - } - if (input->ExpectTag(18)) goto parse_message; - break; - } - - // optional string message = 2; - case 2: { - if (tag == 18) { - parse_message: - DO_(::google::protobuf::internal::WireFormatLite::ReadString( - input, this->mutable_message())); - ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( - this->message().data(), this->message().length(), - ::google::protobuf::internal::WireFormat::PARSE, - "examples.RouteNote.message"); - } else { - goto handle_unusual; - } - if (input->ExpectAtEnd()) goto success; - break; - } - - default: { - handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { - goto success; - } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); - break; - } - } - } -success: - // @@protoc_insertion_point(parse_success:examples.RouteNote) - return true; -failure: - // @@protoc_insertion_point(parse_failure:examples.RouteNote) - return false; -#undef DO_ -} - -void RouteNote::SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const { - // @@protoc_insertion_point(serialize_start:examples.RouteNote) - // optional .examples.Point location = 1; - if (this->has_location()) { - ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( - 1, *this->location_, output); - } - - // optional string message = 2; - if (this->message().size() > 0) { - ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( - this->message().data(), this->message().length(), - ::google::protobuf::internal::WireFormat::SERIALIZE, - "examples.RouteNote.message"); - ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased( - 2, this->message(), output); - } - - // @@protoc_insertion_point(serialize_end:examples.RouteNote) -} - -::google::protobuf::uint8* RouteNote::SerializeWithCachedSizesToArray( - ::google::protobuf::uint8* target) const { - // @@protoc_insertion_point(serialize_to_array_start:examples.RouteNote) - // optional .examples.Point location = 1; - if (this->has_location()) { - target = ::google::protobuf::internal::WireFormatLite:: - WriteMessageNoVirtualToArray( - 1, *this->location_, target); - } - - // optional string message = 2; - if (this->message().size() > 0) { - ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( - this->message().data(), this->message().length(), - ::google::protobuf::internal::WireFormat::SERIALIZE, - "examples.RouteNote.message"); - target = - ::google::protobuf::internal::WireFormatLite::WriteStringToArray( - 2, this->message(), target); - } - - // @@protoc_insertion_point(serialize_to_array_end:examples.RouteNote) - return target; -} - -int RouteNote::ByteSize() const { - int total_size = 0; - - // optional .examples.Point location = 1; - if (this->has_location()) { - total_size += 1 + - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - *this->location_); - } - - // optional string message = 2; - if (this->message().size() > 0) { - total_size += 1 + - ::google::protobuf::internal::WireFormatLite::StringSize( - this->message()); - } - - GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; - GOOGLE_SAFE_CONCURRENT_WRITES_END(); - return total_size; -} - -void RouteNote::MergeFrom(const ::google::protobuf::Message& from) { - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); - const RouteNote* source = - ::google::protobuf::internal::dynamic_cast_if_available( - &from); - if (source == NULL) { - ::google::protobuf::internal::ReflectionOps::Merge(from, this); - } else { - MergeFrom(*source); - } -} - -void RouteNote::MergeFrom(const RouteNote& from) { - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); - if (from.has_location()) { - mutable_location()->::examples::Point::MergeFrom(from.location()); - } - if (from.message().size() > 0) { - - message_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.message_); - } -} - -void RouteNote::CopyFrom(const ::google::protobuf::Message& from) { - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -void RouteNote::CopyFrom(const RouteNote& from) { - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool RouteNote::IsInitialized() const { - - return true; -} - -void RouteNote::Swap(RouteNote* other) { - if (other == this) return; - InternalSwap(other); -} -void RouteNote::InternalSwap(RouteNote* other) { - std::swap(location_, other->location_); - message_.Swap(&other->message_); - _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); -} - -::google::protobuf::Metadata RouteNote::GetMetadata() const { - protobuf_AssignDescriptorsOnce(); - ::google::protobuf::Metadata metadata; - metadata.descriptor = RouteNote_descriptor_; - metadata.reflection = RouteNote_reflection_; - return metadata; -} - - -// =================================================================== - -#ifndef _MSC_VER -const int RouteSummary::kPointCountFieldNumber; -const int RouteSummary::kFeatureCountFieldNumber; -const int RouteSummary::kDistanceFieldNumber; -const int RouteSummary::kElapsedTimeFieldNumber; -#endif // !_MSC_VER - -RouteSummary::RouteSummary() - : ::google::protobuf::Message() , _internal_metadata_(NULL) { - SharedCtor(); - // @@protoc_insertion_point(constructor:examples.RouteSummary) -} - -void RouteSummary::InitAsDefaultInstance() { - _is_default_instance_ = true; -} - -RouteSummary::RouteSummary(const RouteSummary& from) - : ::google::protobuf::Message(), - _internal_metadata_(NULL) { - SharedCtor(); - MergeFrom(from); - // @@protoc_insertion_point(copy_constructor:examples.RouteSummary) -} - -void RouteSummary::SharedCtor() { - _is_default_instance_ = false; - _cached_size_ = 0; - point_count_ = 0; - feature_count_ = 0; - distance_ = 0; - elapsed_time_ = 0; -} - -RouteSummary::~RouteSummary() { - // @@protoc_insertion_point(destructor:examples.RouteSummary) - SharedDtor(); -} - -void RouteSummary::SharedDtor() { - if (this != default_instance_) { - } -} - -void RouteSummary::SetCachedSize(int size) const { - GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = size; - GOOGLE_SAFE_CONCURRENT_WRITES_END(); -} -const ::google::protobuf::Descriptor* RouteSummary::descriptor() { - protobuf_AssignDescriptorsOnce(); - return RouteSummary_descriptor_; -} - -const RouteSummary& RouteSummary::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_route_5fguide_2eproto(); - return *default_instance_; -} - -RouteSummary* RouteSummary::default_instance_ = NULL; - -RouteSummary* RouteSummary::New(::google::protobuf::Arena* arena) const { - RouteSummary* n = new RouteSummary; - if (arena != NULL) { - arena->Own(n); - } - return n; -} - -void RouteSummary::Clear() { -#define OFFSET_OF_FIELD_(f) (reinterpret_cast( \ - &reinterpret_cast(16)->f) - \ - reinterpret_cast(16)) - -#define ZR_(first, last) do { \ - size_t f = OFFSET_OF_FIELD_(first); \ - size_t n = OFFSET_OF_FIELD_(last) - f + sizeof(last); \ - ::memset(&first, 0, n); \ - } while (0) - - ZR_(point_count_, elapsed_time_); - -#undef OFFSET_OF_FIELD_ -#undef ZR_ - -} - -bool RouteSummary::MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input) { -#define DO_(EXPRESSION) if (!(EXPRESSION)) goto failure - ::google::protobuf::uint32 tag; - // @@protoc_insertion_point(parse_start:examples.RouteSummary) - for (;;) { - ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127); - tag = p.first; - if (!p.second) goto handle_unusual; - switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { - // optional int32 point_count = 1; - case 1: { - if (tag == 8) { - DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< - ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( - input, &point_count_))); - - } else { - goto handle_unusual; - } - if (input->ExpectTag(16)) goto parse_feature_count; - break; - } - - // optional int32 feature_count = 2; - case 2: { - if (tag == 16) { - parse_feature_count: - DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< - ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( - input, &feature_count_))); - - } else { - goto handle_unusual; - } - if (input->ExpectTag(24)) goto parse_distance; - break; - } - - // optional int32 distance = 3; - case 3: { - if (tag == 24) { - parse_distance: - DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< - ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( - input, &distance_))); - - } else { - goto handle_unusual; - } - if (input->ExpectTag(32)) goto parse_elapsed_time; - break; - } - - // optional int32 elapsed_time = 4; - case 4: { - if (tag == 32) { - parse_elapsed_time: - DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< - ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( - input, &elapsed_time_))); - - } else { - goto handle_unusual; - } - if (input->ExpectAtEnd()) goto success; - break; - } - - default: { - handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { - goto success; - } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); - break; - } - } - } -success: - // @@protoc_insertion_point(parse_success:examples.RouteSummary) - return true; -failure: - // @@protoc_insertion_point(parse_failure:examples.RouteSummary) - return false; -#undef DO_ -} - -void RouteSummary::SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const { - // @@protoc_insertion_point(serialize_start:examples.RouteSummary) - // optional int32 point_count = 1; - if (this->point_count() != 0) { - ::google::protobuf::internal::WireFormatLite::WriteInt32(1, this->point_count(), output); - } - - // optional int32 feature_count = 2; - if (this->feature_count() != 0) { - ::google::protobuf::internal::WireFormatLite::WriteInt32(2, this->feature_count(), output); - } - - // optional int32 distance = 3; - if (this->distance() != 0) { - ::google::protobuf::internal::WireFormatLite::WriteInt32(3, this->distance(), output); - } - - // optional int32 elapsed_time = 4; - if (this->elapsed_time() != 0) { - ::google::protobuf::internal::WireFormatLite::WriteInt32(4, this->elapsed_time(), output); - } - - // @@protoc_insertion_point(serialize_end:examples.RouteSummary) -} - -::google::protobuf::uint8* RouteSummary::SerializeWithCachedSizesToArray( - ::google::protobuf::uint8* target) const { - // @@protoc_insertion_point(serialize_to_array_start:examples.RouteSummary) - // optional int32 point_count = 1; - if (this->point_count() != 0) { - target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(1, this->point_count(), target); - } - - // optional int32 feature_count = 2; - if (this->feature_count() != 0) { - target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(2, this->feature_count(), target); - } - - // optional int32 distance = 3; - if (this->distance() != 0) { - target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(3, this->distance(), target); - } - - // optional int32 elapsed_time = 4; - if (this->elapsed_time() != 0) { - target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(4, this->elapsed_time(), target); - } - - // @@protoc_insertion_point(serialize_to_array_end:examples.RouteSummary) - return target; -} - -int RouteSummary::ByteSize() const { - int total_size = 0; - - // optional int32 point_count = 1; - if (this->point_count() != 0) { - total_size += 1 + - ::google::protobuf::internal::WireFormatLite::Int32Size( - this->point_count()); - } - - // optional int32 feature_count = 2; - if (this->feature_count() != 0) { - total_size += 1 + - ::google::protobuf::internal::WireFormatLite::Int32Size( - this->feature_count()); - } - - // optional int32 distance = 3; - if (this->distance() != 0) { - total_size += 1 + - ::google::protobuf::internal::WireFormatLite::Int32Size( - this->distance()); - } - - // optional int32 elapsed_time = 4; - if (this->elapsed_time() != 0) { - total_size += 1 + - ::google::protobuf::internal::WireFormatLite::Int32Size( - this->elapsed_time()); - } - - GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; - GOOGLE_SAFE_CONCURRENT_WRITES_END(); - return total_size; -} - -void RouteSummary::MergeFrom(const ::google::protobuf::Message& from) { - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); - const RouteSummary* source = - ::google::protobuf::internal::dynamic_cast_if_available( - &from); - if (source == NULL) { - ::google::protobuf::internal::ReflectionOps::Merge(from, this); - } else { - MergeFrom(*source); - } -} - -void RouteSummary::MergeFrom(const RouteSummary& from) { - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); - if (from.point_count() != 0) { - set_point_count(from.point_count()); - } - if (from.feature_count() != 0) { - set_feature_count(from.feature_count()); - } - if (from.distance() != 0) { - set_distance(from.distance()); - } - if (from.elapsed_time() != 0) { - set_elapsed_time(from.elapsed_time()); - } -} - -void RouteSummary::CopyFrom(const ::google::protobuf::Message& from) { - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -void RouteSummary::CopyFrom(const RouteSummary& from) { - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool RouteSummary::IsInitialized() const { - - return true; -} - -void RouteSummary::Swap(RouteSummary* other) { - if (other == this) return; - InternalSwap(other); -} -void RouteSummary::InternalSwap(RouteSummary* other) { - std::swap(point_count_, other->point_count_); - std::swap(feature_count_, other->feature_count_); - std::swap(distance_, other->distance_); - std::swap(elapsed_time_, other->elapsed_time_); - _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); -} - -::google::protobuf::Metadata RouteSummary::GetMetadata() const { - protobuf_AssignDescriptorsOnce(); - ::google::protobuf::Metadata metadata; - metadata.descriptor = RouteSummary_descriptor_; - metadata.reflection = RouteSummary_reflection_; - return metadata; -} - - -static const char* RouteGuide_method_names[] = { - "/examples.RouteGuide/GetFeature", - "/examples.RouteGuide/ListFeatures", - "/examples.RouteGuide/RecordRoute", - "/examples.RouteGuide/RouteChat", -}; - -RouteGuide::Stub* RouteGuide::NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel) { - RouteGuide::Stub* stub = new RouteGuide::Stub(); - stub->set_channel(channel); - return stub; -}; - -::grpc::Status RouteGuide::Stub::GetFeature(::grpc::ClientContext* context, const ::examples::Point& request, ::examples::Feature* response) { - return ::grpc::BlockingUnaryCall(channel(),::grpc::RpcMethod(RouteGuide_method_names[0]), context, request, response); -} - -::grpc::ClientAsyncResponseReader< ::examples::Feature>* RouteGuide::Stub::GetFeature(::grpc::ClientContext* context, const ::examples::Point& request, ::grpc::CompletionQueue* cq, void* tag) { - return new ::grpc::ClientAsyncResponseReader< ::examples::Feature>(channel(), cq, ::grpc::RpcMethod(RouteGuide_method_names[0]), context, request, tag); -} - -::grpc::ClientReader< ::examples::Feature>* RouteGuide::Stub::ListFeatures(::grpc::ClientContext* context, const ::examples::Rectangle& request) { - return new ::grpc::ClientReader< ::examples::Feature>(channel(),::grpc::RpcMethod(RouteGuide_method_names[1], ::grpc::RpcMethod::RpcType::SERVER_STREAMING), context, request); -} - -::grpc::ClientAsyncReader< ::examples::Feature>* RouteGuide::Stub::ListFeatures(::grpc::ClientContext* context, const ::examples::Rectangle& request, ::grpc::CompletionQueue* cq, void* tag) { - return new ::grpc::ClientAsyncReader< ::examples::Feature>(channel(), cq, ::grpc::RpcMethod(RouteGuide_method_names[1], ::grpc::RpcMethod::RpcType::SERVER_STREAMING), context, request, tag); -} - -::grpc::ClientWriter< ::examples::Point>* RouteGuide::Stub::RecordRoute(::grpc::ClientContext* context, ::examples::RouteSummary* response) { - return new ::grpc::ClientWriter< ::examples::Point>(channel(),::grpc::RpcMethod(RouteGuide_method_names[2], ::grpc::RpcMethod::RpcType::CLIENT_STREAMING), context, response); -} - -::grpc::ClientAsyncWriter< ::examples::Point>* RouteGuide::Stub::RecordRoute(::grpc::ClientContext* context, ::examples::RouteSummary* response, ::grpc::CompletionQueue* cq, void* tag) { - return new ::grpc::ClientAsyncWriter< ::examples::Point>(channel(), cq, ::grpc::RpcMethod(RouteGuide_method_names[2], ::grpc::RpcMethod::RpcType::CLIENT_STREAMING), context, response, tag); -} - -::grpc::ClientReaderWriter< ::examples::RouteNote, ::examples::RouteNote>* RouteGuide::Stub::RouteChat(::grpc::ClientContext* context) { - return new ::grpc::ClientReaderWriter< ::examples::RouteNote, ::examples::RouteNote>(channel(),::grpc::RpcMethod(RouteGuide_method_names[3], ::grpc::RpcMethod::RpcType::BIDI_STREAMING), context); -} - -::grpc::ClientAsyncReaderWriter< ::examples::RouteNote, ::examples::RouteNote>* RouteGuide::Stub::RouteChat(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) { - return new ::grpc::ClientAsyncReaderWriter< ::examples::RouteNote, ::examples::RouteNote>(channel(), cq, ::grpc::RpcMethod(RouteGuide_method_names[3], ::grpc::RpcMethod::RpcType::BIDI_STREAMING), context, tag); -} - -RouteGuide::AsyncService::AsyncService(::grpc::CompletionQueue* cq) : ::grpc::AsynchronousService(cq, RouteGuide_method_names, 4) {} - -RouteGuide::Service::~Service() { - delete service_; -} - -::grpc::Status RouteGuide::Service::GetFeature(::grpc::ServerContext* context, const ::examples::Point* request, ::examples::Feature* response) { - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED); -} - -void RouteGuide::AsyncService::RequestGetFeature(::grpc::ServerContext* context, ::examples::Point* request, ::grpc::ServerAsyncResponseWriter< ::examples::Feature>* response, ::grpc::CompletionQueue* cq, void* tag) { - AsynchronousService::RequestAsyncUnary(0, context, request, response, cq, tag); -} - -::grpc::Status RouteGuide::Service::ListFeatures(::grpc::ServerContext* context, const ::examples::Rectangle* request, ::grpc::ServerWriter< ::examples::Feature>* writer) { - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED); -} - -void RouteGuide::AsyncService::RequestListFeatures(::grpc::ServerContext* context, ::examples::Rectangle* request, ::grpc::ServerAsyncWriter< ::examples::Feature>* writer, ::grpc::CompletionQueue* cq, void* tag) { - AsynchronousService::RequestServerStreaming(1, context, request, writer, cq, tag); -} - -::grpc::Status RouteGuide::Service::RecordRoute(::grpc::ServerContext* context, ::grpc::ServerReader< ::examples::Point>* reader, ::examples::RouteSummary* response) { - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED); -} - -void RouteGuide::AsyncService::RequestRecordRoute(::grpc::ServerContext* context, ::grpc::ServerAsyncReader< ::examples::RouteSummary, ::examples::Point>* reader, ::grpc::CompletionQueue* cq, void* tag) { - AsynchronousService::RequestClientStreaming(2, context, reader, cq, tag); -} - -::grpc::Status RouteGuide::Service::RouteChat(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::examples::RouteNote, ::examples::RouteNote>* stream) { - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED); -} - -void RouteGuide::AsyncService::RequestRouteChat(::grpc::ServerContext* context, ::grpc::ServerAsyncReaderWriter< ::examples::RouteNote, ::examples::RouteNote>* stream, ::grpc::CompletionQueue* cq, void *tag) { - AsynchronousService::RequestBidiStreaming(3, context, stream, cq, tag); -} - -::grpc::RpcService* RouteGuide::Service::service() { - if (service_ != nullptr) { - return service_; - } - service_ = new ::grpc::RpcService(); - service_->AddMethod(new ::grpc::RpcServiceMethod( - RouteGuide_method_names[0], - ::grpc::RpcMethod::NORMAL_RPC, - new ::grpc::RpcMethodHandler< RouteGuide::Service, ::examples::Point, ::examples::Feature>( - std::function< ::grpc::Status(RouteGuide::Service*, ::grpc::ServerContext*, const ::examples::Point*, ::examples::Feature*)>(&RouteGuide::Service::GetFeature), this), - new ::examples::Point, new ::examples::Feature)); - service_->AddMethod(new ::grpc::RpcServiceMethod( - RouteGuide_method_names[1], - ::grpc::RpcMethod::SERVER_STREAMING, - new ::grpc::ServerStreamingHandler< RouteGuide::Service, ::examples::Rectangle, ::examples::Feature>( - std::function< ::grpc::Status(RouteGuide::Service*, ::grpc::ServerContext*, const ::examples::Rectangle*, ::grpc::ServerWriter< ::examples::Feature>*)>(&RouteGuide::Service::ListFeatures), this), - new ::examples::Rectangle, new ::examples::Feature)); - service_->AddMethod(new ::grpc::RpcServiceMethod( - RouteGuide_method_names[2], - ::grpc::RpcMethod::CLIENT_STREAMING, - new ::grpc::ClientStreamingHandler< RouteGuide::Service, ::examples::Point, ::examples::RouteSummary>( - std::function< ::grpc::Status(RouteGuide::Service*, ::grpc::ServerContext*, ::grpc::ServerReader< ::examples::Point>*, ::examples::RouteSummary*)>(&RouteGuide::Service::RecordRoute), this), - new ::examples::Point, new ::examples::RouteSummary)); - service_->AddMethod(new ::grpc::RpcServiceMethod( - RouteGuide_method_names[3], - ::grpc::RpcMethod::BIDI_STREAMING, - new ::grpc::BidiStreamingHandler< RouteGuide::Service, ::examples::RouteNote, ::examples::RouteNote>( - std::function< ::grpc::Status(RouteGuide::Service*, ::grpc::ServerContext*, ::grpc::ServerReaderWriter< ::examples::RouteNote, ::examples::RouteNote>*)>(&RouteGuide::Service::RouteChat), this), - new ::examples::RouteNote, new ::examples::RouteNote)); - return service_; -} - - -// @@protoc_insertion_point(namespace_scope) - -} // namespace examples - -// @@protoc_insertion_point(global_scope) diff --git a/cpp/route_guide/route_guide.pb.h b/cpp/route_guide/route_guide.pb.h deleted file mode 100644 index 7689003..0000000 --- a/cpp/route_guide/route_guide.pb.h +++ /dev/null @@ -1,929 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: route_guide.proto - -#ifndef PROTOBUF_route_5fguide_2eproto__INCLUDED -#define PROTOBUF_route_5fguide_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 3000000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 3000000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace grpc { -class CompletionQueue; -class ChannelInterface; -class RpcService; -class ServerContext; -template class ClientAsyncResponseReader; -template class ServerAsyncResponseWriter; -template class ClientWriter; -template class ServerReader; -template class ClientAsyncWriter; -template class ServerAsyncReader; -template class ClientReader; -template class ServerWriter; -template class ClientAsyncReader; -template class ServerAsyncWriter; -template -class ClientReaderWriter; -template -class ServerReaderWriter; -template -class ClientAsyncReaderWriter; -template -class ServerAsyncReaderWriter; -} // namespace grpc -// @@protoc_insertion_point(includes) - -namespace examples { - -// Internal implementation detail -- do not call these. -void protobuf_AddDesc_route_5fguide_2eproto(); -void protobuf_AssignDesc_route_5fguide_2eproto(); -void protobuf_ShutdownFile_route_5fguide_2eproto(); - -class Point; -class Rectangle; -class Feature; -class RouteNote; -class RouteSummary; - -// =================================================================== - -class Point : public ::google::protobuf::Message { - public: - Point(); - virtual ~Point(); - - Point(const Point& from); - - inline Point& operator=(const Point& from) { - CopyFrom(from); - return *this; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const Point& default_instance(); - - void Swap(Point* other); - - // implements Message ---------------------------------------------- - - inline Point* New() const { return New(NULL); } - - Point* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const Point& from); - void MergeFrom(const Point& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(Point* other); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 latitude = 1; - inline void clear_latitude(); - static const int kLatitudeFieldNumber = 1; - inline ::google::protobuf::int32 latitude() const; - inline void set_latitude(::google::protobuf::int32 value); - - // optional int32 longitude = 2; - inline void clear_longitude(); - static const int kLongitudeFieldNumber = 2; - inline ::google::protobuf::int32 longitude() const; - inline void set_longitude(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:examples.Point) - private: - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - bool _is_default_instance_; - ::google::protobuf::int32 latitude_; - ::google::protobuf::int32 longitude_; - mutable int _cached_size_; - friend void protobuf_AddDesc_route_5fguide_2eproto(); - friend void protobuf_AssignDesc_route_5fguide_2eproto(); - friend void protobuf_ShutdownFile_route_5fguide_2eproto(); - - void InitAsDefaultInstance(); - static Point* default_instance_; -}; -// ------------------------------------------------------------------- - -class Rectangle : public ::google::protobuf::Message { - public: - Rectangle(); - virtual ~Rectangle(); - - Rectangle(const Rectangle& from); - - inline Rectangle& operator=(const Rectangle& from) { - CopyFrom(from); - return *this; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const Rectangle& default_instance(); - - void Swap(Rectangle* other); - - // implements Message ---------------------------------------------- - - inline Rectangle* New() const { return New(NULL); } - - Rectangle* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const Rectangle& from); - void MergeFrom(const Rectangle& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(Rectangle* other); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional .examples.Point lo = 1; - inline bool has_lo() const; - inline void clear_lo(); - static const int kLoFieldNumber = 1; - inline const ::examples::Point& lo() const; - inline ::examples::Point* mutable_lo(); - inline ::examples::Point* release_lo(); - inline void set_allocated_lo(::examples::Point* lo); - - // optional .examples.Point hi = 2; - inline bool has_hi() const; - inline void clear_hi(); - static const int kHiFieldNumber = 2; - inline const ::examples::Point& hi() const; - inline ::examples::Point* mutable_hi(); - inline ::examples::Point* release_hi(); - inline void set_allocated_hi(::examples::Point* hi); - - // @@protoc_insertion_point(class_scope:examples.Rectangle) - private: - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - bool _is_default_instance_; - ::examples::Point* lo_; - ::examples::Point* hi_; - mutable int _cached_size_; - friend void protobuf_AddDesc_route_5fguide_2eproto(); - friend void protobuf_AssignDesc_route_5fguide_2eproto(); - friend void protobuf_ShutdownFile_route_5fguide_2eproto(); - - void InitAsDefaultInstance(); - static Rectangle* default_instance_; -}; -// ------------------------------------------------------------------- - -class Feature : public ::google::protobuf::Message { - public: - Feature(); - virtual ~Feature(); - - Feature(const Feature& from); - - inline Feature& operator=(const Feature& from) { - CopyFrom(from); - return *this; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const Feature& default_instance(); - - void Swap(Feature* other); - - // implements Message ---------------------------------------------- - - inline Feature* New() const { return New(NULL); } - - Feature* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const Feature& from); - void MergeFrom(const Feature& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(Feature* other); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string name = 1; - inline void clear_name(); - static const int kNameFieldNumber = 1; - inline const ::std::string& name() const; - inline void set_name(const ::std::string& value); - inline void set_name(const char* value); - inline void set_name(const char* value, size_t size); - inline ::std::string* mutable_name(); - inline ::std::string* release_name(); - inline void set_allocated_name(::std::string* name); - - // optional .examples.Point location = 2; - inline bool has_location() const; - inline void clear_location(); - static const int kLocationFieldNumber = 2; - inline const ::examples::Point& location() const; - inline ::examples::Point* mutable_location(); - inline ::examples::Point* release_location(); - inline void set_allocated_location(::examples::Point* location); - - // @@protoc_insertion_point(class_scope:examples.Feature) - private: - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - bool _is_default_instance_; - ::google::protobuf::internal::ArenaStringPtr name_; - ::examples::Point* location_; - mutable int _cached_size_; - friend void protobuf_AddDesc_route_5fguide_2eproto(); - friend void protobuf_AssignDesc_route_5fguide_2eproto(); - friend void protobuf_ShutdownFile_route_5fguide_2eproto(); - - void InitAsDefaultInstance(); - static Feature* default_instance_; -}; -// ------------------------------------------------------------------- - -class RouteNote : public ::google::protobuf::Message { - public: - RouteNote(); - virtual ~RouteNote(); - - RouteNote(const RouteNote& from); - - inline RouteNote& operator=(const RouteNote& from) { - CopyFrom(from); - return *this; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const RouteNote& default_instance(); - - void Swap(RouteNote* other); - - // implements Message ---------------------------------------------- - - inline RouteNote* New() const { return New(NULL); } - - RouteNote* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const RouteNote& from); - void MergeFrom(const RouteNote& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(RouteNote* other); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional .examples.Point location = 1; - inline bool has_location() const; - inline void clear_location(); - static const int kLocationFieldNumber = 1; - inline const ::examples::Point& location() const; - inline ::examples::Point* mutable_location(); - inline ::examples::Point* release_location(); - inline void set_allocated_location(::examples::Point* location); - - // optional string message = 2; - inline void clear_message(); - static const int kMessageFieldNumber = 2; - inline const ::std::string& message() const; - inline void set_message(const ::std::string& value); - inline void set_message(const char* value); - inline void set_message(const char* value, size_t size); - inline ::std::string* mutable_message(); - inline ::std::string* release_message(); - inline void set_allocated_message(::std::string* message); - - // @@protoc_insertion_point(class_scope:examples.RouteNote) - private: - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - bool _is_default_instance_; - ::examples::Point* location_; - ::google::protobuf::internal::ArenaStringPtr message_; - mutable int _cached_size_; - friend void protobuf_AddDesc_route_5fguide_2eproto(); - friend void protobuf_AssignDesc_route_5fguide_2eproto(); - friend void protobuf_ShutdownFile_route_5fguide_2eproto(); - - void InitAsDefaultInstance(); - static RouteNote* default_instance_; -}; -// ------------------------------------------------------------------- - -class RouteSummary : public ::google::protobuf::Message { - public: - RouteSummary(); - virtual ~RouteSummary(); - - RouteSummary(const RouteSummary& from); - - inline RouteSummary& operator=(const RouteSummary& from) { - CopyFrom(from); - return *this; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const RouteSummary& default_instance(); - - void Swap(RouteSummary* other); - - // implements Message ---------------------------------------------- - - inline RouteSummary* New() const { return New(NULL); } - - RouteSummary* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const RouteSummary& from); - void MergeFrom(const RouteSummary& from); - void Clear(); - bool IsInitialized() const; - - int ByteSize() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(RouteSummary* other); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 point_count = 1; - inline void clear_point_count(); - static const int kPointCountFieldNumber = 1; - inline ::google::protobuf::int32 point_count() const; - inline void set_point_count(::google::protobuf::int32 value); - - // optional int32 feature_count = 2; - inline void clear_feature_count(); - static const int kFeatureCountFieldNumber = 2; - inline ::google::protobuf::int32 feature_count() const; - inline void set_feature_count(::google::protobuf::int32 value); - - // optional int32 distance = 3; - inline void clear_distance(); - static const int kDistanceFieldNumber = 3; - inline ::google::protobuf::int32 distance() const; - inline void set_distance(::google::protobuf::int32 value); - - // optional int32 elapsed_time = 4; - inline void clear_elapsed_time(); - static const int kElapsedTimeFieldNumber = 4; - inline ::google::protobuf::int32 elapsed_time() const; - inline void set_elapsed_time(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:examples.RouteSummary) - private: - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - bool _is_default_instance_; - ::google::protobuf::int32 point_count_; - ::google::protobuf::int32 feature_count_; - ::google::protobuf::int32 distance_; - ::google::protobuf::int32 elapsed_time_; - mutable int _cached_size_; - friend void protobuf_AddDesc_route_5fguide_2eproto(); - friend void protobuf_AssignDesc_route_5fguide_2eproto(); - friend void protobuf_ShutdownFile_route_5fguide_2eproto(); - - void InitAsDefaultInstance(); - static RouteSummary* default_instance_; -}; -// =================================================================== - - -// =================================================================== - -// Point - -// optional int32 latitude = 1; -inline void Point::clear_latitude() { - latitude_ = 0; -} -inline ::google::protobuf::int32 Point::latitude() const { - // @@protoc_insertion_point(field_get:examples.Point.latitude) - return latitude_; -} -inline void Point::set_latitude(::google::protobuf::int32 value) { - - latitude_ = value; - // @@protoc_insertion_point(field_set:examples.Point.latitude) -} - -// optional int32 longitude = 2; -inline void Point::clear_longitude() { - longitude_ = 0; -} -inline ::google::protobuf::int32 Point::longitude() const { - // @@protoc_insertion_point(field_get:examples.Point.longitude) - return longitude_; -} -inline void Point::set_longitude(::google::protobuf::int32 value) { - - longitude_ = value; - // @@protoc_insertion_point(field_set:examples.Point.longitude) -} - -// ------------------------------------------------------------------- - -// Rectangle - -// optional .examples.Point lo = 1; -inline bool Rectangle::has_lo() const { - return !_is_default_instance_ && lo_ != NULL; -} -inline void Rectangle::clear_lo() { - if (lo_ != NULL) delete lo_; - lo_ = NULL; -} -inline const ::examples::Point& Rectangle::lo() const { - // @@protoc_insertion_point(field_get:examples.Rectangle.lo) - return lo_ != NULL ? *lo_ : *default_instance_->lo_; -} -inline ::examples::Point* Rectangle::mutable_lo() { - - if (lo_ == NULL) { - lo_ = new ::examples::Point; - } - // @@protoc_insertion_point(field_mutable:examples.Rectangle.lo) - return lo_; -} -inline ::examples::Point* Rectangle::release_lo() { - - ::examples::Point* temp = lo_; - lo_ = NULL; - return temp; -} -inline void Rectangle::set_allocated_lo(::examples::Point* lo) { - delete lo_; - lo_ = lo; - if (lo) { - - } else { - - } - // @@protoc_insertion_point(field_set_allocated:examples.Rectangle.lo) -} - -// optional .examples.Point hi = 2; -inline bool Rectangle::has_hi() const { - return !_is_default_instance_ && hi_ != NULL; -} -inline void Rectangle::clear_hi() { - if (hi_ != NULL) delete hi_; - hi_ = NULL; -} -inline const ::examples::Point& Rectangle::hi() const { - // @@protoc_insertion_point(field_get:examples.Rectangle.hi) - return hi_ != NULL ? *hi_ : *default_instance_->hi_; -} -inline ::examples::Point* Rectangle::mutable_hi() { - - if (hi_ == NULL) { - hi_ = new ::examples::Point; - } - // @@protoc_insertion_point(field_mutable:examples.Rectangle.hi) - return hi_; -} -inline ::examples::Point* Rectangle::release_hi() { - - ::examples::Point* temp = hi_; - hi_ = NULL; - return temp; -} -inline void Rectangle::set_allocated_hi(::examples::Point* hi) { - delete hi_; - hi_ = hi; - if (hi) { - - } else { - - } - // @@protoc_insertion_point(field_set_allocated:examples.Rectangle.hi) -} - -// ------------------------------------------------------------------- - -// Feature - -// optional string name = 1; -inline void Feature::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline const ::std::string& Feature::name() const { - // @@protoc_insertion_point(field_get:examples.Feature.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void Feature::set_name(const ::std::string& value) { - - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:examples.Feature.name) -} -inline void Feature::set_name(const char* value) { - - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:examples.Feature.name) -} -inline void Feature::set_name(const char* value, size_t size) { - - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:examples.Feature.name) -} -inline ::std::string* Feature::mutable_name() { - - // @@protoc_insertion_point(field_mutable:examples.Feature.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* Feature::release_name() { - - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void Feature::set_allocated_name(::std::string* name) { - if (name != NULL) { - - } else { - - } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); - // @@protoc_insertion_point(field_set_allocated:examples.Feature.name) -} - -// optional .examples.Point location = 2; -inline bool Feature::has_location() const { - return !_is_default_instance_ && location_ != NULL; -} -inline void Feature::clear_location() { - if (location_ != NULL) delete location_; - location_ = NULL; -} -inline const ::examples::Point& Feature::location() const { - // @@protoc_insertion_point(field_get:examples.Feature.location) - return location_ != NULL ? *location_ : *default_instance_->location_; -} -inline ::examples::Point* Feature::mutable_location() { - - if (location_ == NULL) { - location_ = new ::examples::Point; - } - // @@protoc_insertion_point(field_mutable:examples.Feature.location) - return location_; -} -inline ::examples::Point* Feature::release_location() { - - ::examples::Point* temp = location_; - location_ = NULL; - return temp; -} -inline void Feature::set_allocated_location(::examples::Point* location) { - delete location_; - location_ = location; - if (location) { - - } else { - - } - // @@protoc_insertion_point(field_set_allocated:examples.Feature.location) -} - -// ------------------------------------------------------------------- - -// RouteNote - -// optional .examples.Point location = 1; -inline bool RouteNote::has_location() const { - return !_is_default_instance_ && location_ != NULL; -} -inline void RouteNote::clear_location() { - if (location_ != NULL) delete location_; - location_ = NULL; -} -inline const ::examples::Point& RouteNote::location() const { - // @@protoc_insertion_point(field_get:examples.RouteNote.location) - return location_ != NULL ? *location_ : *default_instance_->location_; -} -inline ::examples::Point* RouteNote::mutable_location() { - - if (location_ == NULL) { - location_ = new ::examples::Point; - } - // @@protoc_insertion_point(field_mutable:examples.RouteNote.location) - return location_; -} -inline ::examples::Point* RouteNote::release_location() { - - ::examples::Point* temp = location_; - location_ = NULL; - return temp; -} -inline void RouteNote::set_allocated_location(::examples::Point* location) { - delete location_; - location_ = location; - if (location) { - - } else { - - } - // @@protoc_insertion_point(field_set_allocated:examples.RouteNote.location) -} - -// optional string message = 2; -inline void RouteNote::clear_message() { - message_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline const ::std::string& RouteNote::message() const { - // @@protoc_insertion_point(field_get:examples.RouteNote.message) - return message_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void RouteNote::set_message(const ::std::string& value) { - - message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:examples.RouteNote.message) -} -inline void RouteNote::set_message(const char* value) { - - message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:examples.RouteNote.message) -} -inline void RouteNote::set_message(const char* value, size_t size) { - - message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:examples.RouteNote.message) -} -inline ::std::string* RouteNote::mutable_message() { - - // @@protoc_insertion_point(field_mutable:examples.RouteNote.message) - return message_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* RouteNote::release_message() { - - return message_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void RouteNote::set_allocated_message(::std::string* message) { - if (message != NULL) { - - } else { - - } - message_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), message); - // @@protoc_insertion_point(field_set_allocated:examples.RouteNote.message) -} - -// ------------------------------------------------------------------- - -// RouteSummary - -// optional int32 point_count = 1; -inline void RouteSummary::clear_point_count() { - point_count_ = 0; -} -inline ::google::protobuf::int32 RouteSummary::point_count() const { - // @@protoc_insertion_point(field_get:examples.RouteSummary.point_count) - return point_count_; -} -inline void RouteSummary::set_point_count(::google::protobuf::int32 value) { - - point_count_ = value; - // @@protoc_insertion_point(field_set:examples.RouteSummary.point_count) -} - -// optional int32 feature_count = 2; -inline void RouteSummary::clear_feature_count() { - feature_count_ = 0; -} -inline ::google::protobuf::int32 RouteSummary::feature_count() const { - // @@protoc_insertion_point(field_get:examples.RouteSummary.feature_count) - return feature_count_; -} -inline void RouteSummary::set_feature_count(::google::protobuf::int32 value) { - - feature_count_ = value; - // @@protoc_insertion_point(field_set:examples.RouteSummary.feature_count) -} - -// optional int32 distance = 3; -inline void RouteSummary::clear_distance() { - distance_ = 0; -} -inline ::google::protobuf::int32 RouteSummary::distance() const { - // @@protoc_insertion_point(field_get:examples.RouteSummary.distance) - return distance_; -} -inline void RouteSummary::set_distance(::google::protobuf::int32 value) { - - distance_ = value; - // @@protoc_insertion_point(field_set:examples.RouteSummary.distance) -} - -// optional int32 elapsed_time = 4; -inline void RouteSummary::clear_elapsed_time() { - elapsed_time_ = 0; -} -inline ::google::protobuf::int32 RouteSummary::elapsed_time() const { - // @@protoc_insertion_point(field_get:examples.RouteSummary.elapsed_time) - return elapsed_time_; -} -inline void RouteSummary::set_elapsed_time(::google::protobuf::int32 value) { - - elapsed_time_ = value; - // @@protoc_insertion_point(field_set:examples.RouteSummary.elapsed_time) -} - - -class RouteGuide final { - public: - class Stub final : public ::grpc::InternalStub { - public: - ::grpc::Status GetFeature(::grpc::ClientContext* context, const ::examples::Point& request, ::examples::Feature* response); - ::grpc::ClientAsyncResponseReader< ::examples::Feature>* GetFeature(::grpc::ClientContext* context, const ::examples::Point& request, ::grpc::CompletionQueue* cq, void* tag); - ::grpc::ClientReader< ::examples::Feature>* ListFeatures(::grpc::ClientContext* context, const ::examples::Rectangle& request); - ::grpc::ClientAsyncReader< ::examples::Feature>* ListFeatures(::grpc::ClientContext* context, const ::examples::Rectangle& request, ::grpc::CompletionQueue* cq, void* tag); - ::grpc::ClientWriter< ::examples::Point>* RecordRoute(::grpc::ClientContext* context, ::examples::RouteSummary* response); - ::grpc::ClientAsyncWriter< ::examples::Point>* RecordRoute(::grpc::ClientContext* context, ::examples::RouteSummary* response, ::grpc::CompletionQueue* cq, void* tag); - ::grpc::ClientReaderWriter< ::examples::RouteNote, ::examples::RouteNote>* RouteChat(::grpc::ClientContext* context); - ::grpc::ClientAsyncReaderWriter< ::examples::RouteNote, ::examples::RouteNote>* RouteChat(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag); - }; - static Stub* NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel); - - class Service : public ::grpc::SynchronousService { - public: - Service() : service_(nullptr) {} - virtual ~Service(); - virtual ::grpc::Status GetFeature(::grpc::ServerContext* context, const ::examples::Point* request, ::examples::Feature* response); - virtual ::grpc::Status ListFeatures(::grpc::ServerContext* context, const ::examples::Rectangle* request, ::grpc::ServerWriter< ::examples::Feature>* writer); - virtual ::grpc::Status RecordRoute(::grpc::ServerContext* context, ::grpc::ServerReader< ::examples::Point>* reader, ::examples::RouteSummary* response); - virtual ::grpc::Status RouteChat(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::examples::RouteNote, ::examples::RouteNote>* stream); - ::grpc::RpcService* service() override final; - private: - ::grpc::RpcService* service_; - }; - class AsyncService final : public ::grpc::AsynchronousService { - public: - explicit AsyncService(::grpc::CompletionQueue* cq); - ~AsyncService() {}; - void RequestGetFeature(::grpc::ServerContext* context, ::examples::Point* request, ::grpc::ServerAsyncResponseWriter< ::examples::Feature>* response, ::grpc::CompletionQueue* cq, void *tag); - void RequestListFeatures(::grpc::ServerContext* context, ::examples::Rectangle* request, ::grpc::ServerAsyncWriter< ::examples::Feature>* writer, ::grpc::CompletionQueue* cq, void *tag); - void RequestRecordRoute(::grpc::ServerContext* context, ::grpc::ServerAsyncReader< ::examples::RouteSummary, ::examples::Point>* reader, ::grpc::CompletionQueue* cq, void *tag); - void RequestRouteChat(::grpc::ServerContext* context, ::grpc::ServerAsyncReaderWriter< ::examples::RouteNote, ::examples::RouteNote>* stream, ::grpc::CompletionQueue* cq, void *tag); - }; -}; - -// @@protoc_insertion_point(namespace_scope) - -} // namespace examples - -#ifndef SWIG -namespace google { -namespace protobuf { - - -} // namespace protobuf -} // namespace google -#endif // SWIG - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_route_5fguide_2eproto__INCLUDED diff --git a/cpp/route_guide/route_guide_client.cc b/cpp/route_guide/route_guide_client.cc index 4a51f5e..65ca3af 100644 --- a/cpp/route_guide/route_guide_client.cc +++ b/cpp/route_guide/route_guide_client.cc @@ -41,51 +41,110 @@ #include #include #include -#include "helloworld.pb.h" +#include +#include "route_guide.pb.h" using grpc::ChannelArguments; using grpc::ChannelInterface; using grpc::ClientContext; +using grpc::ClientReader; +using grpc::ClientReaderWriter; +using grpc::ClientWriter; using grpc::Status; -using helloworld::HelloRequest; -using helloworld::HelloReply; -using helloworld::Greeter; +using examples::Point; +using examples::Feature; +using examples::Rectangle; +using examples::RouteSummary; +using examples::RouteNote; +using examples::RouteGuide; -class GreeterClient { +class RouteGuideClient { public: - GreeterClient(std::shared_ptr channel) - : stub_(Greeter::NewStub(channel)) {} + RouteGuideClient(std::shared_ptr channel) + : stub_(RouteGuide::NewStub(channel)) {} - std::string SayHello(const std::string& user) { - HelloRequest request; - request.set_name(user); - HelloReply reply; + void GetFeature() { + Point point; + Feature feature; ClientContext context; - Status status = stub_->sayHello(&context, request, &reply); + Status status = stub_->GetFeature(&context, point, &feature); if (status.IsOk()) { - return reply.message(); + std::cout << "GetFeature rpc succeeded." << std::endl; } else { - return "Rpc failed"; + std::cout << "GetFeature rpc failed." << std::endl; + } + } + + void ListFeatures() { + Rectangle rect; + Feature feature; + ClientContext context; + + std::unique_ptr > reader( + stub_->ListFeatures(&context, rect)); + while (reader->Read(&feature)) { + std::cout << "Received feature" << std::endl; + } + Status status = reader->Finish(); + if (status.IsOk()) { + std::cout << "ListFeatures rpc succeeded." << std::endl; + } else { + std::cout << "ListFeatures rpc failed." << std::endl; + } + } + + void RecordRoute() { + Point point; + RouteSummary summary; + ClientContext context; + + std::unique_ptr > writer( + stub_->RecordRoute(&context, &summary)); + writer->WritesDone(); + Status status = writer->Finish(); + if (status.IsOk()) { + std::cout << "RecordRoute rpc succeeded." << std::endl; + } else { + std::cout << "RecordRoute rpc failed." << std::endl; + } + } + + void RouteChat() { + RouteNote server_note; + ClientContext context; + + std::unique_ptr > stream( + stub_->RouteChat(&context)); + stream->WritesDone(); + while (stream->Read(&server_note)) { + } + Status status = stream->Finish(); + if (status.IsOk()) { + std::cout << "RouteChat rpc succeeded." << std::endl; + } else { + std::cout << "RouteChat rpc failed." << std::endl; } } void Shutdown() { stub_.reset(); } private: - std::unique_ptr stub_; + std::unique_ptr stub_; }; int main(int argc, char** argv) { grpc_init(); - GreeterClient greeter( + RouteGuideClient guide( grpc::CreateChannel("localhost:50051", ChannelArguments())); - std::string user("world"); - std::string reply = greeter.SayHello(user); - std::cout << "Greeter received: " << reply << std::endl; - greeter.Shutdown(); + guide.GetFeature(); + guide.ListFeatures(); + guide.RecordRoute(); + guide.RouteChat(); + + guide.Shutdown(); grpc_shutdown(); } diff --git a/cpp/route_guide/route_guide_server.cc b/cpp/route_guide/route_guide_server.cc index 3a2ab60..718afba 100644 --- a/cpp/route_guide/route_guide_server.cc +++ b/cpp/route_guide/route_guide_server.cc @@ -41,28 +41,45 @@ #include #include #include -#include "helloworld.pb.h" +#include +#include "route_guide.pb.h" using grpc::Server; using grpc::ServerBuilder; using grpc::ServerContext; +using grpc::ServerReader; +using grpc::ServerReaderWriter; +using grpc::ServerWriter; using grpc::Status; -using helloworld::HelloRequest; -using helloworld::HelloReply; -using helloworld::Greeter; +using examples::Point; +using examples::Feature; +using examples::Rectangle; +using examples::RouteSummary; +using examples::RouteNote; +using examples::RouteGuide; -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()); +class RouteGuideImpl final : public RouteGuide::Service { + Status GetFeature(ServerContext* context, const Point* point, + Feature* feature) override { + return Status::OK; + } + Status ListFeatures(ServerContext* context, const Rectangle* rectangle, + ServerWriter* writer) override { + return Status::OK; + } + Status RecordRoute(ServerContext* context, ServerReader* reader, + RouteSummary* summary) override { + return Status::OK; + } + Status RouteChat(ServerContext* context, + ServerReaderWriter* stream) override { return Status::OK; } }; void RunServer() { std::string server_address("0.0.0.0:50051"); - GreeterServiceImpl service; + RouteGuideImpl service; ServerBuilder builder; builder.AddPort(server_address); From 6b3df7da6a468313c2220315d1d141d9fe9353b0 Mon Sep 17 00:00:00 2001 From: Yang Gao Date: Mon, 23 Feb 2015 00:54:35 -0800 Subject: [PATCH 04/12] client impl except db_parser --- cpp/route_guide/route_guide_client.cc | 169 +++++++++++++++++++++++--- 1 file changed, 150 insertions(+), 19 deletions(-) diff --git a/cpp/route_guide/route_guide_client.cc b/cpp/route_guide/route_guide_client.cc index 65ca3af..6dbe6b8 100644 --- a/cpp/route_guide/route_guide_client.cc +++ b/cpp/route_guide/route_guide_client.cc @@ -31,9 +31,14 @@ * */ +#include +#include #include #include +#include +#include #include +#include #include #include @@ -58,6 +63,33 @@ 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; +} + +bool ParseDb(stringstream stream, std::vector* feature_list) { + // TODO +} + class RouteGuideClient { public: RouteGuideClient(std::shared_ptr channel) @@ -66,14 +98,10 @@ class RouteGuideClient { void GetFeature() { Point point; Feature feature; - ClientContext context; - - Status status = stub_->GetFeature(&context, point, &feature); - if (status.IsOk()) { - std::cout << "GetFeature rpc succeeded." << std::endl; - } else { - std::cout << "GetFeature rpc failed." << std::endl; - } + point = MakePoint(409146138, -746188906); + GetOneFeature(point, &feature); + point = MakePoint(0, 0); + GetOneFeature(point, &feature); } void ListFeatures() { @@ -81,10 +109,20 @@ class RouteGuideClient { 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 << "Received feature" << std::endl; + std::cout << "Found feature called " + << feature.name() << " at " + << feature.location().latitude()/kCoordFactor_ << ", " + << feature.location().latitude()/kCoordFactor_ << std::endl; } Status status = reader->Finish(); if (status.IsOk()) { @@ -96,41 +134,120 @@ class RouteGuideClient { void RecordRoute() { Point point; - RouteSummary summary; + RouteSummary stats; ClientContext context; + const int kPoints = 10; + std::default_random_engine generator; + 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, &summary)); + 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 << "RecordRoute rpc succeeded." << std::endl; + 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() { - RouteNote server_note; ClientContext context; - std::unique_ptr > stream( - stub_->RouteChat(&context)); - stream->WritesDone(); + ClientReaderWriter* 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.IsOk()) { - std::cout << "RouteChat rpc succeeded." << std::endl; - } else { + if (!status.IsOk()) { std::cout << "RouteChat rpc failed." << std::endl; } + delete stream; } void Shutdown() { stub_.reset(); } + void FillFeatureList(const std::string& db_path) { + if (db_path.empty()) { + return; + } + std::ifstream db_file(db_path); + if (!db_file.is_open()) { + std::cout << "Failed to open " << db_path << std::endl; + } + std::stringstream db; + db << db_file.rdbuf(); + ParseDb(db, &feature_list_); + } + private: + + bool GetOneFeature(const Point& point, Feature* feature) { + ClientContext context; + Status status = stub_->GetFeature(&context, point, feature); + if (!status.IsOk()) { + 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) { @@ -138,6 +255,20 @@ int main(int argc, char** argv) { RouteGuideClient guide( grpc::CreateChannel("localhost:50051", ChannelArguments())); + 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); + } + } + } + guide.FillFeatureList(db_path); guide.GetFeature(); guide.ListFeatures(); From 3906f35c453e9219bc1f7be0705ad0092d1e7044 Mon Sep 17 00:00:00 2001 From: Yang Gao Date: Mon, 23 Feb 2015 10:44:44 -0800 Subject: [PATCH 05/12] make things compile --- cpp/route_guide/route_guide_client.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cpp/route_guide/route_guide_client.cc b/cpp/route_guide/route_guide_client.cc index 6dbe6b8..86f603f 100644 --- a/cpp/route_guide/route_guide_client.cc +++ b/cpp/route_guide/route_guide_client.cc @@ -86,7 +86,7 @@ RouteNote MakeRouteNote(const std::string& message, return n; } -bool ParseDb(stringstream stream, std::vector* feature_list) { +bool ParseDb(const std::string& stream, std::vector* feature_list) { // TODO } @@ -173,8 +173,8 @@ class RouteGuideClient { void RouteChat() { ClientContext context; - ClientReaderWriter* stream = - stub_->RouteChat(&context); + std::shared_ptr > stream( + stub_->RouteChat(&context)); std::thread writer([stream]() { std::vector notes{ @@ -202,7 +202,6 @@ class RouteGuideClient { if (!status.IsOk()) { std::cout << "RouteChat rpc failed." << std::endl; } - delete stream; } void Shutdown() { stub_.reset(); } @@ -217,7 +216,7 @@ class RouteGuideClient { } std::stringstream db; db << db_file.rdbuf(); - ParseDb(db, &feature_list_); + ParseDb(db.str(), &feature_list_); } private: From ea33d60f71980f53e20c245768efe50683170e24 Mon Sep 17 00:00:00 2001 From: Yang Gao Date: Mon, 23 Feb 2015 13:55:33 -0800 Subject: [PATCH 06/12] Server impl. Status: builds. Missing db parsing logic --- cpp/route_guide/route_guide_client.cc | 24 +++-- cpp/route_guide/route_guide_server.cc | 143 +++++++++++++++++++++++++- 2 files changed, 154 insertions(+), 13 deletions(-) diff --git a/cpp/route_guide/route_guide_client.cc b/cpp/route_guide/route_guide_client.cc index 86f603f..8b4a532 100644 --- a/cpp/route_guide/route_guide_client.cc +++ b/cpp/route_guide/route_guide_client.cc @@ -90,6 +90,19 @@ bool ParseDb(const std::string& stream, std::vector* feature_list) { // TODO } +void FillFeatureList(const std::string& db_path, std::vector* feature_list) { + if (db_path.empty()) { + return; + } + std::ifstream db_file(db_path); + if (!db_file.is_open()) { + std::cout << "Failed to open " << db_path << std::endl; + } + std::stringstream db; + db << db_file.rdbuf(); + ParseDb(db.str(), feature_list); +} + class RouteGuideClient { public: RouteGuideClient(std::shared_ptr channel) @@ -207,16 +220,7 @@ class RouteGuideClient { void Shutdown() { stub_.reset(); } void FillFeatureList(const std::string& db_path) { - if (db_path.empty()) { - return; - } - std::ifstream db_file(db_path); - if (!db_file.is_open()) { - std::cout << "Failed to open " << db_path << std::endl; - } - std::stringstream db; - db << db_file.rdbuf(); - ParseDb(db.str(), &feature_list_); + ::FillFeatureList(db_path, &feature_list_); } private: diff --git a/cpp/route_guide/route_guide_server.cc b/cpp/route_guide/route_guide_server.cc index 718afba..d4ecded 100644 --- a/cpp/route_guide/route_guide_server.cc +++ b/cpp/route_guide/route_guide_server.cc @@ -31,8 +31,13 @@ * */ +#include +#include +#include +#include #include #include +#include #include #include @@ -57,29 +62,148 @@ using examples::Rectangle; using examples::RouteSummary; using examples::RouteNote; using examples::RouteGuide; +using std::chrono::system_clock; + +const float kCoordFactor = 10000000.0; + +bool ParseDb(const std::string& stream, std::vector* feature_list) { + // TODO +} + +float ConvertToRadians(float num) { + return num * 3.1415926 /180; +} + +float GetDistance(const Point& start, const Point& end) { + + 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; +} + +void FillFeatureList(const std::string& db_path, std::vector* feature_list) { + if (db_path.empty()) { + return; + } + std::ifstream db_file(db_path); + if (!db_file.is_open()) { + std::cout << "Failed to open " << db_path << std::endl; + } + std::stringstream db; + db << db_file.rdbuf(); + ParseDb(db.str(), feature_list); +} + +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: + RouteGuideImpl(const std::string& db_path) { + FillFeatureList(db_path, &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 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() { +void RunServer(const std::string& db_path) { std::string server_address("0.0.0.0:50051"); - RouteGuideImpl service; + RouteGuideImpl service(db_path); ServerBuilder builder; builder.AddPort(server_address); @@ -94,7 +218,20 @@ void RunServer() { int main(int argc, char** argv) { grpc_init(); - RunServer(); + 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); + } + } + } + RunServer(db_path); grpc_shutdown(); return 0; From 178fdf82e1538d3c2c34181cc66d7cb25d29096e Mon Sep 17 00:00:00 2001 From: Yang Gao Date: Mon, 23 Feb 2015 14:16:01 -0800 Subject: [PATCH 07/12] clean up a bit --- cpp/route_guide/Makefile | 4 +- cpp/route_guide/helper.cc | 73 +++++++++++++++++++++++++++ cpp/route_guide/helper.h | 50 ++++++++++++++++++ cpp/route_guide/route_guide_client.cc | 40 ++------------- cpp/route_guide/route_guide_server.cc | 43 +++------------- 5 files changed, 136 insertions(+), 74 deletions(-) create mode 100644 cpp/route_guide/helper.cc create mode 100644 cpp/route_guide/helper.h diff --git a/cpp/route_guide/Makefile b/cpp/route_guide/Makefile index fae9a9d..1319562 100644 --- a/cpp/route_guide/Makefile +++ b/cpp/route_guide/Makefile @@ -43,10 +43,10 @@ vpath %.proto $(PROTOS_PATH) all: system-check route_guide_client route_guide_server -route_guide_client: route_guide.pb.o route_guide_client.o +route_guide_client: route_guide.pb.o route_guide_client.o helper.o $(CXX) $^ $(LDFLAGS) -o $@ -route_guide_server: route_guide.pb.o route_guide_server.o +route_guide_server: route_guide.pb.o route_guide_server.o helper.o $(CXX) $^ $(LDFLAGS) -o $@ %.pb.cc: %.proto diff --git a/cpp/route_guide/helper.cc b/cpp/route_guide/helper.cc new file mode 100644 index 0000000..a4be8bf --- /dev/null +++ b/cpp/route_guide/helper.cc @@ -0,0 +1,73 @@ +/* + * + * 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 "route_guide.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); + } + } + } + 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(); +} + +void ParseDb(const std::string& db, std::vector* feature_list) { + +} + + +} // namespace examples + diff --git a/cpp/route_guide/helper.h b/cpp/route_guide/helper.h new file mode 100644 index 0000000..65c93c1 --- /dev/null +++ b/cpp/route_guide/helper.h @@ -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. + * + */ + +#ifndef GRPC_COMMON_CPP_ROUTE_GUIDE_HELPER_H_ +#define GRPC_COMMON_CPP_ROUTE_GUIDE_HELPER_H_ + +#include +#include + +namespace examples { +class Feature; + +std::string GetDbFileContent(int argc, char** argv); + +void ParseDb(const std::string& db, std::vector* feature_list); + +} // namespace examples + +#endif // GRPC_COMMON_CPP_ROUTE_GUIDE_HELPER_H_ + diff --git a/cpp/route_guide/route_guide_client.cc b/cpp/route_guide/route_guide_client.cc index 8b4a532..fd3d98e 100644 --- a/cpp/route_guide/route_guide_client.cc +++ b/cpp/route_guide/route_guide_client.cc @@ -32,11 +32,9 @@ */ #include -#include #include #include #include -#include #include #include @@ -47,6 +45,7 @@ #include #include #include +#include "helper.h" #include "route_guide.pb.h" using grpc::ChannelArguments; @@ -86,23 +85,6 @@ RouteNote MakeRouteNote(const std::string& message, return n; } -bool ParseDb(const std::string& stream, std::vector* feature_list) { - // TODO -} - -void FillFeatureList(const std::string& db_path, std::vector* feature_list) { - if (db_path.empty()) { - return; - } - std::ifstream db_file(db_path); - if (!db_file.is_open()) { - std::cout << "Failed to open " << db_path << std::endl; - } - std::stringstream db; - db << db_file.rdbuf(); - ParseDb(db.str(), feature_list); -} - class RouteGuideClient { public: RouteGuideClient(std::shared_ptr channel) @@ -219,8 +201,8 @@ class RouteGuideClient { void Shutdown() { stub_.reset(); } - void FillFeatureList(const std::string& db_path) { - ::FillFeatureList(db_path, &feature_list_); + void FillFeatureList(const std::string& db) { + examples::ParseDb(db, &feature_list_); } private: @@ -258,20 +240,8 @@ int main(int argc, char** argv) { RouteGuideClient guide( grpc::CreateChannel("localhost:50051", ChannelArguments())); - 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); - } - } - } - guide.FillFeatureList(db_path); + std::string db = examples::GetDbFileContent(argc, argv); + guide.FillFeatureList(db); guide.GetFeature(); guide.ListFeatures(); diff --git a/cpp/route_guide/route_guide_server.cc b/cpp/route_guide/route_guide_server.cc index d4ecded..38cd64b 100644 --- a/cpp/route_guide/route_guide_server.cc +++ b/cpp/route_guide/route_guide_server.cc @@ -34,10 +34,8 @@ #include #include #include -#include #include #include -#include #include #include @@ -47,6 +45,7 @@ #include #include #include +#include "helper.h" #include "route_guide.pb.h" using grpc::Server; @@ -64,18 +63,13 @@ using examples::RouteNote; using examples::RouteGuide; using std::chrono::system_clock; -const float kCoordFactor = 10000000.0; - -bool ParseDb(const std::string& stream, std::vector* feature_list) { - // TODO -} 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; @@ -93,19 +87,6 @@ float GetDistance(const Point& start, const Point& end) { return R * c; } -void FillFeatureList(const std::string& db_path, std::vector* feature_list) { - if (db_path.empty()) { - return; - } - std::ifstream db_file(db_path); - if (!db_file.is_open()) { - std::cout << "Failed to open " << db_path << std::endl; - } - std::stringstream db; - db << db_file.rdbuf(); - ParseDb(db.str(), feature_list); -} - std::string GetFeatureName(const Point& point, const std::vector& feature_list) { for (const Feature& f : feature_list) { @@ -119,8 +100,8 @@ std::string GetFeatureName(const Point& point, class RouteGuideImpl final : public RouteGuide::Service { public: - RouteGuideImpl(const std::string& db_path) { - FillFeatureList(db_path, &feature_list_); + RouteGuideImpl(const std::string& db) { + examples::ParseDb(db, &feature_list_); } Status GetFeature(ServerContext* context, const Point* point, @@ -218,20 +199,8 @@ void RunServer(const std::string& db_path) { int main(int argc, char** argv) { grpc_init(); - 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); - } - } - } - RunServer(db_path); + std::string db = examples::GetDbFileContent(argc, argv); + RunServer(db); grpc_shutdown(); return 0; From dbc06dd84c80d0f2211f24d65d786367e140e1cb Mon Sep 17 00:00:00 2001 From: Yang Gao Date: Mon, 23 Feb 2015 14:26:28 -0800 Subject: [PATCH 08/12] more cleanup --- cpp/route_guide/helper.cc | 1 + cpp/route_guide/route_guide_client.cc | 17 ++++++++--------- cpp/route_guide/route_guide_server.cc | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cpp/route_guide/helper.cc b/cpp/route_guide/helper.cc index a4be8bf..8c04489 100644 --- a/cpp/route_guide/helper.cc +++ b/cpp/route_guide/helper.cc @@ -65,6 +65,7 @@ std::string GetDbFileContent(int argc, char** argv) { } void ParseDb(const std::string& db, std::vector* feature_list) { + feature_list->clear(); } diff --git a/cpp/route_guide/route_guide_client.cc b/cpp/route_guide/route_guide_client.cc index fd3d98e..01c48c9 100644 --- a/cpp/route_guide/route_guide_client.cc +++ b/cpp/route_guide/route_guide_client.cc @@ -87,8 +87,11 @@ RouteNote MakeRouteNote(const std::string& message, class RouteGuideClient { public: - RouteGuideClient(std::shared_ptr channel) - : stub_(RouteGuide::NewStub(channel)) {} + RouteGuideClient(std::shared_ptr channel, + const std::string& db) + : stub_(RouteGuide::NewStub(channel)) { + examples::ParseDb(db, &feature_list_); + } void GetFeature() { Point point; @@ -201,10 +204,6 @@ class RouteGuideClient { void Shutdown() { stub_.reset(); } - void FillFeatureList(const std::string& db) { - examples::ParseDb(db, &feature_list_); - } - private: bool GetOneFeature(const Point& point, Feature* feature) { @@ -238,10 +237,10 @@ class RouteGuideClient { int main(int argc, char** argv) { grpc_init(); - RouteGuideClient guide( - grpc::CreateChannel("localhost:50051", ChannelArguments())); std::string db = examples::GetDbFileContent(argc, argv); - guide.FillFeatureList(db); + RouteGuideClient guide( + grpc::CreateChannel("localhost:50051", ChannelArguments()), + db); guide.GetFeature(); guide.ListFeatures(); diff --git a/cpp/route_guide/route_guide_server.cc b/cpp/route_guide/route_guide_server.cc index 38cd64b..62fee24 100644 --- a/cpp/route_guide/route_guide_server.cc +++ b/cpp/route_guide/route_guide_server.cc @@ -100,7 +100,7 @@ std::string GetFeatureName(const Point& point, class RouteGuideImpl final : public RouteGuide::Service { public: - RouteGuideImpl(const std::string& db) { + explicit RouteGuideImpl(const std::string& db) { examples::ParseDb(db, &feature_list_); } From 9b7f104ee3ed7a7514f1aa887147df76497f585b Mon Sep 17 00:00:00 2001 From: Yang Gao Date: Mon, 23 Feb 2015 17:00:07 -0800 Subject: [PATCH 09/12] Add a simple parser --- cpp/route_guide/helper.cc | 102 +++++ cpp/route_guide/route_guide_db.json | 601 ++++++++++++++++++++++++++++ 2 files changed, 703 insertions(+) create mode 100644 cpp/route_guide/route_guide_db.json diff --git a/cpp/route_guide/helper.cc b/cpp/route_guide/helper.cc index 8c04489..3e10496 100644 --- a/cpp/route_guide/helper.cc +++ b/cpp/route_guide/helper.cc @@ -31,6 +31,8 @@ * */ +#include +#include #include #include #include @@ -64,9 +66,109 @@ std::string GetDbFileContent(int argc, char** argv) { 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; } diff --git a/cpp/route_guide/route_guide_db.json b/cpp/route_guide/route_guide_db.json new file mode 100644 index 0000000..9d6a980 --- /dev/null +++ b/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" +}] From f65c93abde35c9999096812b60cb891eb965ef50 Mon Sep 17 00:00:00 2001 From: Yang Gao Date: Mon, 23 Feb 2015 22:01:56 -0800 Subject: [PATCH 10/12] Add more logs --- cpp/route_guide/route_guide_client.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cpp/route_guide/route_guide_client.cc b/cpp/route_guide/route_guide_client.cc index 01c48c9..5fb1697 100644 --- a/cpp/route_guide/route_guide_client.cc +++ b/cpp/route_guide/route_guide_client.cc @@ -242,9 +242,13 @@ int main(int argc, char** argv) { grpc::CreateChannel("localhost:50051", 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(); guide.Shutdown(); From 57d306e78ef329842d89bfe9a1aee6583241c0be Mon Sep 17 00:00:00 2001 From: Yang Gao Date: Mon, 23 Feb 2015 22:40:19 -0800 Subject: [PATCH 11/12] Sync-up API change and seed the random generator --- cpp/route_guide/route_guide_client.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cpp/route_guide/route_guide_client.cc b/cpp/route_guide/route_guide_client.cc index 5fb1697..acb8dd4 100644 --- a/cpp/route_guide/route_guide_client.cc +++ b/cpp/route_guide/route_guide_client.cc @@ -135,7 +135,9 @@ class RouteGuideClient { RouteSummary stats; ClientContext context; const int kPoints = 10; - std::default_random_engine generator; + 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( @@ -239,7 +241,7 @@ int main(int argc, char** argv) { std::string db = examples::GetDbFileContent(argc, argv); RouteGuideClient guide( - grpc::CreateChannel("localhost:50051", ChannelArguments()), + grpc::CreateChannelDeprecated("localhost:50051", ChannelArguments()), db); std::cout << "-------------- GetFeature --------------" << std::endl; From 9f392590bba5b517fc82f7b25b9de71c4c707d6b Mon Sep 17 00:00:00 2001 From: Yang Gao Date: Mon, 23 Feb 2015 22:51:14 -0800 Subject: [PATCH 12/12] Add default json path --- cpp/route_guide/helper.cc | 2 ++ cpp/route_guide/route_guide_client.cc | 1 + cpp/route_guide/route_guide_server.cc | 1 + 3 files changed, 4 insertions(+) diff --git a/cpp/route_guide/helper.cc b/cpp/route_guide/helper.cc index 3e10496..d147846 100644 --- a/cpp/route_guide/helper.cc +++ b/cpp/route_guide/helper.cc @@ -55,6 +55,8 @@ std::string GetDbFileContent(int argc, char** argv) { 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()) { diff --git a/cpp/route_guide/route_guide_client.cc b/cpp/route_guide/route_guide_client.cc index acb8dd4..cbf4207 100644 --- a/cpp/route_guide/route_guide_client.cc +++ b/cpp/route_guide/route_guide_client.cc @@ -239,6 +239,7 @@ class RouteGuideClient { int main(int argc, char** argv) { grpc_init(); + // Expect only arg: --db_path=path/to/route_guide_db.json. std::string db = examples::GetDbFileContent(argc, argv); RouteGuideClient guide( grpc::CreateChannelDeprecated("localhost:50051", ChannelArguments()), diff --git a/cpp/route_guide/route_guide_server.cc b/cpp/route_guide/route_guide_server.cc index 62fee24..2699330 100644 --- a/cpp/route_guide/route_guide_server.cc +++ b/cpp/route_guide/route_guide_server.cc @@ -199,6 +199,7 @@ void RunServer(const std::string& db_path) { int main(int argc, char** argv) { grpc_init(); + // Expect only arg: --db_path=path/to/route_guide_db.json. std::string db = examples::GetDbFileContent(argc, argv); RunServer(db);