commit
038a71d826
286 changed files with 7990 additions and 7250 deletions
@ -0,0 +1,110 @@ |
||||
#
|
||||
# Copyright 2018 gRPC authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
|
||||
SYSTEM ?= $(HOST_SYSTEM)
|
||||
CXX = g++
|
||||
CPPFLAGS += `pkg-config --cflags protobuf grpc`
|
||||
CXXFLAGS += -std=c++11
|
||||
ifeq ($(SYSTEM),Darwin) |
||||
LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++ grpc`\
|
||||
-lgrpc++_reflection\
|
||||
-ldl
|
||||
else |
||||
LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++ grpc`\
|
||||
-Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed\
|
||||
-ldl
|
||||
endif |
||||
PROTOC = protoc
|
||||
GRPC_CPP_PLUGIN = grpc_cpp_plugin
|
||||
GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)`
|
||||
|
||||
PROTOS_PATH = ../../protos
|
||||
|
||||
vpath %.proto $(PROTOS_PATH) |
||||
|
||||
all: system-check greeter_client greeter_server |
||||
|
||||
greeter_client: helloworld.pb.o helloworld.grpc.pb.o greeter_client.o |
||||
$(CXX) $^ $(LDFLAGS) -o $@
|
||||
|
||||
greeter_server: helloworld.pb.o helloworld.grpc.pb.o greeter_server.o |
||||
$(CXX) $^ $(LDFLAGS) -o $@
|
||||
|
||||
.PRECIOUS: %.grpc.pb.cc |
||||
%.grpc.pb.cc: %.proto |
||||
$(PROTOC) -I $(PROTOS_PATH) --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $<
|
||||
|
||||
.PRECIOUS: %.pb.cc |
||||
%.pb.cc: %.proto |
||||
$(PROTOC) -I $(PROTOS_PATH) --cpp_out=. $<
|
||||
|
||||
clean: |
||||
rm -f *.o *.pb.cc *.pb.h greeter_client greeter_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"
|
||||
@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 |
@ -0,0 +1,84 @@ |
||||
# gRPC C++ Message Compression Tutorial |
||||
|
||||
### Prerequisite |
||||
Make sure you have run the [hello world example](../helloworld) or understood the basics of gRPC. We will not dive into the details that have been discussed in the hello world example. |
||||
|
||||
### Get the tutorial source code |
||||
|
||||
The example code for this and our other examples lives in the `examples` directory. Clone this repository to your local machine by running the following command: |
||||
|
||||
|
||||
```sh |
||||
$ git clone -b $(curl -L https://grpc.io/release) https://github.com/grpc/grpc |
||||
``` |
||||
|
||||
Change your current directory to examples/cpp/compression |
||||
|
||||
```sh |
||||
$ cd examples/cpp/compression/ |
||||
``` |
||||
|
||||
### Generating gRPC code |
||||
|
||||
To generate the client and server side interfaces: |
||||
|
||||
```sh |
||||
$ make helloworld.grpc.pb.cc helloworld.pb.cc |
||||
``` |
||||
Which internally invokes the proto-compiler as: |
||||
|
||||
```sh |
||||
$ protoc -I ../../protos/ --grpc_out=. --plugin=protoc-gen-grpc=grpc_cpp_plugin ../../protos/helloworld.proto |
||||
$ protoc -I ../../protos/ --cpp_out=. ../../protos/helloworld.proto |
||||
``` |
||||
|
||||
### Writing a client and a server |
||||
|
||||
The client and the server can be based on the hello world example. |
||||
|
||||
Additionally, we can configure the compression settings. |
||||
|
||||
In the client, set the default compression algorithm of the channel via the channel arg. |
||||
|
||||
```cpp |
||||
ChannelArguments args; |
||||
// Set the default compression algorithm for the channel. |
||||
args.SetCompressionAlgorithm(GRPC_COMPRESS_GZIP); |
||||
GreeterClient greeter(grpc::CreateCustomChannel( |
||||
"localhost:50051", grpc::InsecureChannelCredentials(), args)); |
||||
``` |
||||
|
||||
Each call's compression configuration can be overwritten by client context. |
||||
|
||||
```cpp |
||||
// Overwrite the call's compression algorithm to DEFLATE. |
||||
context.set_compression_algorithm(GRPC_COMPRESS_DEFLATE); |
||||
``` |
||||
|
||||
In the server, set the default compression algorithm via the server builder. |
||||
|
||||
```cpp |
||||
ServerBuilder builder; |
||||
// Set the default compression algorithm for the server. |
||||
builder.SetDefaultCompressionAlgorithm(GRPC_COMPRESS_GZIP); |
||||
``` |
||||
|
||||
Each call's compression configuration can be overwritten by server context. |
||||
|
||||
```cpp |
||||
// Overwrite the call's compression algorithm to DEFLATE. |
||||
context->set_compression_algorithm(GRPC_COMPRESS_DEFLATE); |
||||
``` |
||||
|
||||
For a working example, refer to [greeter_client.cc](greeter_client.cc) and [greeter_server.cc](greeter_server.cc). |
||||
|
||||
Build and run the (compressing) client and the server by the following commands. |
||||
|
||||
```sh |
||||
make |
||||
./greeter_server |
||||
``` |
||||
|
||||
```sh |
||||
./greeter_client |
||||
``` |
@ -0,0 +1,93 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2018 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#include <iostream> |
||||
#include <memory> |
||||
#include <string> |
||||
|
||||
#include <grpcpp/grpcpp.h> |
||||
|
||||
#ifdef BAZEL_BUILD |
||||
#include "examples/protos/helloworld.grpc.pb.h" |
||||
#else |
||||
#include "helloworld.grpc.pb.h" |
||||
#endif |
||||
|
||||
using grpc::Channel; |
||||
using grpc::ChannelArguments; |
||||
using grpc::ClientContext; |
||||
using grpc::Status; |
||||
using helloworld::HelloRequest; |
||||
using helloworld::HelloReply; |
||||
using helloworld::Greeter; |
||||
|
||||
class GreeterClient { |
||||
public: |
||||
GreeterClient(std::shared_ptr<Channel> channel) |
||||
: stub_(Greeter::NewStub(channel)) {} |
||||
|
||||
// Assembles the client's payload, sends it and presents the response back
|
||||
// from the server.
|
||||
std::string SayHello(const std::string& user) { |
||||
// Data we are sending to the server.
|
||||
HelloRequest request; |
||||
request.set_name(user); |
||||
|
||||
// Container for the data we expect from the server.
|
||||
HelloReply reply; |
||||
|
||||
// Context for the client. It could be used to convey extra information to
|
||||
// the server and/or tweak certain RPC behaviors.
|
||||
ClientContext context; |
||||
|
||||
// Overwrite the call's compression algorithm to DEFLATE.
|
||||
context.set_compression_algorithm(GRPC_COMPRESS_DEFLATE); |
||||
|
||||
// The actual RPC.
|
||||
Status status = stub_->SayHello(&context, request, &reply); |
||||
|
||||
// Act upon its status.
|
||||
if (status.ok()) { |
||||
return reply.message(); |
||||
} else { |
||||
std::cout << status.error_code() << ": " << status.error_message() |
||||
<< std::endl; |
||||
return "RPC failed"; |
||||
} |
||||
} |
||||
|
||||
private: |
||||
std::unique_ptr<Greeter::Stub> stub_; |
||||
}; |
||||
|
||||
int main(int argc, char** argv) { |
||||
// Instantiate the client. It requires a channel, out of which the actual RPCs
|
||||
// are created. This channel models a connection to an endpoint (in this case,
|
||||
// localhost at port 50051). We indicate that the channel isn't authenticated
|
||||
// (use of InsecureChannelCredentials()).
|
||||
ChannelArguments args; |
||||
// Set the default compression algorithm for the channel.
|
||||
args.SetCompressionAlgorithm(GRPC_COMPRESS_GZIP); |
||||
GreeterClient greeter(grpc::CreateCustomChannel( |
||||
"localhost:50051", grpc::InsecureChannelCredentials(), args)); |
||||
std::string user("world"); |
||||
std::string reply = greeter.SayHello(user); |
||||
std::cout << "Greeter received: " << reply << std::endl; |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,76 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2018 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#include <iostream> |
||||
#include <memory> |
||||
#include <string> |
||||
|
||||
#include <grpcpp/grpcpp.h> |
||||
|
||||
#ifdef BAZEL_BUILD |
||||
#include "examples/protos/helloworld.grpc.pb.h" |
||||
#else |
||||
#include "helloworld.grpc.pb.h" |
||||
#endif |
||||
|
||||
using grpc::Server; |
||||
using grpc::ServerBuilder; |
||||
using grpc::ServerContext; |
||||
using grpc::Status; |
||||
using helloworld::HelloRequest; |
||||
using helloworld::HelloReply; |
||||
using helloworld::Greeter; |
||||
|
||||
// Logic and data behind the server's behavior.
|
||||
class GreeterServiceImpl final : public Greeter::Service { |
||||
Status SayHello(ServerContext* context, const HelloRequest* request, |
||||
HelloReply* reply) override { |
||||
// Overwrite the call's compression algorithm to DEFLATE.
|
||||
context->set_compression_algorithm(GRPC_COMPRESS_DEFLATE); |
||||
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; |
||||
// Set the default compression algorithm for the server.
|
||||
builder.SetDefaultCompressionAlgorithm(GRPC_COMPRESS_GZIP); |
||||
// Listen on the given address without any authentication mechanism.
|
||||
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials()); |
||||
// Register "service" as the instance through which we'll communicate with
|
||||
// clients. In this case it corresponds to an *synchronous* service.
|
||||
builder.RegisterService(&service); |
||||
// Finally assemble the server.
|
||||
std::unique_ptr<Server> server(builder.BuildAndStart()); |
||||
std::cout << "Server listening on " << server_address << std::endl; |
||||
|
||||
// Wait for the server to shutdown. Note that some other thread must be
|
||||
// responsible for shutting down the server for this call to ever return.
|
||||
server->Wait(); |
||||
} |
||||
|
||||
int main(int argc, char** argv) { |
||||
RunServer(); |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,96 @@ |
||||
#
|
||||
# Copyright 2018 gRPC authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
|
||||
SYSTEM ?= $(HOST_SYSTEM)
|
||||
CXX = g++
|
||||
CPPFLAGS += `pkg-config --cflags protobuf grpc`
|
||||
CXXFLAGS += -std=c++11
|
||||
ifeq ($(SYSTEM),Darwin) |
||||
LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++ grpc`\
|
||||
-lgrpc++_reflection\
|
||||
-ldl
|
||||
else |
||||
LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++ grpc`\
|
||||
-Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed\
|
||||
-ldl
|
||||
endif |
||||
PROTOC = protoc
|
||||
GRPC_CPP_PLUGIN = grpc_cpp_plugin
|
||||
GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)`
|
||||
PROTOS_PATH = ../../protos
|
||||
vpath %.proto $(PROTOS_PATH)
|
||||
all: system-check greeter_client greeter_server
|
||||
greeter_client: helloworld.pb.o helloworld.grpc.pb.o greeter_client.o
|
||||
$(CXX) $^ $(LDFLAGS) -o $@
|
||||
greeter_server: helloworld.pb.o helloworld.grpc.pb.o greeter_server.o
|
||||
$(CXX) $^ $(LDFLAGS) -o $@
|
||||
.PRECIOUS: %.grpc.pb.cc
|
||||
%.grpc.pb.cc: %.proto |
||||
$(PROTOC) -I $(PROTOS_PATH) --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $<
|
||||
.PRECIOUS: %.pb.cc
|
||||
%.pb.cc: %.proto |
||||
$(PROTOC) -I $(PROTOS_PATH) --cpp_out=. $<
|
||||
clean:
|
||||
rm -f *.o *.pb.cc *.pb.h greeter_client greeter_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"
|
||||
@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 |
@ -0,0 +1,66 @@ |
||||
# Metadata Example |
||||
|
||||
## Overview |
||||
|
||||
This example shows you how to add custom headers on the client and server and |
||||
how to access them. |
||||
|
||||
Custom metadata must follow the "Custom-Metadata" format listed in |
||||
https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md, with the |
||||
exception of binary headers, which don't have to be base64 encoded. |
||||
|
||||
### Get the tutorial source code |
||||
The example code for this and our other examples lives in the `examples` directory. Clone this repository to your local machine by running the following command: |
||||
```sh |
||||
$ git clone -b $(curl -L https://grpc.io/release) https://github.com/grpc/grpc |
||||
``` |
||||
Change your current directory to examples/cpp/metadata |
||||
```sh |
||||
$ cd examples/cpp/metadata |
||||
``` |
||||
|
||||
### Generating gRPC code |
||||
To generate the client and server side interfaces: |
||||
```sh |
||||
$ make helloworld.grpc.pb.cc helloworld.pb.cc |
||||
``` |
||||
Which internally invokes the proto-compiler as: |
||||
```sh |
||||
$ protoc -I ../../protos/ --grpc_out=. --plugin=protoc-gen-grpc=grpc_cpp_plugin ../../protos/helloworld.proto |
||||
$ protoc -I ../../protos/ --cpp_out=. ../../protos/helloworld.proto |
||||
``` |
||||
### Try it! |
||||
Build client and server: |
||||
|
||||
```sh |
||||
$ make |
||||
``` |
||||
|
||||
Run the server, which will listen on port 50051: |
||||
|
||||
```sh |
||||
$ ./greeter_server |
||||
``` |
||||
|
||||
Run the client (in a different terminal): |
||||
|
||||
```sh |
||||
$ ./greeter_client |
||||
``` |
||||
|
||||
If things go smoothly, you will see in the client terminal: |
||||
|
||||
"Client received initial metadata from server: initial metadata value" |
||||
"Client received trailing metadata from server: trailing metadata value" |
||||
"Client received message: Hello World" |
||||
|
||||
|
||||
And in the server terminal: |
||||
|
||||
"Header key: custom-bin , value: 01234567" |
||||
"Header key: custom-header , value: Custom Value" |
||||
"Header key: user-agent , value: grpc-c++/1.16.0-dev grpc-c/6.0.0-dev (linux; chttp2; gao)" |
||||
|
||||
We did not add the user-agent metadata as a custom header. This shows how |
||||
the gRPC framework adds some headers under the hood that may show up in the |
||||
metadata map. |
@ -0,0 +1,95 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#include <iostream> |
||||
#include <memory> |
||||
#include <string> |
||||
|
||||
#include <grpcpp/grpcpp.h> |
||||
|
||||
#ifdef BAZEL_BUILD |
||||
#include "examples/protos/helloworld.grpc.pb.h" |
||||
#else |
||||
#include "helloworld.grpc.pb.h" |
||||
#endif |
||||
|
||||
using grpc::Channel; |
||||
using grpc::ClientContext; |
||||
using grpc::Status; |
||||
using helloworld::HelloRequest; |
||||
using helloworld::HelloReply; |
||||
using helloworld::Greeter; |
||||
|
||||
class CustomHeaderClient { |
||||
public: |
||||
CustomHeaderClient(std::shared_ptr<Channel> channel) |
||||
: stub_(Greeter::NewStub(channel)) {} |
||||
|
||||
// Assembles the client's payload, sends it and presents the response back
|
||||
// from the server.
|
||||
std::string SayHello(const std::string& user) { |
||||
// Data we are sending to the server.
|
||||
HelloRequest request; |
||||
request.set_name(user); |
||||
|
||||
// Container for the data we expect from the server.
|
||||
HelloReply reply; |
||||
|
||||
// Context for the client. It could be used to convey extra information to
|
||||
// the server and/or tweak certain RPC behaviors.
|
||||
ClientContext context; |
||||
|
||||
// Setting custom metadata to be sent to the server
|
||||
context.AddMetadata("custom-header", "Custom Value"); |
||||
|
||||
// Setting custom binary metadata
|
||||
char bytes[8] = {'\0', '\1', '\2', '\3', |
||||
'\4', '\5', '\6', '\7'}; |
||||
context.AddMetadata("custom-bin", grpc::string(bytes, 8)); |
||||
|
||||
// The actual RPC.
|
||||
Status status = stub_->SayHello(&context, request, &reply); |
||||
|
||||
// Act upon its status.
|
||||
if (status.ok()) { |
||||
std::cout << "Client received initial metadata from server: " << context.GetServerInitialMetadata().find("custom-server-metadata")->second << std::endl; |
||||
std::cout << "Client received trailing metadata from server: " << context.GetServerTrailingMetadata().find("custom-trailing-metadata")->second << std::endl; |
||||
return reply.message(); |
||||
} else { |
||||
std::cout << status.error_code() << ": " << status.error_message() |
||||
<< std::endl; |
||||
return "RPC failed"; |
||||
} |
||||
} |
||||
|
||||
private: |
||||
std::unique_ptr<Greeter::Stub> stub_; |
||||
}; |
||||
|
||||
int main(int argc, char** argv) { |
||||
// Instantiate the client. It requires a channel, out of which the actual RPCs
|
||||
// are created. This channel models a connection to an endpoint (in this case,
|
||||
// localhost at port 50051). We indicate that the channel isn't authenticated
|
||||
// (use of InsecureChannelCredentials()).
|
||||
CustomHeaderClient greeter(grpc::CreateChannel( |
||||
"localhost:50051", grpc::InsecureChannelCredentials())); |
||||
std::string user("world"); |
||||
std::string reply = greeter.SayHello(user); |
||||
std::cout << "Client received message: " << reply << std::endl; |
||||
return 0; |
||||
} |
@ -0,0 +1,94 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#include <iostream> |
||||
#include <memory> |
||||
#include <string> |
||||
|
||||
#include <grpcpp/grpcpp.h> |
||||
|
||||
#ifdef BAZEL_BUILD |
||||
#include "examples/protos/helloworld.grpc.pb.h" |
||||
#else |
||||
#include "helloworld.grpc.pb.h" |
||||
#endif |
||||
|
||||
using grpc::Server; |
||||
using grpc::ServerBuilder; |
||||
using grpc::ServerContext; |
||||
using grpc::Status; |
||||
using helloworld::HelloRequest; |
||||
using helloworld::HelloReply; |
||||
using helloworld::Greeter; |
||||
|
||||
// Logic and data behind the server's behavior.
|
||||
class GreeterServiceImpl final : public Greeter::Service { |
||||
Status SayHello(ServerContext* context, const HelloRequest* request, |
||||
HelloReply* reply) override { |
||||
std::string prefix("Hello "); |
||||
|
||||
// Get the client's initial metadata
|
||||
std::cout << "Client metadata: " << std::endl; |
||||
const std::multimap<grpc::string_ref, grpc::string_ref> metadata = context->client_metadata(); |
||||
for (auto iter = metadata.begin(); iter != metadata.end(); ++iter) { |
||||
std::cout << "Header key: " << iter->first << ", value: "; |
||||
// Check for binary value
|
||||
size_t isbin = iter->first.find("-bin"); |
||||
if ((isbin != std::string::npos) && (isbin + 4 == iter->first.size())) { |
||||
std::cout << std::hex; |
||||
for (auto c : iter->second) { |
||||
std::cout << static_cast<unsigned int>(c); |
||||
} |
||||
std::cout << std::dec; |
||||
} else { |
||||
std::cout << iter->second; |
||||
} |
||||
std::cout << std::endl; |
||||
} |
||||
|
||||
context->AddInitialMetadata("custom-server-metadata", "initial metadata value"); |
||||
context->AddTrailingMetadata("custom-trailing-metadata", "trailing metadata value"); |
||||
reply->set_message(prefix + request->name()); |
||||
return Status::OK; |
||||
} |
||||
}; |
||||
|
||||
void RunServer() { |
||||
std::string server_address("0.0.0.0:50051"); |
||||
GreeterServiceImpl service; |
||||
|
||||
ServerBuilder builder; |
||||
// Listen on the given address without any authentication mechanism.
|
||||
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials()); |
||||
// Register "service" as the instance through which we'll communicate with
|
||||
// clients. In this case it corresponds to an *synchronous* service.
|
||||
builder.RegisterService(&service); |
||||
// Finally assemble the server.
|
||||
std::unique_ptr<Server> server(builder.BuildAndStart()); |
||||
std::cout << "Server listening on " << server_address << std::endl; |
||||
|
||||
// Wait for the server to shutdown. Note that some other thread must be
|
||||
// responsible for shutting down the server for this call to ever return.
|
||||
server->Wait(); |
||||
} |
||||
|
||||
int main(int argc, char** argv) { |
||||
RunServer(); |
||||
|
||||
return 0; |
||||
} |
@ -1,5 +1,7 @@ |
||||
.vs/ |
||||
bin/ |
||||
obj/ |
||||
packages/ |
||||
*.suo |
||||
*.user |
||||
*.userprefs |
||||
|
@ -1,312 +0,0 @@ |
||||
// <auto-generated> |
||||
// Generated by the protocol buffer compiler. DO NOT EDIT! |
||||
// source: helloworld.proto |
||||
// </auto-generated> |
||||
#pragma warning disable 1591, 0612, 3021 |
||||
#region Designer generated code |
||||
|
||||
using pb = global::Google.Protobuf; |
||||
using pbc = global::Google.Protobuf.Collections; |
||||
using pbr = global::Google.Protobuf.Reflection; |
||||
using scg = global::System.Collections.Generic; |
||||
namespace Helloworld { |
||||
|
||||
/// <summary>Holder for reflection information generated from helloworld.proto</summary> |
||||
public static partial class HelloworldReflection { |
||||
|
||||
#region Descriptor |
||||
/// <summary>File descriptor for helloworld.proto</summary> |
||||
public static pbr::FileDescriptor Descriptor { |
||||
get { return descriptor; } |
||||
} |
||||
private static pbr::FileDescriptor descriptor; |
||||
|
||||
static HelloworldReflection() { |
||||
byte[] descriptorData = global::System.Convert.FromBase64String( |
||||
string.Concat( |
||||
"ChBoZWxsb3dvcmxkLnByb3RvEgpoZWxsb3dvcmxkIhwKDEhlbGxvUmVxdWVz", |
||||
"dBIMCgRuYW1lGAEgASgJIh0KCkhlbGxvUmVwbHkSDwoHbWVzc2FnZRgBIAEo", |
||||
"CTJJCgdHcmVldGVyEj4KCFNheUhlbGxvEhguaGVsbG93b3JsZC5IZWxsb1Jl", |
||||
"cXVlc3QaFi5oZWxsb3dvcmxkLkhlbGxvUmVwbHkiAEI2Chtpby5ncnBjLmV4", |
||||
"YW1wbGVzLmhlbGxvd29ybGRCD0hlbGxvV29ybGRQcm90b1ABogIDSExXYgZw", |
||||
"cm90bzM=")); |
||||
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, |
||||
new pbr::FileDescriptor[] { }, |
||||
new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { |
||||
new pbr::GeneratedClrTypeInfo(typeof(global::Helloworld.HelloRequest), global::Helloworld.HelloRequest.Parser, new[]{ "Name" }, null, null, null), |
||||
new pbr::GeneratedClrTypeInfo(typeof(global::Helloworld.HelloReply), global::Helloworld.HelloReply.Parser, new[]{ "Message" }, null, null, null) |
||||
})); |
||||
} |
||||
#endregion |
||||
|
||||
} |
||||
#region Messages |
||||
/// <summary> |
||||
/// The request message containing the user's name. |
||||
/// </summary> |
||||
public sealed partial class HelloRequest : pb::IMessage<HelloRequest> { |
||||
private static readonly pb::MessageParser<HelloRequest> _parser = new pb::MessageParser<HelloRequest>(() => new HelloRequest()); |
||||
private pb::UnknownFieldSet _unknownFields; |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public static pb::MessageParser<HelloRequest> Parser { get { return _parser; } } |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public static pbr::MessageDescriptor Descriptor { |
||||
get { return global::Helloworld.HelloworldReflection.Descriptor.MessageTypes[0]; } |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
pbr::MessageDescriptor pb::IMessage.Descriptor { |
||||
get { return Descriptor; } |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public HelloRequest() { |
||||
OnConstruction(); |
||||
} |
||||
|
||||
partial void OnConstruction(); |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public HelloRequest(HelloRequest other) : this() { |
||||
name_ = other.name_; |
||||
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public HelloRequest Clone() { |
||||
return new HelloRequest(this); |
||||
} |
||||
|
||||
/// <summary>Field number for the "name" field.</summary> |
||||
public const int NameFieldNumber = 1; |
||||
private string name_ = ""; |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public string Name { |
||||
get { return name_; } |
||||
set { |
||||
name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); |
||||
} |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public override bool Equals(object other) { |
||||
return Equals(other as HelloRequest); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public bool Equals(HelloRequest other) { |
||||
if (ReferenceEquals(other, null)) { |
||||
return false; |
||||
} |
||||
if (ReferenceEquals(other, this)) { |
||||
return true; |
||||
} |
||||
if (Name != other.Name) return false; |
||||
return Equals(_unknownFields, other._unknownFields); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public override int GetHashCode() { |
||||
int hash = 1; |
||||
if (Name.Length != 0) hash ^= Name.GetHashCode(); |
||||
if (_unknownFields != null) { |
||||
hash ^= _unknownFields.GetHashCode(); |
||||
} |
||||
return hash; |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public override string ToString() { |
||||
return pb::JsonFormatter.ToDiagnosticString(this); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public void WriteTo(pb::CodedOutputStream output) { |
||||
if (Name.Length != 0) { |
||||
output.WriteRawTag(10); |
||||
output.WriteString(Name); |
||||
} |
||||
if (_unknownFields != null) { |
||||
_unknownFields.WriteTo(output); |
||||
} |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public int CalculateSize() { |
||||
int size = 0; |
||||
if (Name.Length != 0) { |
||||
size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); |
||||
} |
||||
if (_unknownFields != null) { |
||||
size += _unknownFields.CalculateSize(); |
||||
} |
||||
return size; |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public void MergeFrom(HelloRequest other) { |
||||
if (other == null) { |
||||
return; |
||||
} |
||||
if (other.Name.Length != 0) { |
||||
Name = other.Name; |
||||
} |
||||
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public void MergeFrom(pb::CodedInputStream input) { |
||||
uint tag; |
||||
while ((tag = input.ReadTag()) != 0) { |
||||
switch(tag) { |
||||
default: |
||||
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); |
||||
break; |
||||
case 10: { |
||||
Name = input.ReadString(); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
/// <summary> |
||||
/// The response message containing the greetings |
||||
/// </summary> |
||||
public sealed partial class HelloReply : pb::IMessage<HelloReply> { |
||||
private static readonly pb::MessageParser<HelloReply> _parser = new pb::MessageParser<HelloReply>(() => new HelloReply()); |
||||
private pb::UnknownFieldSet _unknownFields; |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public static pb::MessageParser<HelloReply> Parser { get { return _parser; } } |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public static pbr::MessageDescriptor Descriptor { |
||||
get { return global::Helloworld.HelloworldReflection.Descriptor.MessageTypes[1]; } |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
pbr::MessageDescriptor pb::IMessage.Descriptor { |
||||
get { return Descriptor; } |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public HelloReply() { |
||||
OnConstruction(); |
||||
} |
||||
|
||||
partial void OnConstruction(); |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public HelloReply(HelloReply other) : this() { |
||||
message_ = other.message_; |
||||
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public HelloReply Clone() { |
||||
return new HelloReply(this); |
||||
} |
||||
|
||||
/// <summary>Field number for the "message" field.</summary> |
||||
public const int MessageFieldNumber = 1; |
||||
private string message_ = ""; |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public string Message { |
||||
get { return message_; } |
||||
set { |
||||
message_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); |
||||
} |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public override bool Equals(object other) { |
||||
return Equals(other as HelloReply); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public bool Equals(HelloReply other) { |
||||
if (ReferenceEquals(other, null)) { |
||||
return false; |
||||
} |
||||
if (ReferenceEquals(other, this)) { |
||||
return true; |
||||
} |
||||
if (Message != other.Message) return false; |
||||
return Equals(_unknownFields, other._unknownFields); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public override int GetHashCode() { |
||||
int hash = 1; |
||||
if (Message.Length != 0) hash ^= Message.GetHashCode(); |
||||
if (_unknownFields != null) { |
||||
hash ^= _unknownFields.GetHashCode(); |
||||
} |
||||
return hash; |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public override string ToString() { |
||||
return pb::JsonFormatter.ToDiagnosticString(this); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public void WriteTo(pb::CodedOutputStream output) { |
||||
if (Message.Length != 0) { |
||||
output.WriteRawTag(10); |
||||
output.WriteString(Message); |
||||
} |
||||
if (_unknownFields != null) { |
||||
_unknownFields.WriteTo(output); |
||||
} |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public int CalculateSize() { |
||||
int size = 0; |
||||
if (Message.Length != 0) { |
||||
size += 1 + pb::CodedOutputStream.ComputeStringSize(Message); |
||||
} |
||||
if (_unknownFields != null) { |
||||
size += _unknownFields.CalculateSize(); |
||||
} |
||||
return size; |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public void MergeFrom(HelloReply other) { |
||||
if (other == null) { |
||||
return; |
||||
} |
||||
if (other.Message.Length != 0) { |
||||
Message = other.Message; |
||||
} |
||||
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public void MergeFrom(pb::CodedInputStream input) { |
||||
uint tag; |
||||
while ((tag = input.ReadTag()) != 0) { |
||||
switch(tag) { |
||||
default: |
||||
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); |
||||
break; |
||||
case 10: { |
||||
Message = input.ReadString(); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
#endregion |
||||
|
||||
} |
||||
|
||||
#endregion Designer generated code |
@ -1,149 +0,0 @@ |
||||
// <auto-generated> |
||||
// Generated by the protocol buffer compiler. DO NOT EDIT! |
||||
// source: helloworld.proto |
||||
// </auto-generated> |
||||
// Original file comments: |
||||
// Copyright 2015 gRPC authors. |
||||
// |
||||
// Licensed under the Apache License, Version 2.0 (the "License"); |
||||
// you may not use this file except in compliance with the License. |
||||
// You may obtain a copy of the License at |
||||
// |
||||
// http://www.apache.org/licenses/LICENSE-2.0 |
||||
// |
||||
// Unless required by applicable law or agreed to in writing, software |
||||
// distributed under the License is distributed on an "AS IS" BASIS, |
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
// See the License for the specific language governing permissions and |
||||
// limitations under the License. |
||||
// |
||||
#pragma warning disable 0414, 1591 |
||||
#region Designer generated code |
||||
|
||||
using grpc = global::Grpc.Core; |
||||
|
||||
namespace Helloworld { |
||||
/// <summary> |
||||
/// The greeting service definition. |
||||
/// </summary> |
||||
public static partial class Greeter |
||||
{ |
||||
static readonly string __ServiceName = "helloworld.Greeter"; |
||||
|
||||
static readonly grpc::Marshaller<global::Helloworld.HelloRequest> __Marshaller_helloworld_HelloRequest = grpc::Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Helloworld.HelloRequest.Parser.ParseFrom); |
||||
static readonly grpc::Marshaller<global::Helloworld.HelloReply> __Marshaller_helloworld_HelloReply = grpc::Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Helloworld.HelloReply.Parser.ParseFrom); |
||||
|
||||
static readonly grpc::Method<global::Helloworld.HelloRequest, global::Helloworld.HelloReply> __Method_SayHello = new grpc::Method<global::Helloworld.HelloRequest, global::Helloworld.HelloReply>( |
||||
grpc::MethodType.Unary, |
||||
__ServiceName, |
||||
"SayHello", |
||||
__Marshaller_helloworld_HelloRequest, |
||||
__Marshaller_helloworld_HelloReply); |
||||
|
||||
/// <summary>Service descriptor</summary> |
||||
public static global::Google.Protobuf.Reflection.ServiceDescriptor Descriptor |
||||
{ |
||||
get { return global::Helloworld.HelloworldReflection.Descriptor.Services[0]; } |
||||
} |
||||
|
||||
/// <summary>Base class for server-side implementations of Greeter</summary> |
||||
public abstract partial class GreeterBase |
||||
{ |
||||
/// <summary> |
||||
/// Sends a greeting |
||||
/// </summary> |
||||
/// <param name="request">The request received from the client.</param> |
||||
/// <param name="context">The context of the server-side call handler being invoked.</param> |
||||
/// <returns>The response to send back to the client (wrapped by a task).</returns> |
||||
public virtual global::System.Threading.Tasks.Task<global::Helloworld.HelloReply> SayHello(global::Helloworld.HelloRequest request, grpc::ServerCallContext context) |
||||
{ |
||||
throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, "")); |
||||
} |
||||
|
||||
} |
||||
|
||||
/// <summary>Client for Greeter</summary> |
||||
public partial class GreeterClient : grpc::ClientBase<GreeterClient> |
||||
{ |
||||
/// <summary>Creates a new client for Greeter</summary> |
||||
/// <param name="channel">The channel to use to make remote calls.</param> |
||||
public GreeterClient(grpc::Channel channel) : base(channel) |
||||
{ |
||||
} |
||||
/// <summary>Creates a new client for Greeter that uses a custom <c>CallInvoker</c>.</summary> |
||||
/// <param name="callInvoker">The callInvoker to use to make remote calls.</param> |
||||
public GreeterClient(grpc::CallInvoker callInvoker) : base(callInvoker) |
||||
{ |
||||
} |
||||
/// <summary>Protected parameterless constructor to allow creation of test doubles.</summary> |
||||
protected GreeterClient() : base() |
||||
{ |
||||
} |
||||
/// <summary>Protected constructor to allow creation of configured clients.</summary> |
||||
/// <param name="configuration">The client configuration.</param> |
||||
protected GreeterClient(ClientBaseConfiguration configuration) : base(configuration) |
||||
{ |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Sends a greeting |
||||
/// </summary> |
||||
/// <param name="request">The request to send to the server.</param> |
||||
/// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
||||
/// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param> |
||||
/// <param name="cancellationToken">An optional token for canceling the call.</param> |
||||
/// <returns>The response received from the server.</returns> |
||||
public virtual global::Helloworld.HelloReply SayHello(global::Helloworld.HelloRequest request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) |
||||
{ |
||||
return SayHello(request, new grpc::CallOptions(headers, deadline, cancellationToken)); |
||||
} |
||||
/// <summary> |
||||
/// Sends a greeting |
||||
/// </summary> |
||||
/// <param name="request">The request to send to the server.</param> |
||||
/// <param name="options">The options for the call.</param> |
||||
/// <returns>The response received from the server.</returns> |
||||
public virtual global::Helloworld.HelloReply SayHello(global::Helloworld.HelloRequest request, grpc::CallOptions options) |
||||
{ |
||||
return CallInvoker.BlockingUnaryCall(__Method_SayHello, null, options, request); |
||||
} |
||||
/// <summary> |
||||
/// Sends a greeting |
||||
/// </summary> |
||||
/// <param name="request">The request to send to the server.</param> |
||||
/// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
||||
/// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param> |
||||
/// <param name="cancellationToken">An optional token for canceling the call.</param> |
||||
/// <returns>The call object.</returns> |
||||
public virtual grpc::AsyncUnaryCall<global::Helloworld.HelloReply> SayHelloAsync(global::Helloworld.HelloRequest request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) |
||||
{ |
||||
return SayHelloAsync(request, new grpc::CallOptions(headers, deadline, cancellationToken)); |
||||
} |
||||
/// <summary> |
||||
/// Sends a greeting |
||||
/// </summary> |
||||
/// <param name="request">The request to send to the server.</param> |
||||
/// <param name="options">The options for the call.</param> |
||||
/// <returns>The call object.</returns> |
||||
public virtual grpc::AsyncUnaryCall<global::Helloworld.HelloReply> SayHelloAsync(global::Helloworld.HelloRequest request, grpc::CallOptions options) |
||||
{ |
||||
return CallInvoker.AsyncUnaryCall(__Method_SayHello, null, options, request); |
||||
} |
||||
/// <summary>Creates a new instance of client from given <c>ClientBaseConfiguration</c>.</summary> |
||||
protected override GreeterClient NewInstance(ClientBaseConfiguration configuration) |
||||
{ |
||||
return new GreeterClient(configuration); |
||||
} |
||||
} |
||||
|
||||
/// <summary>Creates service definition that can be registered with a server</summary> |
||||
/// <param name="serviceImpl">An object implementing the server-side handling logic.</param> |
||||
public static grpc::ServerServiceDefinition BindService(GreeterBase serviceImpl) |
||||
{ |
||||
return grpc::ServerServiceDefinition.CreateBuilder() |
||||
.AddMethod(__Method_SayHello, serviceImpl.SayHello).Build(); |
||||
} |
||||
|
||||
} |
||||
} |
||||
#endregion |
@ -1,28 +0,0 @@ |
||||
@rem Copyright 2016 gRPC authors. |
||||
@rem |
||||
@rem Licensed under the Apache License, Version 2.0 (the "License"); |
||||
@rem you may not use this file except in compliance with the License. |
||||
@rem You may obtain a copy of the License at |
||||
@rem |
||||
@rem http://www.apache.org/licenses/LICENSE-2.0 |
||||
@rem |
||||
@rem Unless required by applicable law or agreed to in writing, software |
||||
@rem distributed under the License is distributed on an "AS IS" BASIS, |
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
@rem See the License for the specific language governing permissions and |
||||
@rem limitations under the License. |
||||
|
||||
@rem Generate the C# code for .proto files |
||||
|
||||
setlocal |
||||
|
||||
@rem enter this directory |
||||
cd /d %~dp0 |
||||
|
||||
@rem packages will be available in nuget cache directory once the project is built or after "dotnet restore" |
||||
set PROTOC=%UserProfile%\.nuget\packages\Google.Protobuf.Tools\3.6.1\tools\windows_x64\protoc.exe |
||||
set PLUGIN=%UserProfile%\.nuget\packages\Grpc.Tools\1.14.1\tools\windows_x64\grpc_csharp_plugin.exe |
||||
|
||||
%PROTOC% -I../../protos --csharp_out Greeter ../../protos/helloworld.proto --grpc_out Greeter --plugin=protoc-gen-grpc=%PLUGIN% |
||||
|
||||
endlocal |
@ -1,312 +0,0 @@ |
||||
// <auto-generated> |
||||
// Generated by the protocol buffer compiler. DO NOT EDIT! |
||||
// source: helloworld.proto |
||||
// </auto-generated> |
||||
#pragma warning disable 1591, 0612, 3021 |
||||
#region Designer generated code |
||||
|
||||
using pb = global::Google.Protobuf; |
||||
using pbc = global::Google.Protobuf.Collections; |
||||
using pbr = global::Google.Protobuf.Reflection; |
||||
using scg = global::System.Collections.Generic; |
||||
namespace Helloworld { |
||||
|
||||
/// <summary>Holder for reflection information generated from helloworld.proto</summary> |
||||
public static partial class HelloworldReflection { |
||||
|
||||
#region Descriptor |
||||
/// <summary>File descriptor for helloworld.proto</summary> |
||||
public static pbr::FileDescriptor Descriptor { |
||||
get { return descriptor; } |
||||
} |
||||
private static pbr::FileDescriptor descriptor; |
||||
|
||||
static HelloworldReflection() { |
||||
byte[] descriptorData = global::System.Convert.FromBase64String( |
||||
string.Concat( |
||||
"ChBoZWxsb3dvcmxkLnByb3RvEgpoZWxsb3dvcmxkIhwKDEhlbGxvUmVxdWVz", |
||||
"dBIMCgRuYW1lGAEgASgJIh0KCkhlbGxvUmVwbHkSDwoHbWVzc2FnZRgBIAEo", |
||||
"CTJJCgdHcmVldGVyEj4KCFNheUhlbGxvEhguaGVsbG93b3JsZC5IZWxsb1Jl", |
||||
"cXVlc3QaFi5oZWxsb3dvcmxkLkhlbGxvUmVwbHkiAEI2Chtpby5ncnBjLmV4", |
||||
"YW1wbGVzLmhlbGxvd29ybGRCD0hlbGxvV29ybGRQcm90b1ABogIDSExXYgZw", |
||||
"cm90bzM=")); |
||||
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, |
||||
new pbr::FileDescriptor[] { }, |
||||
new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { |
||||
new pbr::GeneratedClrTypeInfo(typeof(global::Helloworld.HelloRequest), global::Helloworld.HelloRequest.Parser, new[]{ "Name" }, null, null, null), |
||||
new pbr::GeneratedClrTypeInfo(typeof(global::Helloworld.HelloReply), global::Helloworld.HelloReply.Parser, new[]{ "Message" }, null, null, null) |
||||
})); |
||||
} |
||||
#endregion |
||||
|
||||
} |
||||
#region Messages |
||||
/// <summary> |
||||
/// The request message containing the user's name. |
||||
/// </summary> |
||||
public sealed partial class HelloRequest : pb::IMessage<HelloRequest> { |
||||
private static readonly pb::MessageParser<HelloRequest> _parser = new pb::MessageParser<HelloRequest>(() => new HelloRequest()); |
||||
private pb::UnknownFieldSet _unknownFields; |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public static pb::MessageParser<HelloRequest> Parser { get { return _parser; } } |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public static pbr::MessageDescriptor Descriptor { |
||||
get { return global::Helloworld.HelloworldReflection.Descriptor.MessageTypes[0]; } |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
pbr::MessageDescriptor pb::IMessage.Descriptor { |
||||
get { return Descriptor; } |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public HelloRequest() { |
||||
OnConstruction(); |
||||
} |
||||
|
||||
partial void OnConstruction(); |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public HelloRequest(HelloRequest other) : this() { |
||||
name_ = other.name_; |
||||
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public HelloRequest Clone() { |
||||
return new HelloRequest(this); |
||||
} |
||||
|
||||
/// <summary>Field number for the "name" field.</summary> |
||||
public const int NameFieldNumber = 1; |
||||
private string name_ = ""; |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public string Name { |
||||
get { return name_; } |
||||
set { |
||||
name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); |
||||
} |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public override bool Equals(object other) { |
||||
return Equals(other as HelloRequest); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public bool Equals(HelloRequest other) { |
||||
if (ReferenceEquals(other, null)) { |
||||
return false; |
||||
} |
||||
if (ReferenceEquals(other, this)) { |
||||
return true; |
||||
} |
||||
if (Name != other.Name) return false; |
||||
return Equals(_unknownFields, other._unknownFields); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public override int GetHashCode() { |
||||
int hash = 1; |
||||
if (Name.Length != 0) hash ^= Name.GetHashCode(); |
||||
if (_unknownFields != null) { |
||||
hash ^= _unknownFields.GetHashCode(); |
||||
} |
||||
return hash; |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public override string ToString() { |
||||
return pb::JsonFormatter.ToDiagnosticString(this); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public void WriteTo(pb::CodedOutputStream output) { |
||||
if (Name.Length != 0) { |
||||
output.WriteRawTag(10); |
||||
output.WriteString(Name); |
||||
} |
||||
if (_unknownFields != null) { |
||||
_unknownFields.WriteTo(output); |
||||
} |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public int CalculateSize() { |
||||
int size = 0; |
||||
if (Name.Length != 0) { |
||||
size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); |
||||
} |
||||
if (_unknownFields != null) { |
||||
size += _unknownFields.CalculateSize(); |
||||
} |
||||
return size; |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public void MergeFrom(HelloRequest other) { |
||||
if (other == null) { |
||||
return; |
||||
} |
||||
if (other.Name.Length != 0) { |
||||
Name = other.Name; |
||||
} |
||||
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public void MergeFrom(pb::CodedInputStream input) { |
||||
uint tag; |
||||
while ((tag = input.ReadTag()) != 0) { |
||||
switch(tag) { |
||||
default: |
||||
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); |
||||
break; |
||||
case 10: { |
||||
Name = input.ReadString(); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
/// <summary> |
||||
/// The response message containing the greetings |
||||
/// </summary> |
||||
public sealed partial class HelloReply : pb::IMessage<HelloReply> { |
||||
private static readonly pb::MessageParser<HelloReply> _parser = new pb::MessageParser<HelloReply>(() => new HelloReply()); |
||||
private pb::UnknownFieldSet _unknownFields; |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public static pb::MessageParser<HelloReply> Parser { get { return _parser; } } |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public static pbr::MessageDescriptor Descriptor { |
||||
get { return global::Helloworld.HelloworldReflection.Descriptor.MessageTypes[1]; } |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
pbr::MessageDescriptor pb::IMessage.Descriptor { |
||||
get { return Descriptor; } |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public HelloReply() { |
||||
OnConstruction(); |
||||
} |
||||
|
||||
partial void OnConstruction(); |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public HelloReply(HelloReply other) : this() { |
||||
message_ = other.message_; |
||||
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public HelloReply Clone() { |
||||
return new HelloReply(this); |
||||
} |
||||
|
||||
/// <summary>Field number for the "message" field.</summary> |
||||
public const int MessageFieldNumber = 1; |
||||
private string message_ = ""; |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public string Message { |
||||
get { return message_; } |
||||
set { |
||||
message_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); |
||||
} |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public override bool Equals(object other) { |
||||
return Equals(other as HelloReply); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public bool Equals(HelloReply other) { |
||||
if (ReferenceEquals(other, null)) { |
||||
return false; |
||||
} |
||||
if (ReferenceEquals(other, this)) { |
||||
return true; |
||||
} |
||||
if (Message != other.Message) return false; |
||||
return Equals(_unknownFields, other._unknownFields); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public override int GetHashCode() { |
||||
int hash = 1; |
||||
if (Message.Length != 0) hash ^= Message.GetHashCode(); |
||||
if (_unknownFields != null) { |
||||
hash ^= _unknownFields.GetHashCode(); |
||||
} |
||||
return hash; |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public override string ToString() { |
||||
return pb::JsonFormatter.ToDiagnosticString(this); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public void WriteTo(pb::CodedOutputStream output) { |
||||
if (Message.Length != 0) { |
||||
output.WriteRawTag(10); |
||||
output.WriteString(Message); |
||||
} |
||||
if (_unknownFields != null) { |
||||
_unknownFields.WriteTo(output); |
||||
} |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public int CalculateSize() { |
||||
int size = 0; |
||||
if (Message.Length != 0) { |
||||
size += 1 + pb::CodedOutputStream.ComputeStringSize(Message); |
||||
} |
||||
if (_unknownFields != null) { |
||||
size += _unknownFields.CalculateSize(); |
||||
} |
||||
return size; |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public void MergeFrom(HelloReply other) { |
||||
if (other == null) { |
||||
return; |
||||
} |
||||
if (other.Message.Length != 0) { |
||||
Message = other.Message; |
||||
} |
||||
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public void MergeFrom(pb::CodedInputStream input) { |
||||
uint tag; |
||||
while ((tag = input.ReadTag()) != 0) { |
||||
switch(tag) { |
||||
default: |
||||
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); |
||||
break; |
||||
case 10: { |
||||
Message = input.ReadString(); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
#endregion |
||||
|
||||
} |
||||
|
||||
#endregion Designer generated code |
@ -1,149 +0,0 @@ |
||||
// <auto-generated> |
||||
// Generated by the protocol buffer compiler. DO NOT EDIT! |
||||
// source: helloworld.proto |
||||
// </auto-generated> |
||||
// Original file comments: |
||||
// Copyright 2015 gRPC authors. |
||||
// |
||||
// Licensed under the Apache License, Version 2.0 (the "License"); |
||||
// you may not use this file except in compliance with the License. |
||||
// You may obtain a copy of the License at |
||||
// |
||||
// http://www.apache.org/licenses/LICENSE-2.0 |
||||
// |
||||
// Unless required by applicable law or agreed to in writing, software |
||||
// distributed under the License is distributed on an "AS IS" BASIS, |
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
// See the License for the specific language governing permissions and |
||||
// limitations under the License. |
||||
// |
||||
#pragma warning disable 0414, 1591 |
||||
#region Designer generated code |
||||
|
||||
using grpc = global::Grpc.Core; |
||||
|
||||
namespace Helloworld { |
||||
/// <summary> |
||||
/// The greeting service definition. |
||||
/// </summary> |
||||
public static partial class Greeter |
||||
{ |
||||
static readonly string __ServiceName = "helloworld.Greeter"; |
||||
|
||||
static readonly grpc::Marshaller<global::Helloworld.HelloRequest> __Marshaller_helloworld_HelloRequest = grpc::Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Helloworld.HelloRequest.Parser.ParseFrom); |
||||
static readonly grpc::Marshaller<global::Helloworld.HelloReply> __Marshaller_helloworld_HelloReply = grpc::Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Helloworld.HelloReply.Parser.ParseFrom); |
||||
|
||||
static readonly grpc::Method<global::Helloworld.HelloRequest, global::Helloworld.HelloReply> __Method_SayHello = new grpc::Method<global::Helloworld.HelloRequest, global::Helloworld.HelloReply>( |
||||
grpc::MethodType.Unary, |
||||
__ServiceName, |
||||
"SayHello", |
||||
__Marshaller_helloworld_HelloRequest, |
||||
__Marshaller_helloworld_HelloReply); |
||||
|
||||
/// <summary>Service descriptor</summary> |
||||
public static global::Google.Protobuf.Reflection.ServiceDescriptor Descriptor |
||||
{ |
||||
get { return global::Helloworld.HelloworldReflection.Descriptor.Services[0]; } |
||||
} |
||||
|
||||
/// <summary>Base class for server-side implementations of Greeter</summary> |
||||
public abstract partial class GreeterBase |
||||
{ |
||||
/// <summary> |
||||
/// Sends a greeting |
||||
/// </summary> |
||||
/// <param name="request">The request received from the client.</param> |
||||
/// <param name="context">The context of the server-side call handler being invoked.</param> |
||||
/// <returns>The response to send back to the client (wrapped by a task).</returns> |
||||
public virtual global::System.Threading.Tasks.Task<global::Helloworld.HelloReply> SayHello(global::Helloworld.HelloRequest request, grpc::ServerCallContext context) |
||||
{ |
||||
throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, "")); |
||||
} |
||||
|
||||
} |
||||
|
||||
/// <summary>Client for Greeter</summary> |
||||
public partial class GreeterClient : grpc::ClientBase<GreeterClient> |
||||
{ |
||||
/// <summary>Creates a new client for Greeter</summary> |
||||
/// <param name="channel">The channel to use to make remote calls.</param> |
||||
public GreeterClient(grpc::Channel channel) : base(channel) |
||||
{ |
||||
} |
||||
/// <summary>Creates a new client for Greeter that uses a custom <c>CallInvoker</c>.</summary> |
||||
/// <param name="callInvoker">The callInvoker to use to make remote calls.</param> |
||||
public GreeterClient(grpc::CallInvoker callInvoker) : base(callInvoker) |
||||
{ |
||||
} |
||||
/// <summary>Protected parameterless constructor to allow creation of test doubles.</summary> |
||||
protected GreeterClient() : base() |
||||
{ |
||||
} |
||||
/// <summary>Protected constructor to allow creation of configured clients.</summary> |
||||
/// <param name="configuration">The client configuration.</param> |
||||
protected GreeterClient(ClientBaseConfiguration configuration) : base(configuration) |
||||
{ |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Sends a greeting |
||||
/// </summary> |
||||
/// <param name="request">The request to send to the server.</param> |
||||
/// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
||||
/// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param> |
||||
/// <param name="cancellationToken">An optional token for canceling the call.</param> |
||||
/// <returns>The response received from the server.</returns> |
||||
public virtual global::Helloworld.HelloReply SayHello(global::Helloworld.HelloRequest request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) |
||||
{ |
||||
return SayHello(request, new grpc::CallOptions(headers, deadline, cancellationToken)); |
||||
} |
||||
/// <summary> |
||||
/// Sends a greeting |
||||
/// </summary> |
||||
/// <param name="request">The request to send to the server.</param> |
||||
/// <param name="options">The options for the call.</param> |
||||
/// <returns>The response received from the server.</returns> |
||||
public virtual global::Helloworld.HelloReply SayHello(global::Helloworld.HelloRequest request, grpc::CallOptions options) |
||||
{ |
||||
return CallInvoker.BlockingUnaryCall(__Method_SayHello, null, options, request); |
||||
} |
||||
/// <summary> |
||||
/// Sends a greeting |
||||
/// </summary> |
||||
/// <param name="request">The request to send to the server.</param> |
||||
/// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
||||
/// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param> |
||||
/// <param name="cancellationToken">An optional token for canceling the call.</param> |
||||
/// <returns>The call object.</returns> |
||||
public virtual grpc::AsyncUnaryCall<global::Helloworld.HelloReply> SayHelloAsync(global::Helloworld.HelloRequest request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) |
||||
{ |
||||
return SayHelloAsync(request, new grpc::CallOptions(headers, deadline, cancellationToken)); |
||||
} |
||||
/// <summary> |
||||
/// Sends a greeting |
||||
/// </summary> |
||||
/// <param name="request">The request to send to the server.</param> |
||||
/// <param name="options">The options for the call.</param> |
||||
/// <returns>The call object.</returns> |
||||
public virtual grpc::AsyncUnaryCall<global::Helloworld.HelloReply> SayHelloAsync(global::Helloworld.HelloRequest request, grpc::CallOptions options) |
||||
{ |
||||
return CallInvoker.AsyncUnaryCall(__Method_SayHello, null, options, request); |
||||
} |
||||
/// <summary>Creates a new instance of client from given <c>ClientBaseConfiguration</c>.</summary> |
||||
protected override GreeterClient NewInstance(ClientBaseConfiguration configuration) |
||||
{ |
||||
return new GreeterClient(configuration); |
||||
} |
||||
} |
||||
|
||||
/// <summary>Creates service definition that can be registered with a server</summary> |
||||
/// <param name="serviceImpl">An object implementing the server-side handling logic.</param> |
||||
public static grpc::ServerServiceDefinition BindService(GreeterBase serviceImpl) |
||||
{ |
||||
return grpc::ServerServiceDefinition.CreateBuilder() |
||||
.AddMethod(__Method_SayHello, serviceImpl.SayHello).Build(); |
||||
} |
||||
|
||||
} |
||||
} |
||||
#endregion |
@ -1,26 +0,0 @@ |
||||
@rem Copyright 2016 gRPC authors. |
||||
@rem |
||||
@rem Licensed under the Apache License, Version 2.0 (the "License"); |
||||
@rem you may not use this file except in compliance with the License. |
||||
@rem You may obtain a copy of the License at |
||||
@rem |
||||
@rem http://www.apache.org/licenses/LICENSE-2.0 |
||||
@rem |
||||
@rem Unless required by applicable law or agreed to in writing, software |
||||
@rem distributed under the License is distributed on an "AS IS" BASIS, |
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
@rem See the License for the specific language governing permissions and |
||||
@rem limitations under the License. |
||||
|
||||
@rem Generate the C# code for .proto files |
||||
|
||||
setlocal |
||||
|
||||
@rem enter this directory |
||||
cd /d %~dp0 |
||||
|
||||
set TOOLS_PATH=packages\Grpc.Tools.1.14.1\tools\windows_x86 |
||||
|
||||
%TOOLS_PATH%\protoc.exe -I../../protos --csharp_out Greeter ../../protos/helloworld.proto --grpc_out Greeter --plugin=protoc-gen-grpc=%TOOLS_PATH%\grpc_csharp_plugin.exe |
||||
|
||||
endlocal |
@ -1,981 +0,0 @@ |
||||
// <auto-generated> |
||||
// Generated by the protocol buffer compiler. DO NOT EDIT! |
||||
// source: route_guide.proto |
||||
// </auto-generated> |
||||
#pragma warning disable 1591, 0612, 3021 |
||||
#region Designer generated code |
||||
|
||||
using pb = global::Google.Protobuf; |
||||
using pbc = global::Google.Protobuf.Collections; |
||||
using pbr = global::Google.Protobuf.Reflection; |
||||
using scg = global::System.Collections.Generic; |
||||
namespace Routeguide { |
||||
|
||||
/// <summary>Holder for reflection information generated from route_guide.proto</summary> |
||||
public static partial class RouteGuideReflection { |
||||
|
||||
#region Descriptor |
||||
/// <summary>File descriptor for route_guide.proto</summary> |
||||
public static pbr::FileDescriptor Descriptor { |
||||
get { return descriptor; } |
||||
} |
||||
private static pbr::FileDescriptor descriptor; |
||||
|
||||
static RouteGuideReflection() { |
||||
byte[] descriptorData = global::System.Convert.FromBase64String( |
||||
string.Concat( |
||||
"ChFyb3V0ZV9ndWlkZS5wcm90bxIKcm91dGVndWlkZSIsCgVQb2ludBIQCghs", |
||||
"YXRpdHVkZRgBIAEoBRIRCglsb25naXR1ZGUYAiABKAUiSQoJUmVjdGFuZ2xl", |
||||
"Eh0KAmxvGAEgASgLMhEucm91dGVndWlkZS5Qb2ludBIdCgJoaRgCIAEoCzIR", |
||||
"LnJvdXRlZ3VpZGUuUG9pbnQiPAoHRmVhdHVyZRIMCgRuYW1lGAEgASgJEiMK", |
||||
"CGxvY2F0aW9uGAIgASgLMhEucm91dGVndWlkZS5Qb2ludCJBCglSb3V0ZU5v", |
||||
"dGUSIwoIbG9jYXRpb24YASABKAsyES5yb3V0ZWd1aWRlLlBvaW50Eg8KB21l", |
||||
"c3NhZ2UYAiABKAkiYgoMUm91dGVTdW1tYXJ5EhMKC3BvaW50X2NvdW50GAEg", |
||||
"ASgFEhUKDWZlYXR1cmVfY291bnQYAiABKAUSEAoIZGlzdGFuY2UYAyABKAUS", |
||||
"FAoMZWxhcHNlZF90aW1lGAQgASgFMoUCCgpSb3V0ZUd1aWRlEjYKCkdldEZl", |
||||
"YXR1cmUSES5yb3V0ZWd1aWRlLlBvaW50GhMucm91dGVndWlkZS5GZWF0dXJl", |
||||
"IgASPgoMTGlzdEZlYXR1cmVzEhUucm91dGVndWlkZS5SZWN0YW5nbGUaEy5y", |
||||
"b3V0ZWd1aWRlLkZlYXR1cmUiADABEj4KC1JlY29yZFJvdXRlEhEucm91dGVn", |
||||
"dWlkZS5Qb2ludBoYLnJvdXRlZ3VpZGUuUm91dGVTdW1tYXJ5IgAoARI/CglS", |
||||
"b3V0ZUNoYXQSFS5yb3V0ZWd1aWRlLlJvdXRlTm90ZRoVLnJvdXRlZ3VpZGUu", |
||||
"Um91dGVOb3RlIgAoATABQjYKG2lvLmdycGMuZXhhbXBsZXMucm91dGVndWlk", |
||||
"ZUIPUm91dGVHdWlkZVByb3RvUAGiAgNSVEdiBnByb3RvMw==")); |
||||
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, |
||||
new pbr::FileDescriptor[] { }, |
||||
new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { |
||||
new pbr::GeneratedClrTypeInfo(typeof(global::Routeguide.Point), global::Routeguide.Point.Parser, new[]{ "Latitude", "Longitude" }, null, null, null), |
||||
new pbr::GeneratedClrTypeInfo(typeof(global::Routeguide.Rectangle), global::Routeguide.Rectangle.Parser, new[]{ "Lo", "Hi" }, null, null, null), |
||||
new pbr::GeneratedClrTypeInfo(typeof(global::Routeguide.Feature), global::Routeguide.Feature.Parser, new[]{ "Name", "Location" }, null, null, null), |
||||
new pbr::GeneratedClrTypeInfo(typeof(global::Routeguide.RouteNote), global::Routeguide.RouteNote.Parser, new[]{ "Location", "Message" }, null, null, null), |
||||
new pbr::GeneratedClrTypeInfo(typeof(global::Routeguide.RouteSummary), global::Routeguide.RouteSummary.Parser, new[]{ "PointCount", "FeatureCount", "Distance", "ElapsedTime" }, null, null, null) |
||||
})); |
||||
} |
||||
#endregion |
||||
|
||||
} |
||||
#region Messages |
||||
/// <summary> |
||||
/// Points are represented as latitude-longitude pairs in the E7 representation |
||||
/// (degrees multiplied by 10**7 and rounded to the nearest integer). |
||||
/// Latitudes should be in the range +/- 90 degrees and longitude should be in |
||||
/// the range +/- 180 degrees (inclusive). |
||||
/// </summary> |
||||
public sealed partial class Point : pb::IMessage<Point> { |
||||
private static readonly pb::MessageParser<Point> _parser = new pb::MessageParser<Point>(() => new Point()); |
||||
private pb::UnknownFieldSet _unknownFields; |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public static pb::MessageParser<Point> Parser { get { return _parser; } } |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public static pbr::MessageDescriptor Descriptor { |
||||
get { return global::Routeguide.RouteGuideReflection.Descriptor.MessageTypes[0]; } |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
pbr::MessageDescriptor pb::IMessage.Descriptor { |
||||
get { return Descriptor; } |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public Point() { |
||||
OnConstruction(); |
||||
} |
||||
|
||||
partial void OnConstruction(); |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public Point(Point other) : this() { |
||||
latitude_ = other.latitude_; |
||||
longitude_ = other.longitude_; |
||||
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public Point Clone() { |
||||
return new Point(this); |
||||
} |
||||
|
||||
/// <summary>Field number for the "latitude" field.</summary> |
||||
public const int LatitudeFieldNumber = 1; |
||||
private int latitude_; |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public int Latitude { |
||||
get { return latitude_; } |
||||
set { |
||||
latitude_ = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>Field number for the "longitude" field.</summary> |
||||
public const int LongitudeFieldNumber = 2; |
||||
private int longitude_; |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public int Longitude { |
||||
get { return longitude_; } |
||||
set { |
||||
longitude_ = value; |
||||
} |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public override bool Equals(object other) { |
||||
return Equals(other as Point); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public bool Equals(Point other) { |
||||
if (ReferenceEquals(other, null)) { |
||||
return false; |
||||
} |
||||
if (ReferenceEquals(other, this)) { |
||||
return true; |
||||
} |
||||
if (Latitude != other.Latitude) return false; |
||||
if (Longitude != other.Longitude) return false; |
||||
return Equals(_unknownFields, other._unknownFields); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public override int GetHashCode() { |
||||
int hash = 1; |
||||
if (Latitude != 0) hash ^= Latitude.GetHashCode(); |
||||
if (Longitude != 0) hash ^= Longitude.GetHashCode(); |
||||
if (_unknownFields != null) { |
||||
hash ^= _unknownFields.GetHashCode(); |
||||
} |
||||
return hash; |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public override string ToString() { |
||||
return pb::JsonFormatter.ToDiagnosticString(this); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public void WriteTo(pb::CodedOutputStream output) { |
||||
if (Latitude != 0) { |
||||
output.WriteRawTag(8); |
||||
output.WriteInt32(Latitude); |
||||
} |
||||
if (Longitude != 0) { |
||||
output.WriteRawTag(16); |
||||
output.WriteInt32(Longitude); |
||||
} |
||||
if (_unknownFields != null) { |
||||
_unknownFields.WriteTo(output); |
||||
} |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public int CalculateSize() { |
||||
int size = 0; |
||||
if (Latitude != 0) { |
||||
size += 1 + pb::CodedOutputStream.ComputeInt32Size(Latitude); |
||||
} |
||||
if (Longitude != 0) { |
||||
size += 1 + pb::CodedOutputStream.ComputeInt32Size(Longitude); |
||||
} |
||||
if (_unknownFields != null) { |
||||
size += _unknownFields.CalculateSize(); |
||||
} |
||||
return size; |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public void MergeFrom(Point other) { |
||||
if (other == null) { |
||||
return; |
||||
} |
||||
if (other.Latitude != 0) { |
||||
Latitude = other.Latitude; |
||||
} |
||||
if (other.Longitude != 0) { |
||||
Longitude = other.Longitude; |
||||
} |
||||
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public void MergeFrom(pb::CodedInputStream input) { |
||||
uint tag; |
||||
while ((tag = input.ReadTag()) != 0) { |
||||
switch(tag) { |
||||
default: |
||||
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); |
||||
break; |
||||
case 8: { |
||||
Latitude = input.ReadInt32(); |
||||
break; |
||||
} |
||||
case 16: { |
||||
Longitude = input.ReadInt32(); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
/// <summary> |
||||
/// A latitude-longitude rectangle, represented as two diagonally opposite |
||||
/// points "lo" and "hi". |
||||
/// </summary> |
||||
public sealed partial class Rectangle : pb::IMessage<Rectangle> { |
||||
private static readonly pb::MessageParser<Rectangle> _parser = new pb::MessageParser<Rectangle>(() => new Rectangle()); |
||||
private pb::UnknownFieldSet _unknownFields; |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public static pb::MessageParser<Rectangle> Parser { get { return _parser; } } |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public static pbr::MessageDescriptor Descriptor { |
||||
get { return global::Routeguide.RouteGuideReflection.Descriptor.MessageTypes[1]; } |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
pbr::MessageDescriptor pb::IMessage.Descriptor { |
||||
get { return Descriptor; } |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public Rectangle() { |
||||
OnConstruction(); |
||||
} |
||||
|
||||
partial void OnConstruction(); |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public Rectangle(Rectangle other) : this() { |
||||
lo_ = other.lo_ != null ? other.lo_.Clone() : null; |
||||
hi_ = other.hi_ != null ? other.hi_.Clone() : null; |
||||
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public Rectangle Clone() { |
||||
return new Rectangle(this); |
||||
} |
||||
|
||||
/// <summary>Field number for the "lo" field.</summary> |
||||
public const int LoFieldNumber = 1; |
||||
private global::Routeguide.Point lo_; |
||||
/// <summary> |
||||
/// One corner of the rectangle. |
||||
/// </summary> |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public global::Routeguide.Point Lo { |
||||
get { return lo_; } |
||||
set { |
||||
lo_ = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>Field number for the "hi" field.</summary> |
||||
public const int HiFieldNumber = 2; |
||||
private global::Routeguide.Point hi_; |
||||
/// <summary> |
||||
/// The other corner of the rectangle. |
||||
/// </summary> |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public global::Routeguide.Point Hi { |
||||
get { return hi_; } |
||||
set { |
||||
hi_ = value; |
||||
} |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public override bool Equals(object other) { |
||||
return Equals(other as Rectangle); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public bool Equals(Rectangle other) { |
||||
if (ReferenceEquals(other, null)) { |
||||
return false; |
||||
} |
||||
if (ReferenceEquals(other, this)) { |
||||
return true; |
||||
} |
||||
if (!object.Equals(Lo, other.Lo)) return false; |
||||
if (!object.Equals(Hi, other.Hi)) return false; |
||||
return Equals(_unknownFields, other._unknownFields); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public override int GetHashCode() { |
||||
int hash = 1; |
||||
if (lo_ != null) hash ^= Lo.GetHashCode(); |
||||
if (hi_ != null) hash ^= Hi.GetHashCode(); |
||||
if (_unknownFields != null) { |
||||
hash ^= _unknownFields.GetHashCode(); |
||||
} |
||||
return hash; |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public override string ToString() { |
||||
return pb::JsonFormatter.ToDiagnosticString(this); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public void WriteTo(pb::CodedOutputStream output) { |
||||
if (lo_ != null) { |
||||
output.WriteRawTag(10); |
||||
output.WriteMessage(Lo); |
||||
} |
||||
if (hi_ != null) { |
||||
output.WriteRawTag(18); |
||||
output.WriteMessage(Hi); |
||||
} |
||||
if (_unknownFields != null) { |
||||
_unknownFields.WriteTo(output); |
||||
} |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public int CalculateSize() { |
||||
int size = 0; |
||||
if (lo_ != null) { |
||||
size += 1 + pb::CodedOutputStream.ComputeMessageSize(Lo); |
||||
} |
||||
if (hi_ != null) { |
||||
size += 1 + pb::CodedOutputStream.ComputeMessageSize(Hi); |
||||
} |
||||
if (_unknownFields != null) { |
||||
size += _unknownFields.CalculateSize(); |
||||
} |
||||
return size; |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public void MergeFrom(Rectangle other) { |
||||
if (other == null) { |
||||
return; |
||||
} |
||||
if (other.lo_ != null) { |
||||
if (lo_ == null) { |
||||
lo_ = new global::Routeguide.Point(); |
||||
} |
||||
Lo.MergeFrom(other.Lo); |
||||
} |
||||
if (other.hi_ != null) { |
||||
if (hi_ == null) { |
||||
hi_ = new global::Routeguide.Point(); |
||||
} |
||||
Hi.MergeFrom(other.Hi); |
||||
} |
||||
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public void MergeFrom(pb::CodedInputStream input) { |
||||
uint tag; |
||||
while ((tag = input.ReadTag()) != 0) { |
||||
switch(tag) { |
||||
default: |
||||
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); |
||||
break; |
||||
case 10: { |
||||
if (lo_ == null) { |
||||
lo_ = new global::Routeguide.Point(); |
||||
} |
||||
input.ReadMessage(lo_); |
||||
break; |
||||
} |
||||
case 18: { |
||||
if (hi_ == null) { |
||||
hi_ = new global::Routeguide.Point(); |
||||
} |
||||
input.ReadMessage(hi_); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
/// <summary> |
||||
/// A feature names something at a given point. |
||||
/// |
||||
/// If a feature could not be named, the name is empty. |
||||
/// </summary> |
||||
public sealed partial class Feature : pb::IMessage<Feature> { |
||||
private static readonly pb::MessageParser<Feature> _parser = new pb::MessageParser<Feature>(() => new Feature()); |
||||
private pb::UnknownFieldSet _unknownFields; |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public static pb::MessageParser<Feature> Parser { get { return _parser; } } |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public static pbr::MessageDescriptor Descriptor { |
||||
get { return global::Routeguide.RouteGuideReflection.Descriptor.MessageTypes[2]; } |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
pbr::MessageDescriptor pb::IMessage.Descriptor { |
||||
get { return Descriptor; } |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public Feature() { |
||||
OnConstruction(); |
||||
} |
||||
|
||||
partial void OnConstruction(); |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public Feature(Feature other) : this() { |
||||
name_ = other.name_; |
||||
location_ = other.location_ != null ? other.location_.Clone() : null; |
||||
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public Feature Clone() { |
||||
return new Feature(this); |
||||
} |
||||
|
||||
/// <summary>Field number for the "name" field.</summary> |
||||
public const int NameFieldNumber = 1; |
||||
private string name_ = ""; |
||||
/// <summary> |
||||
/// The name of the feature. |
||||
/// </summary> |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public string Name { |
||||
get { return name_; } |
||||
set { |
||||
name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); |
||||
} |
||||
} |
||||
|
||||
/// <summary>Field number for the "location" field.</summary> |
||||
public const int LocationFieldNumber = 2; |
||||
private global::Routeguide.Point location_; |
||||
/// <summary> |
||||
/// The point where the feature is detected. |
||||
/// </summary> |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public global::Routeguide.Point Location { |
||||
get { return location_; } |
||||
set { |
||||
location_ = value; |
||||
} |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public override bool Equals(object other) { |
||||
return Equals(other as Feature); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public bool Equals(Feature other) { |
||||
if (ReferenceEquals(other, null)) { |
||||
return false; |
||||
} |
||||
if (ReferenceEquals(other, this)) { |
||||
return true; |
||||
} |
||||
if (Name != other.Name) return false; |
||||
if (!object.Equals(Location, other.Location)) return false; |
||||
return Equals(_unknownFields, other._unknownFields); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public override int GetHashCode() { |
||||
int hash = 1; |
||||
if (Name.Length != 0) hash ^= Name.GetHashCode(); |
||||
if (location_ != null) hash ^= Location.GetHashCode(); |
||||
if (_unknownFields != null) { |
||||
hash ^= _unknownFields.GetHashCode(); |
||||
} |
||||
return hash; |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public override string ToString() { |
||||
return pb::JsonFormatter.ToDiagnosticString(this); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public void WriteTo(pb::CodedOutputStream output) { |
||||
if (Name.Length != 0) { |
||||
output.WriteRawTag(10); |
||||
output.WriteString(Name); |
||||
} |
||||
if (location_ != null) { |
||||
output.WriteRawTag(18); |
||||
output.WriteMessage(Location); |
||||
} |
||||
if (_unknownFields != null) { |
||||
_unknownFields.WriteTo(output); |
||||
} |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public int CalculateSize() { |
||||
int size = 0; |
||||
if (Name.Length != 0) { |
||||
size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); |
||||
} |
||||
if (location_ != null) { |
||||
size += 1 + pb::CodedOutputStream.ComputeMessageSize(Location); |
||||
} |
||||
if (_unknownFields != null) { |
||||
size += _unknownFields.CalculateSize(); |
||||
} |
||||
return size; |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public void MergeFrom(Feature other) { |
||||
if (other == null) { |
||||
return; |
||||
} |
||||
if (other.Name.Length != 0) { |
||||
Name = other.Name; |
||||
} |
||||
if (other.location_ != null) { |
||||
if (location_ == null) { |
||||
location_ = new global::Routeguide.Point(); |
||||
} |
||||
Location.MergeFrom(other.Location); |
||||
} |
||||
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public void MergeFrom(pb::CodedInputStream input) { |
||||
uint tag; |
||||
while ((tag = input.ReadTag()) != 0) { |
||||
switch(tag) { |
||||
default: |
||||
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); |
||||
break; |
||||
case 10: { |
||||
Name = input.ReadString(); |
||||
break; |
||||
} |
||||
case 18: { |
||||
if (location_ == null) { |
||||
location_ = new global::Routeguide.Point(); |
||||
} |
||||
input.ReadMessage(location_); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
/// <summary> |
||||
/// A RouteNote is a message sent while at a given point. |
||||
/// </summary> |
||||
public sealed partial class RouteNote : pb::IMessage<RouteNote> { |
||||
private static readonly pb::MessageParser<RouteNote> _parser = new pb::MessageParser<RouteNote>(() => new RouteNote()); |
||||
private pb::UnknownFieldSet _unknownFields; |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public static pb::MessageParser<RouteNote> Parser { get { return _parser; } } |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public static pbr::MessageDescriptor Descriptor { |
||||
get { return global::Routeguide.RouteGuideReflection.Descriptor.MessageTypes[3]; } |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
pbr::MessageDescriptor pb::IMessage.Descriptor { |
||||
get { return Descriptor; } |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public RouteNote() { |
||||
OnConstruction(); |
||||
} |
||||
|
||||
partial void OnConstruction(); |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public RouteNote(RouteNote other) : this() { |
||||
location_ = other.location_ != null ? other.location_.Clone() : null; |
||||
message_ = other.message_; |
||||
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public RouteNote Clone() { |
||||
return new RouteNote(this); |
||||
} |
||||
|
||||
/// <summary>Field number for the "location" field.</summary> |
||||
public const int LocationFieldNumber = 1; |
||||
private global::Routeguide.Point location_; |
||||
/// <summary> |
||||
/// The location from which the message is sent. |
||||
/// </summary> |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public global::Routeguide.Point Location { |
||||
get { return location_; } |
||||
set { |
||||
location_ = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>Field number for the "message" field.</summary> |
||||
public const int MessageFieldNumber = 2; |
||||
private string message_ = ""; |
||||
/// <summary> |
||||
/// The message to be sent. |
||||
/// </summary> |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public string Message { |
||||
get { return message_; } |
||||
set { |
||||
message_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); |
||||
} |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public override bool Equals(object other) { |
||||
return Equals(other as RouteNote); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public bool Equals(RouteNote other) { |
||||
if (ReferenceEquals(other, null)) { |
||||
return false; |
||||
} |
||||
if (ReferenceEquals(other, this)) { |
||||
return true; |
||||
} |
||||
if (!object.Equals(Location, other.Location)) return false; |
||||
if (Message != other.Message) return false; |
||||
return Equals(_unknownFields, other._unknownFields); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public override int GetHashCode() { |
||||
int hash = 1; |
||||
if (location_ != null) hash ^= Location.GetHashCode(); |
||||
if (Message.Length != 0) hash ^= Message.GetHashCode(); |
||||
if (_unknownFields != null) { |
||||
hash ^= _unknownFields.GetHashCode(); |
||||
} |
||||
return hash; |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public override string ToString() { |
||||
return pb::JsonFormatter.ToDiagnosticString(this); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public void WriteTo(pb::CodedOutputStream output) { |
||||
if (location_ != null) { |
||||
output.WriteRawTag(10); |
||||
output.WriteMessage(Location); |
||||
} |
||||
if (Message.Length != 0) { |
||||
output.WriteRawTag(18); |
||||
output.WriteString(Message); |
||||
} |
||||
if (_unknownFields != null) { |
||||
_unknownFields.WriteTo(output); |
||||
} |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public int CalculateSize() { |
||||
int size = 0; |
||||
if (location_ != null) { |
||||
size += 1 + pb::CodedOutputStream.ComputeMessageSize(Location); |
||||
} |
||||
if (Message.Length != 0) { |
||||
size += 1 + pb::CodedOutputStream.ComputeStringSize(Message); |
||||
} |
||||
if (_unknownFields != null) { |
||||
size += _unknownFields.CalculateSize(); |
||||
} |
||||
return size; |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public void MergeFrom(RouteNote other) { |
||||
if (other == null) { |
||||
return; |
||||
} |
||||
if (other.location_ != null) { |
||||
if (location_ == null) { |
||||
location_ = new global::Routeguide.Point(); |
||||
} |
||||
Location.MergeFrom(other.Location); |
||||
} |
||||
if (other.Message.Length != 0) { |
||||
Message = other.Message; |
||||
} |
||||
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public void MergeFrom(pb::CodedInputStream input) { |
||||
uint tag; |
||||
while ((tag = input.ReadTag()) != 0) { |
||||
switch(tag) { |
||||
default: |
||||
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); |
||||
break; |
||||
case 10: { |
||||
if (location_ == null) { |
||||
location_ = new global::Routeguide.Point(); |
||||
} |
||||
input.ReadMessage(location_); |
||||
break; |
||||
} |
||||
case 18: { |
||||
Message = input.ReadString(); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
/// <summary> |
||||
/// A RouteSummary is received in response to a RecordRoute rpc. |
||||
/// |
||||
/// It contains the number of individual points received, the number of |
||||
/// detected features, and the total distance covered as the cumulative sum of |
||||
/// the distance between each point. |
||||
/// </summary> |
||||
public sealed partial class RouteSummary : pb::IMessage<RouteSummary> { |
||||
private static readonly pb::MessageParser<RouteSummary> _parser = new pb::MessageParser<RouteSummary>(() => new RouteSummary()); |
||||
private pb::UnknownFieldSet _unknownFields; |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public static pb::MessageParser<RouteSummary> Parser { get { return _parser; } } |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public static pbr::MessageDescriptor Descriptor { |
||||
get { return global::Routeguide.RouteGuideReflection.Descriptor.MessageTypes[4]; } |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
pbr::MessageDescriptor pb::IMessage.Descriptor { |
||||
get { return Descriptor; } |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public RouteSummary() { |
||||
OnConstruction(); |
||||
} |
||||
|
||||
partial void OnConstruction(); |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public RouteSummary(RouteSummary other) : this() { |
||||
pointCount_ = other.pointCount_; |
||||
featureCount_ = other.featureCount_; |
||||
distance_ = other.distance_; |
||||
elapsedTime_ = other.elapsedTime_; |
||||
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public RouteSummary Clone() { |
||||
return new RouteSummary(this); |
||||
} |
||||
|
||||
/// <summary>Field number for the "point_count" field.</summary> |
||||
public const int PointCountFieldNumber = 1; |
||||
private int pointCount_; |
||||
/// <summary> |
||||
/// The number of points received. |
||||
/// </summary> |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public int PointCount { |
||||
get { return pointCount_; } |
||||
set { |
||||
pointCount_ = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>Field number for the "feature_count" field.</summary> |
||||
public const int FeatureCountFieldNumber = 2; |
||||
private int featureCount_; |
||||
/// <summary> |
||||
/// The number of known features passed while traversing the route. |
||||
/// </summary> |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public int FeatureCount { |
||||
get { return featureCount_; } |
||||
set { |
||||
featureCount_ = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>Field number for the "distance" field.</summary> |
||||
public const int DistanceFieldNumber = 3; |
||||
private int distance_; |
||||
/// <summary> |
||||
/// The distance covered in metres. |
||||
/// </summary> |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public int Distance { |
||||
get { return distance_; } |
||||
set { |
||||
distance_ = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>Field number for the "elapsed_time" field.</summary> |
||||
public const int ElapsedTimeFieldNumber = 4; |
||||
private int elapsedTime_; |
||||
/// <summary> |
||||
/// The duration of the traversal in seconds. |
||||
/// </summary> |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public int ElapsedTime { |
||||
get { return elapsedTime_; } |
||||
set { |
||||
elapsedTime_ = value; |
||||
} |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public override bool Equals(object other) { |
||||
return Equals(other as RouteSummary); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public bool Equals(RouteSummary other) { |
||||
if (ReferenceEquals(other, null)) { |
||||
return false; |
||||
} |
||||
if (ReferenceEquals(other, this)) { |
||||
return true; |
||||
} |
||||
if (PointCount != other.PointCount) return false; |
||||
if (FeatureCount != other.FeatureCount) return false; |
||||
if (Distance != other.Distance) return false; |
||||
if (ElapsedTime != other.ElapsedTime) return false; |
||||
return Equals(_unknownFields, other._unknownFields); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public override int GetHashCode() { |
||||
int hash = 1; |
||||
if (PointCount != 0) hash ^= PointCount.GetHashCode(); |
||||
if (FeatureCount != 0) hash ^= FeatureCount.GetHashCode(); |
||||
if (Distance != 0) hash ^= Distance.GetHashCode(); |
||||
if (ElapsedTime != 0) hash ^= ElapsedTime.GetHashCode(); |
||||
if (_unknownFields != null) { |
||||
hash ^= _unknownFields.GetHashCode(); |
||||
} |
||||
return hash; |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public override string ToString() { |
||||
return pb::JsonFormatter.ToDiagnosticString(this); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public void WriteTo(pb::CodedOutputStream output) { |
||||
if (PointCount != 0) { |
||||
output.WriteRawTag(8); |
||||
output.WriteInt32(PointCount); |
||||
} |
||||
if (FeatureCount != 0) { |
||||
output.WriteRawTag(16); |
||||
output.WriteInt32(FeatureCount); |
||||
} |
||||
if (Distance != 0) { |
||||
output.WriteRawTag(24); |
||||
output.WriteInt32(Distance); |
||||
} |
||||
if (ElapsedTime != 0) { |
||||
output.WriteRawTag(32); |
||||
output.WriteInt32(ElapsedTime); |
||||
} |
||||
if (_unknownFields != null) { |
||||
_unknownFields.WriteTo(output); |
||||
} |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public int CalculateSize() { |
||||
int size = 0; |
||||
if (PointCount != 0) { |
||||
size += 1 + pb::CodedOutputStream.ComputeInt32Size(PointCount); |
||||
} |
||||
if (FeatureCount != 0) { |
||||
size += 1 + pb::CodedOutputStream.ComputeInt32Size(FeatureCount); |
||||
} |
||||
if (Distance != 0) { |
||||
size += 1 + pb::CodedOutputStream.ComputeInt32Size(Distance); |
||||
} |
||||
if (ElapsedTime != 0) { |
||||
size += 1 + pb::CodedOutputStream.ComputeInt32Size(ElapsedTime); |
||||
} |
||||
if (_unknownFields != null) { |
||||
size += _unknownFields.CalculateSize(); |
||||
} |
||||
return size; |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public void MergeFrom(RouteSummary other) { |
||||
if (other == null) { |
||||
return; |
||||
} |
||||
if (other.PointCount != 0) { |
||||
PointCount = other.PointCount; |
||||
} |
||||
if (other.FeatureCount != 0) { |
||||
FeatureCount = other.FeatureCount; |
||||
} |
||||
if (other.Distance != 0) { |
||||
Distance = other.Distance; |
||||
} |
||||
if (other.ElapsedTime != 0) { |
||||
ElapsedTime = other.ElapsedTime; |
||||
} |
||||
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] |
||||
public void MergeFrom(pb::CodedInputStream input) { |
||||
uint tag; |
||||
while ((tag = input.ReadTag()) != 0) { |
||||
switch(tag) { |
||||
default: |
||||
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); |
||||
break; |
||||
case 8: { |
||||
PointCount = input.ReadInt32(); |
||||
break; |
||||
} |
||||
case 16: { |
||||
FeatureCount = input.ReadInt32(); |
||||
break; |
||||
} |
||||
case 24: { |
||||
Distance = input.ReadInt32(); |
||||
break; |
||||
} |
||||
case 32: { |
||||
ElapsedTime = input.ReadInt32(); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
#endregion |
||||
|
||||
} |
||||
|
||||
#endregion Designer generated code |
@ -1,331 +0,0 @@ |
||||
// <auto-generated> |
||||
// Generated by the protocol buffer compiler. DO NOT EDIT! |
||||
// source: route_guide.proto |
||||
// </auto-generated> |
||||
// Original file comments: |
||||
// Copyright 2015 gRPC authors. |
||||
// |
||||
// Licensed under the Apache License, Version 2.0 (the "License"); |
||||
// you may not use this file except in compliance with the License. |
||||
// You may obtain a copy of the License at |
||||
// |
||||
// http://www.apache.org/licenses/LICENSE-2.0 |
||||
// |
||||
// Unless required by applicable law or agreed to in writing, software |
||||
// distributed under the License is distributed on an "AS IS" BASIS, |
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
// See the License for the specific language governing permissions and |
||||
// limitations under the License. |
||||
// |
||||
#pragma warning disable 0414, 1591 |
||||
#region Designer generated code |
||||
|
||||
using grpc = global::Grpc.Core; |
||||
|
||||
namespace Routeguide { |
||||
/// <summary> |
||||
/// Interface exported by the server. |
||||
/// </summary> |
||||
public static partial class RouteGuide |
||||
{ |
||||
static readonly string __ServiceName = "routeguide.RouteGuide"; |
||||
|
||||
static readonly grpc::Marshaller<global::Routeguide.Point> __Marshaller_routeguide_Point = grpc::Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Routeguide.Point.Parser.ParseFrom); |
||||
static readonly grpc::Marshaller<global::Routeguide.Feature> __Marshaller_routeguide_Feature = grpc::Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Routeguide.Feature.Parser.ParseFrom); |
||||
static readonly grpc::Marshaller<global::Routeguide.Rectangle> __Marshaller_routeguide_Rectangle = grpc::Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Routeguide.Rectangle.Parser.ParseFrom); |
||||
static readonly grpc::Marshaller<global::Routeguide.RouteSummary> __Marshaller_routeguide_RouteSummary = grpc::Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Routeguide.RouteSummary.Parser.ParseFrom); |
||||
static readonly grpc::Marshaller<global::Routeguide.RouteNote> __Marshaller_routeguide_RouteNote = grpc::Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Routeguide.RouteNote.Parser.ParseFrom); |
||||
|
||||
static readonly grpc::Method<global::Routeguide.Point, global::Routeguide.Feature> __Method_GetFeature = new grpc::Method<global::Routeguide.Point, global::Routeguide.Feature>( |
||||
grpc::MethodType.Unary, |
||||
__ServiceName, |
||||
"GetFeature", |
||||
__Marshaller_routeguide_Point, |
||||
__Marshaller_routeguide_Feature); |
||||
|
||||
static readonly grpc::Method<global::Routeguide.Rectangle, global::Routeguide.Feature> __Method_ListFeatures = new grpc::Method<global::Routeguide.Rectangle, global::Routeguide.Feature>( |
||||
grpc::MethodType.ServerStreaming, |
||||
__ServiceName, |
||||
"ListFeatures", |
||||
__Marshaller_routeguide_Rectangle, |
||||
__Marshaller_routeguide_Feature); |
||||
|
||||
static readonly grpc::Method<global::Routeguide.Point, global::Routeguide.RouteSummary> __Method_RecordRoute = new grpc::Method<global::Routeguide.Point, global::Routeguide.RouteSummary>( |
||||
grpc::MethodType.ClientStreaming, |
||||
__ServiceName, |
||||
"RecordRoute", |
||||
__Marshaller_routeguide_Point, |
||||
__Marshaller_routeguide_RouteSummary); |
||||
|
||||
static readonly grpc::Method<global::Routeguide.RouteNote, global::Routeguide.RouteNote> __Method_RouteChat = new grpc::Method<global::Routeguide.RouteNote, global::Routeguide.RouteNote>( |
||||
grpc::MethodType.DuplexStreaming, |
||||
__ServiceName, |
||||
"RouteChat", |
||||
__Marshaller_routeguide_RouteNote, |
||||
__Marshaller_routeguide_RouteNote); |
||||
|
||||
/// <summary>Service descriptor</summary> |
||||
public static global::Google.Protobuf.Reflection.ServiceDescriptor Descriptor |
||||
{ |
||||
get { return global::Routeguide.RouteGuideReflection.Descriptor.Services[0]; } |
||||
} |
||||
|
||||
/// <summary>Base class for server-side implementations of RouteGuide</summary> |
||||
public abstract partial class RouteGuideBase |
||||
{ |
||||
/// <summary> |
||||
/// A simple RPC. |
||||
/// |
||||
/// Obtains the feature at a given position. |
||||
/// |
||||
/// A feature with an empty name is returned if there's no feature at the given |
||||
/// position. |
||||
/// </summary> |
||||
/// <param name="request">The request received from the client.</param> |
||||
/// <param name="context">The context of the server-side call handler being invoked.</param> |
||||
/// <returns>The response to send back to the client (wrapped by a task).</returns> |
||||
public virtual global::System.Threading.Tasks.Task<global::Routeguide.Feature> GetFeature(global::Routeguide.Point request, grpc::ServerCallContext context) |
||||
{ |
||||
throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, "")); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// A server-to-client streaming RPC. |
||||
/// |
||||
/// Obtains the Features available within the given Rectangle. Results are |
||||
/// streamed rather than returned at once (e.g. in a response message with a |
||||
/// repeated field), as the rectangle may cover a large area and contain a |
||||
/// huge number of features. |
||||
/// </summary> |
||||
/// <param name="request">The request received from the client.</param> |
||||
/// <param name="responseStream">Used for sending responses back to the client.</param> |
||||
/// <param name="context">The context of the server-side call handler being invoked.</param> |
||||
/// <returns>A task indicating completion of the handler.</returns> |
||||
public virtual global::System.Threading.Tasks.Task ListFeatures(global::Routeguide.Rectangle request, grpc::IServerStreamWriter<global::Routeguide.Feature> responseStream, grpc::ServerCallContext context) |
||||
{ |
||||
throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, "")); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// A client-to-server streaming RPC. |
||||
/// |
||||
/// Accepts a stream of Points on a route being traversed, returning a |
||||
/// RouteSummary when traversal is completed. |
||||
/// </summary> |
||||
/// <param name="requestStream">Used for reading requests from the client.</param> |
||||
/// <param name="context">The context of the server-side call handler being invoked.</param> |
||||
/// <returns>The response to send back to the client (wrapped by a task).</returns> |
||||
public virtual global::System.Threading.Tasks.Task<global::Routeguide.RouteSummary> RecordRoute(grpc::IAsyncStreamReader<global::Routeguide.Point> requestStream, grpc::ServerCallContext context) |
||||
{ |
||||
throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, "")); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// A Bidirectional streaming RPC. |
||||
/// |
||||
/// Accepts a stream of RouteNotes sent while a route is being traversed, |
||||
/// while receiving other RouteNotes (e.g. from other users). |
||||
/// </summary> |
||||
/// <param name="requestStream">Used for reading requests from the client.</param> |
||||
/// <param name="responseStream">Used for sending responses back to the client.</param> |
||||
/// <param name="context">The context of the server-side call handler being invoked.</param> |
||||
/// <returns>A task indicating completion of the handler.</returns> |
||||
public virtual global::System.Threading.Tasks.Task RouteChat(grpc::IAsyncStreamReader<global::Routeguide.RouteNote> requestStream, grpc::IServerStreamWriter<global::Routeguide.RouteNote> responseStream, grpc::ServerCallContext context) |
||||
{ |
||||
throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, "")); |
||||
} |
||||
|
||||
} |
||||
|
||||
/// <summary>Client for RouteGuide</summary> |
||||
public partial class RouteGuideClient : grpc::ClientBase<RouteGuideClient> |
||||
{ |
||||
/// <summary>Creates a new client for RouteGuide</summary> |
||||
/// <param name="channel">The channel to use to make remote calls.</param> |
||||
public RouteGuideClient(grpc::Channel channel) : base(channel) |
||||
{ |
||||
} |
||||
/// <summary>Creates a new client for RouteGuide that uses a custom <c>CallInvoker</c>.</summary> |
||||
/// <param name="callInvoker">The callInvoker to use to make remote calls.</param> |
||||
public RouteGuideClient(grpc::CallInvoker callInvoker) : base(callInvoker) |
||||
{ |
||||
} |
||||
/// <summary>Protected parameterless constructor to allow creation of test doubles.</summary> |
||||
protected RouteGuideClient() : base() |
||||
{ |
||||
} |
||||
/// <summary>Protected constructor to allow creation of configured clients.</summary> |
||||
/// <param name="configuration">The client configuration.</param> |
||||
protected RouteGuideClient(ClientBaseConfiguration configuration) : base(configuration) |
||||
{ |
||||
} |
||||
|
||||
/// <summary> |
||||
/// A simple RPC. |
||||
/// |
||||
/// Obtains the feature at a given position. |
||||
/// |
||||
/// A feature with an empty name is returned if there's no feature at the given |
||||
/// position. |
||||
/// </summary> |
||||
/// <param name="request">The request to send to the server.</param> |
||||
/// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
||||
/// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param> |
||||
/// <param name="cancellationToken">An optional token for canceling the call.</param> |
||||
/// <returns>The response received from the server.</returns> |
||||
public virtual global::Routeguide.Feature GetFeature(global::Routeguide.Point request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) |
||||
{ |
||||
return GetFeature(request, new grpc::CallOptions(headers, deadline, cancellationToken)); |
||||
} |
||||
/// <summary> |
||||
/// A simple RPC. |
||||
/// |
||||
/// Obtains the feature at a given position. |
||||
/// |
||||
/// A feature with an empty name is returned if there's no feature at the given |
||||
/// position. |
||||
/// </summary> |
||||
/// <param name="request">The request to send to the server.</param> |
||||
/// <param name="options">The options for the call.</param> |
||||
/// <returns>The response received from the server.</returns> |
||||
public virtual global::Routeguide.Feature GetFeature(global::Routeguide.Point request, grpc::CallOptions options) |
||||
{ |
||||
return CallInvoker.BlockingUnaryCall(__Method_GetFeature, null, options, request); |
||||
} |
||||
/// <summary> |
||||
/// A simple RPC. |
||||
/// |
||||
/// Obtains the feature at a given position. |
||||
/// |
||||
/// A feature with an empty name is returned if there's no feature at the given |
||||
/// position. |
||||
/// </summary> |
||||
/// <param name="request">The request to send to the server.</param> |
||||
/// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
||||
/// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param> |
||||
/// <param name="cancellationToken">An optional token for canceling the call.</param> |
||||
/// <returns>The call object.</returns> |
||||
public virtual grpc::AsyncUnaryCall<global::Routeguide.Feature> GetFeatureAsync(global::Routeguide.Point request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) |
||||
{ |
||||
return GetFeatureAsync(request, new grpc::CallOptions(headers, deadline, cancellationToken)); |
||||
} |
||||
/// <summary> |
||||
/// A simple RPC. |
||||
/// |
||||
/// Obtains the feature at a given position. |
||||
/// |
||||
/// A feature with an empty name is returned if there's no feature at the given |
||||
/// position. |
||||
/// </summary> |
||||
/// <param name="request">The request to send to the server.</param> |
||||
/// <param name="options">The options for the call.</param> |
||||
/// <returns>The call object.</returns> |
||||
public virtual grpc::AsyncUnaryCall<global::Routeguide.Feature> GetFeatureAsync(global::Routeguide.Point request, grpc::CallOptions options) |
||||
{ |
||||
return CallInvoker.AsyncUnaryCall(__Method_GetFeature, null, options, request); |
||||
} |
||||
/// <summary> |
||||
/// A server-to-client streaming RPC. |
||||
/// |
||||
/// Obtains the Features available within the given Rectangle. Results are |
||||
/// streamed rather than returned at once (e.g. in a response message with a |
||||
/// repeated field), as the rectangle may cover a large area and contain a |
||||
/// huge number of features. |
||||
/// </summary> |
||||
/// <param name="request">The request to send to the server.</param> |
||||
/// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
||||
/// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param> |
||||
/// <param name="cancellationToken">An optional token for canceling the call.</param> |
||||
/// <returns>The call object.</returns> |
||||
public virtual grpc::AsyncServerStreamingCall<global::Routeguide.Feature> ListFeatures(global::Routeguide.Rectangle request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) |
||||
{ |
||||
return ListFeatures(request, new grpc::CallOptions(headers, deadline, cancellationToken)); |
||||
} |
||||
/// <summary> |
||||
/// A server-to-client streaming RPC. |
||||
/// |
||||
/// Obtains the Features available within the given Rectangle. Results are |
||||
/// streamed rather than returned at once (e.g. in a response message with a |
||||
/// repeated field), as the rectangle may cover a large area and contain a |
||||
/// huge number of features. |
||||
/// </summary> |
||||
/// <param name="request">The request to send to the server.</param> |
||||
/// <param name="options">The options for the call.</param> |
||||
/// <returns>The call object.</returns> |
||||
public virtual grpc::AsyncServerStreamingCall<global::Routeguide.Feature> ListFeatures(global::Routeguide.Rectangle request, grpc::CallOptions options) |
||||
{ |
||||
return CallInvoker.AsyncServerStreamingCall(__Method_ListFeatures, null, options, request); |
||||
} |
||||
/// <summary> |
||||
/// A client-to-server streaming RPC. |
||||
/// |
||||
/// Accepts a stream of Points on a route being traversed, returning a |
||||
/// RouteSummary when traversal is completed. |
||||
/// </summary> |
||||
/// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
||||
/// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param> |
||||
/// <param name="cancellationToken">An optional token for canceling the call.</param> |
||||
/// <returns>The call object.</returns> |
||||
public virtual grpc::AsyncClientStreamingCall<global::Routeguide.Point, global::Routeguide.RouteSummary> RecordRoute(grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) |
||||
{ |
||||
return RecordRoute(new grpc::CallOptions(headers, deadline, cancellationToken)); |
||||
} |
||||
/// <summary> |
||||
/// A client-to-server streaming RPC. |
||||
/// |
||||
/// Accepts a stream of Points on a route being traversed, returning a |
||||
/// RouteSummary when traversal is completed. |
||||
/// </summary> |
||||
/// <param name="options">The options for the call.</param> |
||||
/// <returns>The call object.</returns> |
||||
public virtual grpc::AsyncClientStreamingCall<global::Routeguide.Point, global::Routeguide.RouteSummary> RecordRoute(grpc::CallOptions options) |
||||
{ |
||||
return CallInvoker.AsyncClientStreamingCall(__Method_RecordRoute, null, options); |
||||
} |
||||
/// <summary> |
||||
/// A Bidirectional streaming RPC. |
||||
/// |
||||
/// Accepts a stream of RouteNotes sent while a route is being traversed, |
||||
/// while receiving other RouteNotes (e.g. from other users). |
||||
/// </summary> |
||||
/// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
||||
/// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param> |
||||
/// <param name="cancellationToken">An optional token for canceling the call.</param> |
||||
/// <returns>The call object.</returns> |
||||
public virtual grpc::AsyncDuplexStreamingCall<global::Routeguide.RouteNote, global::Routeguide.RouteNote> RouteChat(grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) |
||||
{ |
||||
return RouteChat(new grpc::CallOptions(headers, deadline, cancellationToken)); |
||||
} |
||||
/// <summary> |
||||
/// A Bidirectional streaming RPC. |
||||
/// |
||||
/// Accepts a stream of RouteNotes sent while a route is being traversed, |
||||
/// while receiving other RouteNotes (e.g. from other users). |
||||
/// </summary> |
||||
/// <param name="options">The options for the call.</param> |
||||
/// <returns>The call object.</returns> |
||||
public virtual grpc::AsyncDuplexStreamingCall<global::Routeguide.RouteNote, global::Routeguide.RouteNote> RouteChat(grpc::CallOptions options) |
||||
{ |
||||
return CallInvoker.AsyncDuplexStreamingCall(__Method_RouteChat, null, options); |
||||
} |
||||
/// <summary>Creates a new instance of client from given <c>ClientBaseConfiguration</c>.</summary> |
||||
protected override RouteGuideClient NewInstance(ClientBaseConfiguration configuration) |
||||
{ |
||||
return new RouteGuideClient(configuration); |
||||
} |
||||
} |
||||
|
||||
/// <summary>Creates service definition that can be registered with a server</summary> |
||||
/// <param name="serviceImpl">An object implementing the server-side handling logic.</param> |
||||
public static grpc::ServerServiceDefinition BindService(RouteGuideBase serviceImpl) |
||||
{ |
||||
return grpc::ServerServiceDefinition.CreateBuilder() |
||||
.AddMethod(__Method_GetFeature, serviceImpl.GetFeature) |
||||
.AddMethod(__Method_ListFeatures, serviceImpl.ListFeatures) |
||||
.AddMethod(__Method_RecordRoute, serviceImpl.RecordRoute) |
||||
.AddMethod(__Method_RouteChat, serviceImpl.RouteChat).Build(); |
||||
} |
||||
|
||||
} |
||||
} |
||||
#endregion |
@ -1,28 +0,0 @@ |
||||
@rem Copyright 2016 gRPC authors. |
||||
@rem |
||||
@rem Licensed under the Apache License, Version 2.0 (the "License"); |
||||
@rem you may not use this file except in compliance with the License. |
||||
@rem You may obtain a copy of the License at |
||||
@rem |
||||
@rem http://www.apache.org/licenses/LICENSE-2.0 |
||||
@rem |
||||
@rem Unless required by applicable law or agreed to in writing, software |
||||
@rem distributed under the License is distributed on an "AS IS" BASIS, |
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
@rem See the License for the specific language governing permissions and |
||||
@rem limitations under the License. |
||||
|
||||
@rem Generate the C# code for .proto files |
||||
|
||||
setlocal |
||||
|
||||
@rem enter this directory |
||||
cd /d %~dp0 |
||||
|
||||
@rem packages will be available in nuget cache directory once the project is built or after "dotnet restore" |
||||
set PROTOC=%UserProfile%\.nuget\packages\Google.Protobuf.Tools\3.6.1\tools\windows_x64\protoc.exe |
||||
set PLUGIN=%UserProfile%\.nuget\packages\Grpc.Tools\1.14.1\tools\windows_x64\grpc_csharp_plugin.exe |
||||
|
||||
%PROTOC% -I../../protos --csharp_out RouteGuide ../../protos/route_guide.proto --grpc_out RouteGuide --plugin=protoc-gen-grpc=%PLUGIN% |
||||
|
||||
endlocal |
@ -0,0 +1,6 @@ |
||||
An example showing how to add custom HTTP2 headers (or [metadata](https://grpc.io/grpc/python/glossary.html) in gRPC glossary) |
||||
|
||||
HTTP2 supports initial headers and trailing headers, which gRPC utilizes both of them ([learn more](https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md)). |
||||
|
||||
More complete documentation lives at [grpc.io](https://grpc.io/docs/tutorials/basic/python.html). |
||||
For API reference please see [API](https://grpc.io/grpc/python/grpc.html). |
@ -0,0 +1,134 @@ |
||||
# Generated by the protocol buffer compiler. DO NOT EDIT! |
||||
# source: helloworld.proto |
||||
|
||||
import sys |
||||
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) |
||||
from google.protobuf import descriptor as _descriptor |
||||
from google.protobuf import message as _message |
||||
from google.protobuf import reflection as _reflection |
||||
from google.protobuf import symbol_database as _symbol_database |
||||
from google.protobuf import descriptor_pb2 |
||||
# @@protoc_insertion_point(imports) |
||||
|
||||
_sym_db = _symbol_database.Default() |
||||
|
||||
|
||||
|
||||
|
||||
DESCRIPTOR = _descriptor.FileDescriptor( |
||||
name='helloworld.proto', |
||||
package='helloworld', |
||||
syntax='proto3', |
||||
serialized_pb=_b('\n\x10helloworld.proto\x12\nhelloworld\"\x1c\n\x0cHelloRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"\x1d\n\nHelloReply\x12\x0f\n\x07message\x18\x01 \x01(\t2I\n\x07Greeter\x12>\n\x08SayHello\x12\x18.helloworld.HelloRequest\x1a\x16.helloworld.HelloReply\"\x00\x42\x36\n\x1bio.grpc.examples.helloworldB\x0fHelloWorldProtoP\x01\xa2\x02\x03HLWb\x06proto3') |
||||
) |
||||
|
||||
|
||||
|
||||
|
||||
_HELLOREQUEST = _descriptor.Descriptor( |
||||
name='HelloRequest', |
||||
full_name='helloworld.HelloRequest', |
||||
filename=None, |
||||
file=DESCRIPTOR, |
||||
containing_type=None, |
||||
fields=[ |
||||
_descriptor.FieldDescriptor( |
||||
name='name', full_name='helloworld.HelloRequest.name', index=0, |
||||
number=1, type=9, cpp_type=9, label=1, |
||||
has_default_value=False, default_value=_b("").decode('utf-8'), |
||||
message_type=None, enum_type=None, containing_type=None, |
||||
is_extension=False, extension_scope=None, |
||||
options=None), |
||||
], |
||||
extensions=[ |
||||
], |
||||
nested_types=[], |
||||
enum_types=[ |
||||
], |
||||
options=None, |
||||
is_extendable=False, |
||||
syntax='proto3', |
||||
extension_ranges=[], |
||||
oneofs=[ |
||||
], |
||||
serialized_start=32, |
||||
serialized_end=60, |
||||
) |
||||
|
||||
|
||||
_HELLOREPLY = _descriptor.Descriptor( |
||||
name='HelloReply', |
||||
full_name='helloworld.HelloReply', |
||||
filename=None, |
||||
file=DESCRIPTOR, |
||||
containing_type=None, |
||||
fields=[ |
||||
_descriptor.FieldDescriptor( |
||||
name='message', full_name='helloworld.HelloReply.message', index=0, |
||||
number=1, type=9, cpp_type=9, label=1, |
||||
has_default_value=False, default_value=_b("").decode('utf-8'), |
||||
message_type=None, enum_type=None, containing_type=None, |
||||
is_extension=False, extension_scope=None, |
||||
options=None), |
||||
], |
||||
extensions=[ |
||||
], |
||||
nested_types=[], |
||||
enum_types=[ |
||||
], |
||||
options=None, |
||||
is_extendable=False, |
||||
syntax='proto3', |
||||
extension_ranges=[], |
||||
oneofs=[ |
||||
], |
||||
serialized_start=62, |
||||
serialized_end=91, |
||||
) |
||||
|
||||
DESCRIPTOR.message_types_by_name['HelloRequest'] = _HELLOREQUEST |
||||
DESCRIPTOR.message_types_by_name['HelloReply'] = _HELLOREPLY |
||||
_sym_db.RegisterFileDescriptor(DESCRIPTOR) |
||||
|
||||
HelloRequest = _reflection.GeneratedProtocolMessageType('HelloRequest', (_message.Message,), dict( |
||||
DESCRIPTOR = _HELLOREQUEST, |
||||
__module__ = 'helloworld_pb2' |
||||
# @@protoc_insertion_point(class_scope:helloworld.HelloRequest) |
||||
)) |
||||
_sym_db.RegisterMessage(HelloRequest) |
||||
|
||||
HelloReply = _reflection.GeneratedProtocolMessageType('HelloReply', (_message.Message,), dict( |
||||
DESCRIPTOR = _HELLOREPLY, |
||||
__module__ = 'helloworld_pb2' |
||||
# @@protoc_insertion_point(class_scope:helloworld.HelloReply) |
||||
)) |
||||
_sym_db.RegisterMessage(HelloReply) |
||||
|
||||
|
||||
DESCRIPTOR.has_options = True |
||||
DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\033io.grpc.examples.helloworldB\017HelloWorldProtoP\001\242\002\003HLW')) |
||||
|
||||
_GREETER = _descriptor.ServiceDescriptor( |
||||
name='Greeter', |
||||
full_name='helloworld.Greeter', |
||||
file=DESCRIPTOR, |
||||
index=0, |
||||
options=None, |
||||
serialized_start=93, |
||||
serialized_end=166, |
||||
methods=[ |
||||
_descriptor.MethodDescriptor( |
||||
name='SayHello', |
||||
full_name='helloworld.Greeter.SayHello', |
||||
index=0, |
||||
containing_service=None, |
||||
input_type=_HELLOREQUEST, |
||||
output_type=_HELLOREPLY, |
||||
options=None, |
||||
), |
||||
]) |
||||
_sym_db.RegisterServiceDescriptor(_GREETER) |
||||
|
||||
DESCRIPTOR.services_by_name['Greeter'] = _GREETER |
||||
|
||||
# @@protoc_insertion_point(module_scope) |
@ -0,0 +1,46 @@ |
||||
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! |
||||
import grpc |
||||
|
||||
import helloworld_pb2 as helloworld__pb2 |
||||
|
||||
|
||||
class GreeterStub(object): |
||||
"""The greeting service definition. |
||||
""" |
||||
|
||||
def __init__(self, channel): |
||||
"""Constructor. |
||||
|
||||
Args: |
||||
channel: A grpc.Channel. |
||||
""" |
||||
self.SayHello = channel.unary_unary( |
||||
'/helloworld.Greeter/SayHello', |
||||
request_serializer=helloworld__pb2.HelloRequest.SerializeToString, |
||||
response_deserializer=helloworld__pb2.HelloReply.FromString, |
||||
) |
||||
|
||||
|
||||
class GreeterServicer(object): |
||||
"""The greeting service definition. |
||||
""" |
||||
|
||||
def SayHello(self, request, context): |
||||
"""Sends a greeting |
||||
""" |
||||
context.set_code(grpc.StatusCode.UNIMPLEMENTED) |
||||
context.set_details('Method not implemented!') |
||||
raise NotImplementedError('Method not implemented!') |
||||
|
||||
|
||||
def add_GreeterServicer_to_server(servicer, server): |
||||
rpc_method_handlers = { |
||||
'SayHello': grpc.unary_unary_rpc_method_handler( |
||||
servicer.SayHello, |
||||
request_deserializer=helloworld__pb2.HelloRequest.FromString, |
||||
response_serializer=helloworld__pb2.HelloReply.SerializeToString, |
||||
), |
||||
} |
||||
generic_handler = grpc.method_handlers_generic_handler( |
||||
'helloworld.Greeter', rpc_method_handlers) |
||||
server.add_generic_rpc_handlers((generic_handler,)) |
@ -0,0 +1,48 @@ |
||||
# Copyright 2018 The gRPC Authors |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
"""Example gRPC client that gets/sets metadata (HTTP2 headers)""" |
||||
|
||||
from __future__ import print_function |
||||
import logging |
||||
|
||||
import grpc |
||||
|
||||
import helloworld_pb2 |
||||
import helloworld_pb2_grpc |
||||
|
||||
|
||||
def run(): |
||||
# NOTE(gRPC Python Team): .close() is possible on a channel and should be |
||||
# used in circumstances in which the with statement does not fit the needs |
||||
# of the code. |
||||
with grpc.insecure_channel('localhost:50051') as channel: |
||||
stub = helloworld_pb2_grpc.GreeterStub(channel) |
||||
response, call = stub.SayHello.with_call( |
||||
helloworld_pb2.HelloRequest(name='you'), |
||||
metadata=( |
||||
('initial-metadata-1', 'The value should be str'), |
||||
('binary-metadata-bin', |
||||
b'With -bin surffix, the value can be bytes'), |
||||
('accesstoken', 'gRPC Python is great'), |
||||
)) |
||||
|
||||
print("Greeter client received: " + response.message) |
||||
for key, value in call.trailing_metadata(): |
||||
print('Greeter client received trailing metadata: key=%s value=%s' % |
||||
(key, value)) |
||||
|
||||
|
||||
if __name__ == '__main__': |
||||
logging.basicConfig() |
||||
run() |
@ -0,0 +1,56 @@ |
||||
# Copyright 2018 The gRPC Authors |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
"""Example gRPC server that gets/sets metadata (HTTP2 headers)""" |
||||
|
||||
from __future__ import print_function |
||||
from concurrent import futures |
||||
import time |
||||
import logging |
||||
|
||||
import grpc |
||||
|
||||
import helloworld_pb2 |
||||
import helloworld_pb2_grpc |
||||
|
||||
_ONE_DAY_IN_SECONDS = 60 * 60 * 24 |
||||
|
||||
|
||||
class Greeter(helloworld_pb2_grpc.GreeterServicer): |
||||
|
||||
def SayHello(self, request, context): |
||||
for key, value in context.invocation_metadata(): |
||||
print('Received initial metadata: key=%s value=%s' % (key, value)) |
||||
|
||||
context.set_trailing_metadata(( |
||||
('checksum-bin', b'I agree'), |
||||
('retry', 'false'), |
||||
)) |
||||
return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name) |
||||
|
||||
|
||||
def serve(): |
||||
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) |
||||
helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server) |
||||
server.add_insecure_port('[::]:50051') |
||||
server.start() |
||||
try: |
||||
while True: |
||||
time.sleep(_ONE_DAY_IN_SECONDS) |
||||
except KeyboardInterrupt: |
||||
server.stop(0) |
||||
|
||||
|
||||
if __name__ == '__main__': |
||||
logging.basicConfig() |
||||
serve() |
@ -0,0 +1,116 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
/// An Alarm posts the user provided tag to its associated completion queue upon
|
||||
/// expiry or cancellation.
|
||||
#ifndef GRPCPP_ALARM_IMPL_H |
||||
#define GRPCPP_ALARM_IMPL_H |
||||
|
||||
#include <functional> |
||||
|
||||
#include <grpc/grpc.h> |
||||
#include <grpcpp/impl/codegen/completion_queue.h> |
||||
#include <grpcpp/impl/codegen/completion_queue_tag.h> |
||||
#include <grpcpp/impl/codegen/grpc_library.h> |
||||
#include <grpcpp/impl/codegen/time.h> |
||||
#include <grpcpp/impl/grpc_library.h> |
||||
|
||||
namespace grpc_impl { |
||||
|
||||
/// A thin wrapper around \a grpc_alarm (see / \a / src/core/surface/alarm.h).
|
||||
class Alarm : private ::grpc::GrpcLibraryCodegen { |
||||
public: |
||||
/// Create an unset completion queue alarm
|
||||
Alarm(); |
||||
|
||||
/// Destroy the given completion queue alarm, cancelling it in the process.
|
||||
~Alarm(); |
||||
|
||||
/// DEPRECATED: Create and set a completion queue alarm instance associated to
|
||||
/// \a cq.
|
||||
/// This form is deprecated because it is inherently racy.
|
||||
/// \internal We rely on the presence of \a cq for grpc initialization. If \a
|
||||
/// cq were ever to be removed, a reference to a static
|
||||
/// internal::GrpcLibraryInitializer instance would need to be introduced
|
||||
/// here. \endinternal.
|
||||
template <typename T> |
||||
Alarm(::grpc::CompletionQueue* cq, const T& deadline, void* tag) : Alarm() { |
||||
SetInternal(cq, ::grpc::TimePoint<T>(deadline).raw_time(), tag); |
||||
} |
||||
|
||||
/// Trigger an alarm instance on completion queue \a cq at the specified time.
|
||||
/// Once the alarm expires (at \a deadline) or it's cancelled (see \a Cancel),
|
||||
/// an event with tag \a tag will be added to \a cq. If the alarm expired, the
|
||||
/// event's success bit will be true, false otherwise (ie, upon cancellation).
|
||||
template <typename T> |
||||
void Set(::grpc::CompletionQueue* cq, const T& deadline, void* tag) { |
||||
SetInternal(cq, ::grpc::TimePoint<T>(deadline).raw_time(), tag); |
||||
} |
||||
|
||||
/// Alarms aren't copyable.
|
||||
Alarm(const Alarm&) = delete; |
||||
Alarm& operator=(const Alarm&) = delete; |
||||
|
||||
/// Alarms are movable.
|
||||
Alarm(Alarm&& rhs) : alarm_(rhs.alarm_) { rhs.alarm_ = nullptr; } |
||||
Alarm& operator=(Alarm&& rhs) { |
||||
alarm_ = rhs.alarm_; |
||||
rhs.alarm_ = nullptr; |
||||
return *this; |
||||
} |
||||
|
||||
/// Cancel a completion queue alarm. Calling this function over an alarm that
|
||||
/// has already fired has no effect.
|
||||
void Cancel(); |
||||
|
||||
/// NOTE: class experimental_type is not part of the public API of this class
|
||||
/// TODO(vjpai): Move these contents to the public API of Alarm when
|
||||
/// they are no longer experimental
|
||||
class experimental_type { |
||||
public: |
||||
explicit experimental_type(Alarm* alarm) : alarm_(alarm) {} |
||||
|
||||
/// Set an alarm to invoke callback \a f. The argument to the callback
|
||||
/// states whether the alarm expired at \a deadline (true) or was cancelled
|
||||
/// (false)
|
||||
template <typename T> |
||||
void Set(const T& deadline, std::function<void(bool)> f) { |
||||
alarm_->SetInternal(::grpc::TimePoint<T>(deadline).raw_time(), |
||||
std::move(f)); |
||||
} |
||||
|
||||
private: |
||||
Alarm* alarm_; |
||||
}; |
||||
|
||||
/// NOTE: The function experimental() is not stable public API. It is a view
|
||||
/// to the experimental components of this class. It may be changed or removed
|
||||
/// at any time.
|
||||
experimental_type experimental() { return experimental_type(this); } |
||||
|
||||
private: |
||||
void SetInternal(::grpc::CompletionQueue* cq, gpr_timespec deadline, |
||||
void* tag); |
||||
void SetInternal(gpr_timespec deadline, std::function<void(bool)> f); |
||||
|
||||
::grpc::internal::CompletionQueueTag* alarm_; |
||||
}; |
||||
|
||||
} // namespace grpc_impl
|
||||
|
||||
#endif // GRPCPP_ALARM_IMPL_H
|
@ -1,163 +0,0 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#include <string.h> |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/string_util.h> |
||||
|
||||
#include "src/core/lib/channel/channel_args.h" |
||||
|
||||
#include "src/core/ext/filters/client_channel/lb_policy_factory.h" |
||||
#include "src/core/ext/filters/client_channel/parse_address.h" |
||||
|
||||
grpc_lb_addresses* grpc_lb_addresses_create( |
||||
size_t num_addresses, const grpc_lb_user_data_vtable* user_data_vtable) { |
||||
grpc_lb_addresses* addresses = |
||||
static_cast<grpc_lb_addresses*>(gpr_zalloc(sizeof(grpc_lb_addresses))); |
||||
addresses->num_addresses = num_addresses; |
||||
addresses->user_data_vtable = user_data_vtable; |
||||
const size_t addresses_size = sizeof(grpc_lb_address) * num_addresses; |
||||
addresses->addresses = |
||||
static_cast<grpc_lb_address*>(gpr_zalloc(addresses_size)); |
||||
return addresses; |
||||
} |
||||
|
||||
grpc_lb_addresses* grpc_lb_addresses_copy(const grpc_lb_addresses* addresses) { |
||||
grpc_lb_addresses* new_addresses = grpc_lb_addresses_create( |
||||
addresses->num_addresses, addresses->user_data_vtable); |
||||
memcpy(new_addresses->addresses, addresses->addresses, |
||||
sizeof(grpc_lb_address) * addresses->num_addresses); |
||||
for (size_t i = 0; i < addresses->num_addresses; ++i) { |
||||
if (new_addresses->addresses[i].balancer_name != nullptr) { |
||||
new_addresses->addresses[i].balancer_name = |
||||
gpr_strdup(new_addresses->addresses[i].balancer_name); |
||||
} |
||||
if (new_addresses->addresses[i].user_data != nullptr) { |
||||
new_addresses->addresses[i].user_data = addresses->user_data_vtable->copy( |
||||
new_addresses->addresses[i].user_data); |
||||
} |
||||
} |
||||
return new_addresses; |
||||
} |
||||
|
||||
void grpc_lb_addresses_set_address(grpc_lb_addresses* addresses, size_t index, |
||||
const void* address, size_t address_len, |
||||
bool is_balancer, const char* balancer_name, |
||||
void* user_data) { |
||||
GPR_ASSERT(index < addresses->num_addresses); |
||||
if (user_data != nullptr) GPR_ASSERT(addresses->user_data_vtable != nullptr); |
||||
grpc_lb_address* target = &addresses->addresses[index]; |
||||
memcpy(target->address.addr, address, address_len); |
||||
target->address.len = static_cast<socklen_t>(address_len); |
||||
target->is_balancer = is_balancer; |
||||
target->balancer_name = gpr_strdup(balancer_name); |
||||
target->user_data = user_data; |
||||
} |
||||
|
||||
bool grpc_lb_addresses_set_address_from_uri(grpc_lb_addresses* addresses, |
||||
size_t index, const grpc_uri* uri, |
||||
bool is_balancer, |
||||
const char* balancer_name, |
||||
void* user_data) { |
||||
grpc_resolved_address address; |
||||
if (!grpc_parse_uri(uri, &address)) return false; |
||||
grpc_lb_addresses_set_address(addresses, index, address.addr, address.len, |
||||
is_balancer, balancer_name, user_data); |
||||
return true; |
||||
} |
||||
|
||||
int grpc_lb_addresses_cmp(const grpc_lb_addresses* addresses1, |
||||
const grpc_lb_addresses* addresses2) { |
||||
if (addresses1->num_addresses > addresses2->num_addresses) return 1; |
||||
if (addresses1->num_addresses < addresses2->num_addresses) return -1; |
||||
if (addresses1->user_data_vtable > addresses2->user_data_vtable) return 1; |
||||
if (addresses1->user_data_vtable < addresses2->user_data_vtable) return -1; |
||||
for (size_t i = 0; i < addresses1->num_addresses; ++i) { |
||||
const grpc_lb_address* target1 = &addresses1->addresses[i]; |
||||
const grpc_lb_address* target2 = &addresses2->addresses[i]; |
||||
if (target1->address.len > target2->address.len) return 1; |
||||
if (target1->address.len < target2->address.len) return -1; |
||||
int retval = memcmp(target1->address.addr, target2->address.addr, |
||||
target1->address.len); |
||||
if (retval != 0) return retval; |
||||
if (target1->is_balancer > target2->is_balancer) return 1; |
||||
if (target1->is_balancer < target2->is_balancer) return -1; |
||||
const char* balancer_name1 = |
||||
target1->balancer_name != nullptr ? target1->balancer_name : ""; |
||||
const char* balancer_name2 = |
||||
target2->balancer_name != nullptr ? target2->balancer_name : ""; |
||||
retval = strcmp(balancer_name1, balancer_name2); |
||||
if (retval != 0) return retval; |
||||
if (addresses1->user_data_vtable != nullptr) { |
||||
retval = addresses1->user_data_vtable->cmp(target1->user_data, |
||||
target2->user_data); |
||||
if (retval != 0) return retval; |
||||
} |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
void grpc_lb_addresses_destroy(grpc_lb_addresses* addresses) { |
||||
for (size_t i = 0; i < addresses->num_addresses; ++i) { |
||||
gpr_free(addresses->addresses[i].balancer_name); |
||||
if (addresses->addresses[i].user_data != nullptr) { |
||||
addresses->user_data_vtable->destroy(addresses->addresses[i].user_data); |
||||
} |
||||
} |
||||
gpr_free(addresses->addresses); |
||||
gpr_free(addresses); |
||||
} |
||||
|
||||
static void* lb_addresses_copy(void* addresses) { |
||||
return grpc_lb_addresses_copy(static_cast<grpc_lb_addresses*>(addresses)); |
||||
} |
||||
static void lb_addresses_destroy(void* addresses) { |
||||
grpc_lb_addresses_destroy(static_cast<grpc_lb_addresses*>(addresses)); |
||||
} |
||||
static int lb_addresses_cmp(void* addresses1, void* addresses2) { |
||||
return grpc_lb_addresses_cmp(static_cast<grpc_lb_addresses*>(addresses1), |
||||
static_cast<grpc_lb_addresses*>(addresses2)); |
||||
} |
||||
static const grpc_arg_pointer_vtable lb_addresses_arg_vtable = { |
||||
lb_addresses_copy, lb_addresses_destroy, lb_addresses_cmp}; |
||||
|
||||
grpc_arg grpc_lb_addresses_create_channel_arg( |
||||
const grpc_lb_addresses* addresses) { |
||||
return grpc_channel_arg_pointer_create( |
||||
(char*)GRPC_ARG_LB_ADDRESSES, (void*)addresses, &lb_addresses_arg_vtable); |
||||
} |
||||
|
||||
grpc_lb_addresses* grpc_lb_addresses_find_channel_arg( |
||||
const grpc_channel_args* channel_args) { |
||||
const grpc_arg* lb_addresses_arg = |
||||
grpc_channel_args_find(channel_args, GRPC_ARG_LB_ADDRESSES); |
||||
if (lb_addresses_arg == nullptr || lb_addresses_arg->type != GRPC_ARG_POINTER) |
||||
return nullptr; |
||||
return static_cast<grpc_lb_addresses*>(lb_addresses_arg->value.pointer.p); |
||||
} |
||||
|
||||
bool grpc_lb_addresses_contains_balancer_address( |
||||
const grpc_lb_addresses& addresses) { |
||||
for (size_t i = 0; i < addresses.num_addresses; ++i) { |
||||
if (addresses.addresses[i].is_balancer) return true; |
||||
} |
||||
return false; |
||||
} |
@ -0,0 +1,103 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2018 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#include "src/core/ext/filters/client_channel/server_address.h" |
||||
|
||||
#include <string.h> |
||||
|
||||
namespace grpc_core { |
||||
|
||||
//
|
||||
// ServerAddress
|
||||
//
|
||||
|
||||
ServerAddress::ServerAddress(const grpc_resolved_address& address, |
||||
grpc_channel_args* args) |
||||
: address_(address), args_(args) {} |
||||
|
||||
ServerAddress::ServerAddress(const void* address, size_t address_len, |
||||
grpc_channel_args* args) |
||||
: args_(args) { |
||||
memcpy(address_.addr, address, address_len); |
||||
address_.len = static_cast<socklen_t>(address_len); |
||||
} |
||||
|
||||
int ServerAddress::Cmp(const ServerAddress& other) const { |
||||
if (address_.len > other.address_.len) return 1; |
||||
if (address_.len < other.address_.len) return -1; |
||||
int retval = memcmp(address_.addr, other.address_.addr, address_.len); |
||||
if (retval != 0) return retval; |
||||
return grpc_channel_args_compare(args_, other.args_); |
||||
} |
||||
|
||||
bool ServerAddress::IsBalancer() const { |
||||
return grpc_channel_arg_get_bool( |
||||
grpc_channel_args_find(args_, GRPC_ARG_ADDRESS_IS_BALANCER), false); |
||||
} |
||||
|
||||
//
|
||||
// ServerAddressList
|
||||
//
|
||||
|
||||
namespace { |
||||
|
||||
void* ServerAddressListCopy(void* addresses) { |
||||
ServerAddressList* a = static_cast<ServerAddressList*>(addresses); |
||||
return New<ServerAddressList>(*a); |
||||
} |
||||
|
||||
void ServerAddressListDestroy(void* addresses) { |
||||
ServerAddressList* a = static_cast<ServerAddressList*>(addresses); |
||||
Delete(a); |
||||
} |
||||
|
||||
int ServerAddressListCompare(void* addresses1, void* addresses2) { |
||||
ServerAddressList* a1 = static_cast<ServerAddressList*>(addresses1); |
||||
ServerAddressList* a2 = static_cast<ServerAddressList*>(addresses2); |
||||
if (a1->size() > a2->size()) return 1; |
||||
if (a1->size() < a2->size()) return -1; |
||||
for (size_t i = 0; i < a1->size(); ++i) { |
||||
int retval = (*a1)[i].Cmp((*a2)[i]); |
||||
if (retval != 0) return retval; |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
const grpc_arg_pointer_vtable server_addresses_arg_vtable = { |
||||
ServerAddressListCopy, ServerAddressListDestroy, ServerAddressListCompare}; |
||||
|
||||
} // namespace
|
||||
|
||||
grpc_arg CreateServerAddressListChannelArg(const ServerAddressList* addresses) { |
||||
return grpc_channel_arg_pointer_create( |
||||
const_cast<char*>(GRPC_ARG_SERVER_ADDRESS_LIST), |
||||
const_cast<ServerAddressList*>(addresses), &server_addresses_arg_vtable); |
||||
} |
||||
|
||||
ServerAddressList* FindServerAddressListChannelArg( |
||||
const grpc_channel_args* channel_args) { |
||||
const grpc_arg* lb_addresses_arg = |
||||
grpc_channel_args_find(channel_args, GRPC_ARG_SERVER_ADDRESS_LIST); |
||||
if (lb_addresses_arg == nullptr || lb_addresses_arg->type != GRPC_ARG_POINTER) |
||||
return nullptr; |
||||
return static_cast<ServerAddressList*>(lb_addresses_arg->value.pointer.p); |
||||
} |
||||
|
||||
} // namespace grpc_core
|
@ -0,0 +1,108 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2018 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_SERVER_ADDRESS_H |
||||
#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_SERVER_ADDRESS_H |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#include "src/core/lib/channel/channel_args.h" |
||||
#include "src/core/lib/gprpp/inlined_vector.h" |
||||
#include "src/core/lib/iomgr/resolve_address.h" |
||||
#include "src/core/lib/uri/uri_parser.h" |
||||
|
||||
// Channel arg key for ServerAddressList.
|
||||
#define GRPC_ARG_SERVER_ADDRESS_LIST "grpc.server_address_list" |
||||
|
||||
// Channel arg key for a bool indicating whether an address is a grpclb
|
||||
// load balancer (as opposed to a backend).
|
||||
#define GRPC_ARG_ADDRESS_IS_BALANCER "grpc.address_is_balancer" |
||||
|
||||
// Channel arg key for a string indicating an address's balancer name.
|
||||
#define GRPC_ARG_ADDRESS_BALANCER_NAME "grpc.address_balancer_name" |
||||
|
||||
namespace grpc_core { |
||||
|
||||
//
|
||||
// ServerAddress
|
||||
//
|
||||
|
||||
// A server address is a grpc_resolved_address with an associated set of
|
||||
// channel args. Any args present here will be merged into the channel
|
||||
// args when a subchannel is created for this address.
|
||||
class ServerAddress { |
||||
public: |
||||
// Takes ownership of args.
|
||||
ServerAddress(const grpc_resolved_address& address, grpc_channel_args* args); |
||||
ServerAddress(const void* address, size_t address_len, |
||||
grpc_channel_args* args); |
||||
|
||||
~ServerAddress() { grpc_channel_args_destroy(args_); } |
||||
|
||||
// Copyable.
|
||||
ServerAddress(const ServerAddress& other) |
||||
: address_(other.address_), args_(grpc_channel_args_copy(other.args_)) {} |
||||
ServerAddress& operator=(const ServerAddress& other) { |
||||
address_ = other.address_; |
||||
grpc_channel_args_destroy(args_); |
||||
args_ = grpc_channel_args_copy(other.args_); |
||||
return *this; |
||||
} |
||||
|
||||
// Movable.
|
||||
ServerAddress(ServerAddress&& other) |
||||
: address_(other.address_), args_(other.args_) { |
||||
other.args_ = nullptr; |
||||
} |
||||
ServerAddress& operator=(ServerAddress&& other) { |
||||
address_ = other.address_; |
||||
args_ = other.args_; |
||||
other.args_ = nullptr; |
||||
return *this; |
||||
} |
||||
|
||||
bool operator==(const ServerAddress& other) const { return Cmp(other) == 0; } |
||||
|
||||
int Cmp(const ServerAddress& other) const; |
||||
|
||||
const grpc_resolved_address& address() const { return address_; } |
||||
const grpc_channel_args* args() const { return args_; } |
||||
|
||||
bool IsBalancer() const; |
||||
|
||||
private: |
||||
grpc_resolved_address address_; |
||||
grpc_channel_args* args_; |
||||
}; |
||||
|
||||
//
|
||||
// ServerAddressList
|
||||
//
|
||||
|
||||
typedef InlinedVector<ServerAddress, 1> ServerAddressList; |
||||
|
||||
// Returns a channel arg containing \a addresses.
|
||||
grpc_arg CreateServerAddressListChannelArg(const ServerAddressList* addresses); |
||||
|
||||
// Returns the ServerListAddress instance in channel_args or NULL.
|
||||
ServerAddressList* FindServerAddressListChannelArg( |
||||
const grpc_channel_args* channel_args); |
||||
|
||||
} // namespace grpc_core
|
||||
|
||||
#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_SERVER_ADDRESS_H */ |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue