├── .gitignore ├── LICENSE ├── README.md ├── cpp ├── README.md ├── client.cpp ├── hello.grpc.pb.cc ├── hello.grpc.pb.h ├── hello.pb.cc ├── hello.pb.h └── server.cpp ├── csharp ├── Hello │ ├── Hello.sln │ ├── Hello │ │ ├── Hello.cs │ │ ├── Hello.csproj │ │ ├── HelloGrpc.cs │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ └── packages.config │ ├── HelloClient │ │ ├── HelloClient.csproj │ │ ├── Program.cs │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ └── packages.config │ └── HelloServer │ │ ├── HelloServer.csproj │ │ ├── Program.cs │ │ ├── Properties │ │ └── AssemblyInfo.cs │ │ └── packages.config └── README.md ├── go ├── README.md ├── client.go ├── go.mod ├── go.sum ├── hello │ ├── hello.pb.go │ └── hello_grpc.pb.go └── server.go ├── hello.proto ├── node ├── README.md ├── client.js ├── package.json └── server.js ├── objective-c ├── HelloClient │ ├── Hello.podspec │ ├── HelloClient.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ ├── HelloClient.xcworkspace │ │ └── contents.xcworkspacedata │ ├── HelloClient │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ │ └── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ │ ├── LaunchScreen.storyboard │ │ │ └── Main.storyboard │ │ ├── Info.plist │ │ ├── ViewController.h │ │ ├── ViewController.m │ │ └── main.m │ ├── Podfile │ └── Podfile.lock └── README.md ├── python ├── README.md ├── client.py ├── hello_pb2.py ├── hello_pb2_grpc.py ├── requirements.txt └── server.py ├── ruby ├── README.md ├── client.rb ├── hello_pb.rb ├── hello_services_pb.rb └── server.rb ├── rust ├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── README.md ├── build.rs └── src │ ├── client.rs │ ├── lib.rs │ ├── proto │ └── mod.rs │ └── server.rs ├── scala ├── .gitignore ├── README.md ├── build.sbt ├── project │ ├── build.properties │ └── plugins.sbt └── src │ └── main │ └── scala │ └── hello │ ├── client │ └── HelloClient.scala │ └── server │ └── HelloServer.scala └── swift ├── HelloClient ├── Bridging-Header.h ├── Hello.podspec ├── HelloClient.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata ├── HelloClient.xcworkspace │ └── contents.xcworkspacedata ├── HelloClient │ ├── AppDelegate.swift │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── Info.plist │ └── ViewController.swift ├── Podfile └── Podfile.lock └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # C/C++ build outputs 2 | .build/ 3 | bins 4 | gens 5 | libs 6 | objs 7 | *.o 8 | cpp/client 9 | cpp/server 10 | 11 | # Python items 12 | cython_debug/ 13 | python_build/ 14 | yapf_virtual_environment/ 15 | python_pylint_venv/ 16 | .coverage* 17 | .eggs 18 | htmlcov/ 19 | dist/ 20 | *.egg 21 | py27/ 22 | py34/ 23 | 24 | # Node installation output 25 | node_modules 26 | src/node/extension_binary/ 27 | 28 | # gcov coverage data 29 | reports 30 | coverage 31 | *.gcno 32 | 33 | # profiler output 34 | *.prof 35 | 36 | # python compiled objects 37 | *.pyc 38 | 39 | # eclipse project files 40 | .cproject 41 | .project 42 | .settings 43 | 44 | # cache for run_tests.py 45 | .run_tests_cache 46 | .preprocessed_build 47 | 48 | # emacs temp files 49 | *~ 50 | 51 | # vim temp files 52 | .*.swp 53 | 54 | # Makefile's cache 55 | cache.mk 56 | 57 | # Ruby's local gem information 58 | Gemfile.lock 59 | 60 | # Temporary test reports 61 | report.xml 62 | latency_trace.txt 63 | latency_trace.*.txt 64 | 65 | # port server log 66 | portlog.txt 67 | 68 | # gyp generated make files 69 | *-gyp.mk 70 | out 71 | 72 | # YCM config files 73 | .ycm_extra_conf.py 74 | 75 | # XCode 76 | ^build/ 77 | *.pbxuser 78 | !default.pbxuser 79 | *.mode1v3 80 | !default.mode1v3 81 | *.mode2v3 82 | !default.mode2v3 83 | *.perspectivev3 84 | !default.perspectivev3 85 | xcuserdata 86 | *.xccheckout 87 | *.moved-aside 88 | DerivedData 89 | *.hmap 90 | *.ipa 91 | *.xcuserstate 92 | *.DS_Store 93 | 94 | # Objective-C generated files 95 | *.pbobjc.* 96 | *.pbrpc.* 97 | 98 | # Cocoapods artifacts 99 | # Podfile.lock and the workspace file are tracked, to ease deleting them. That's 100 | # needed to trigger "pod install" to rerun the preinstall commands. 101 | Pods/ 102 | 103 | # Artifacts directory 104 | /artifacts/ 105 | 106 | # Git generated files for conflicting 107 | *.orig 108 | 109 | # IDE specific folder for JetBrains IDEs 110 | .idea/ 111 | 112 | # Blaze files 113 | bazel-bin 114 | bazel-genfiles 115 | bazel-grpc 116 | bazel-out 117 | bazel-testlogs 118 | 119 | # Debug output 120 | gdb.txt 121 | 122 | # c sharp things 123 | *.userprefs 124 | *.csproj.user 125 | bin/ 126 | obj/ 127 | packages/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Avinash Sajjanshetty 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gRPC Errors - A handy guide to gRPC errors. 2 | 3 | This repository contains code examples in different languages which demonstrate handling errors in gRPC. 4 | 5 | Check the [`hello.proto`](hello.proto) file to see the gRPC method definitions. It has two methods `SayHello` and `SayHelloStrict`: 6 | 7 | func SayHello(name) { 8 | return "Hey, (name)!" 9 | } 10 | 11 | `SayHelloStrict` is similar, but throws an error if the length of name is more than 10 characters. 12 | 13 | Each language directories have instructions to generate gRPC methods in respective languages. I assume that you have done the basic [tutorials](http://www.grpc.io/docs/quickstart/). 14 | 15 | ## Guide 16 | 17 | Check this page for quick guide and examples of all languages - [gRPC Errors](http://avi.im/grpc-errors) 18 | 19 | ## System Requirements 20 | 21 | - [gRPC](https://github.com/grpc/grpc/blob/master/INSTALL.md) 22 | - [protobuf compiler](https://github.com/google/protobuf) 23 | 24 | ## License 25 | 26 | The mighty MIT license. Please check `LICENSE` for more details. -------------------------------------------------------------------------------- /cpp/README.md: -------------------------------------------------------------------------------- 1 | # CPP gRPC 2 | 3 | ## Instructions 4 | 5 | Generate protobuf files: 6 | 7 | $ protoc -I ../ --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` ../hello.proto 8 | 9 | $ protoc -I ../ --cpp_out=. ../hello.proto 10 | 11 | Compile client and server: 12 | 13 | $ g++ -std=c++11 -I/usr/local/include -pthread -c -o client.o client.cpp 14 | 15 | $ g++ hello.pb.o hello.grpc.pb.o client.o -L/usr/local/lib `pkg-config --libs grpc++ grpc` -lgrpc++_reflection -lprotobuf -lpthread -ldl -o client 16 | 17 | $ g++ -std=c++11 -I/usr/local/include -pthread -c -o server.o server.cpp 18 | 19 | $ g++ hello.pb.o hello.grpc.pb.o server.o -L/usr/local/lib `pkg-config --libs grpc++ grpc` -lgrpc++_reflection -lprotobuf -lpthread -ldl -o server 20 | 21 | Run client and server: 22 | 23 | $ ./server & 24 | $ ./client 25 | 26 | -------------------------------------------------------------------------------- /cpp/client.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | #include "hello.grpc.pb.h" 8 | 9 | using grpc::Channel; 10 | using grpc::ClientContext; 11 | using grpc::Status; 12 | using grpc::StatusCode; 13 | using hello::HelloReq; 14 | using hello::HelloResp; 15 | using hello::HelloService; 16 | 17 | class HelloServiceClient { 18 | public: 19 | HelloServiceClient(std::shared_ptr channel) 20 | : stub_(HelloService::NewStub(channel)) {} 21 | 22 | std::string SayHello(const std::string& name) { 23 | HelloReq request; 24 | request.set_name(name); 25 | HelloResp response; 26 | ClientContext context; 27 | 28 | Status status = stub_->SayHello(&context, request, &response); 29 | // ideally you should check for errors here too before 30 | // returning the response 31 | return response.result(); 32 | } 33 | 34 | void SayHelloStrict(const std::string& name) { 35 | HelloReq request; 36 | request.set_name(name); 37 | HelloResp response; 38 | ClientContext context; 39 | 40 | Status status = stub_->SayHelloStrict(&context, request, &response); 41 | 42 | if (status.ok()) { 43 | return; 44 | } else { 45 | // ouch! 46 | // lets print the gRPC error message 47 | // which is "Length of `Name` cannot be more than 10 characters" 48 | std::cout << status.error_message() << std::endl; 49 | // lets print the error code, which is 3 50 | std::cout << status.error_code() << std::endl; 51 | // want to do some specific action based on the error? 52 | if(status.error_code() == StatusCode::INVALID_ARGUMENT) { 53 | // do your thing here 54 | } 55 | return; 56 | } 57 | } 58 | 59 | private: 60 | std::unique_ptr stub_; 61 | }; 62 | 63 | int main(int argc, char** argv) { 64 | HelloServiceClient client(grpc::CreateChannel( 65 | "localhost:50051", grpc::InsecureChannelCredentials())); 66 | std::cout << client.SayHello("Euler") << std::endl; 67 | 68 | // the failing case 69 | client.SayHelloStrict("Leonhard Euler"); 70 | 71 | return 0; 72 | } -------------------------------------------------------------------------------- /cpp/hello.grpc.pb.cc: -------------------------------------------------------------------------------- 1 | // Generated by the gRPC C++ plugin. 2 | // If you make any local change, they will be lost. 3 | // source: hello.proto 4 | 5 | #include "hello.pb.h" 6 | #include "hello.grpc.pb.h" 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | namespace hello { 17 | 18 | static const char* HelloService_method_names[] = { 19 | "/hello.HelloService/SayHello", 20 | "/hello.HelloService/SayHelloStrict", 21 | }; 22 | 23 | std::unique_ptr< HelloService::Stub> HelloService::NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options) { 24 | std::unique_ptr< HelloService::Stub> stub(new HelloService::Stub(channel)); 25 | return stub; 26 | } 27 | 28 | HelloService::Stub::Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel) 29 | : channel_(channel), rpcmethod_SayHello_(HelloService_method_names[0], ::grpc::RpcMethod::NORMAL_RPC, channel) 30 | , rpcmethod_SayHelloStrict_(HelloService_method_names[1], ::grpc::RpcMethod::NORMAL_RPC, channel) 31 | {} 32 | 33 | ::grpc::Status HelloService::Stub::SayHello(::grpc::ClientContext* context, const ::hello::HelloReq& request, ::hello::HelloResp* response) { 34 | return ::grpc::BlockingUnaryCall(channel_.get(), rpcmethod_SayHello_, context, request, response); 35 | } 36 | 37 | ::grpc::ClientAsyncResponseReader< ::hello::HelloResp>* HelloService::Stub::AsyncSayHelloRaw(::grpc::ClientContext* context, const ::hello::HelloReq& request, ::grpc::CompletionQueue* cq) { 38 | return new ::grpc::ClientAsyncResponseReader< ::hello::HelloResp>(channel_.get(), cq, rpcmethod_SayHello_, context, request); 39 | } 40 | 41 | ::grpc::Status HelloService::Stub::SayHelloStrict(::grpc::ClientContext* context, const ::hello::HelloReq& request, ::hello::HelloResp* response) { 42 | return ::grpc::BlockingUnaryCall(channel_.get(), rpcmethod_SayHelloStrict_, context, request, response); 43 | } 44 | 45 | ::grpc::ClientAsyncResponseReader< ::hello::HelloResp>* HelloService::Stub::AsyncSayHelloStrictRaw(::grpc::ClientContext* context, const ::hello::HelloReq& request, ::grpc::CompletionQueue* cq) { 46 | return new ::grpc::ClientAsyncResponseReader< ::hello::HelloResp>(channel_.get(), cq, rpcmethod_SayHelloStrict_, context, request); 47 | } 48 | 49 | HelloService::Service::Service() { 50 | AddMethod(new ::grpc::RpcServiceMethod( 51 | HelloService_method_names[0], 52 | ::grpc::RpcMethod::NORMAL_RPC, 53 | new ::grpc::RpcMethodHandler< HelloService::Service, ::hello::HelloReq, ::hello::HelloResp>( 54 | std::mem_fn(&HelloService::Service::SayHello), this))); 55 | AddMethod(new ::grpc::RpcServiceMethod( 56 | HelloService_method_names[1], 57 | ::grpc::RpcMethod::NORMAL_RPC, 58 | new ::grpc::RpcMethodHandler< HelloService::Service, ::hello::HelloReq, ::hello::HelloResp>( 59 | std::mem_fn(&HelloService::Service::SayHelloStrict), this))); 60 | } 61 | 62 | HelloService::Service::~Service() { 63 | } 64 | 65 | ::grpc::Status HelloService::Service::SayHello(::grpc::ServerContext* context, const ::hello::HelloReq* request, ::hello::HelloResp* response) { 66 | (void) context; 67 | (void) request; 68 | (void) response; 69 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 70 | } 71 | 72 | ::grpc::Status HelloService::Service::SayHelloStrict(::grpc::ServerContext* context, const ::hello::HelloReq* request, ::hello::HelloResp* response) { 73 | (void) context; 74 | (void) request; 75 | (void) response; 76 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 77 | } 78 | 79 | 80 | } // namespace hello 81 | 82 | -------------------------------------------------------------------------------- /cpp/hello.grpc.pb.h: -------------------------------------------------------------------------------- 1 | // Generated by the gRPC C++ plugin. 2 | // If you make any local change, they will be lost. 3 | // source: hello.proto 4 | #ifndef GRPC_hello_2eproto__INCLUDED 5 | #define GRPC_hello_2eproto__INCLUDED 6 | 7 | #include "hello.pb.h" 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace grpc { 20 | class CompletionQueue; 21 | class Channel; 22 | class RpcService; 23 | class ServerCompletionQueue; 24 | class ServerContext; 25 | } // namespace grpc 26 | 27 | namespace hello { 28 | 29 | class HelloService final { 30 | public: 31 | class StubInterface { 32 | public: 33 | virtual ~StubInterface() {} 34 | // This thing just says Hello to anyone 35 | // SayHello('Euler') -> Hello, Euler! 36 | virtual ::grpc::Status SayHello(::grpc::ClientContext* context, const ::hello::HelloReq& request, ::hello::HelloResp* response) = 0; 37 | std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::hello::HelloResp>> AsyncSayHello(::grpc::ClientContext* context, const ::hello::HelloReq& request, ::grpc::CompletionQueue* cq) { 38 | return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::hello::HelloResp>>(AsyncSayHelloRaw(context, request, cq)); 39 | } 40 | // Strict Version responds only to requests which have `Name` length 41 | // less than 10 characters 42 | virtual ::grpc::Status SayHelloStrict(::grpc::ClientContext* context, const ::hello::HelloReq& request, ::hello::HelloResp* response) = 0; 43 | std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::hello::HelloResp>> AsyncSayHelloStrict(::grpc::ClientContext* context, const ::hello::HelloReq& request, ::grpc::CompletionQueue* cq) { 44 | return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::hello::HelloResp>>(AsyncSayHelloStrictRaw(context, request, cq)); 45 | } 46 | private: 47 | virtual ::grpc::ClientAsyncResponseReaderInterface< ::hello::HelloResp>* AsyncSayHelloRaw(::grpc::ClientContext* context, const ::hello::HelloReq& request, ::grpc::CompletionQueue* cq) = 0; 48 | virtual ::grpc::ClientAsyncResponseReaderInterface< ::hello::HelloResp>* AsyncSayHelloStrictRaw(::grpc::ClientContext* context, const ::hello::HelloReq& request, ::grpc::CompletionQueue* cq) = 0; 49 | }; 50 | class Stub final : public StubInterface { 51 | public: 52 | Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel); 53 | ::grpc::Status SayHello(::grpc::ClientContext* context, const ::hello::HelloReq& request, ::hello::HelloResp* response) override; 54 | std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::hello::HelloResp>> AsyncSayHello(::grpc::ClientContext* context, const ::hello::HelloReq& request, ::grpc::CompletionQueue* cq) { 55 | return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::hello::HelloResp>>(AsyncSayHelloRaw(context, request, cq)); 56 | } 57 | ::grpc::Status SayHelloStrict(::grpc::ClientContext* context, const ::hello::HelloReq& request, ::hello::HelloResp* response) override; 58 | std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::hello::HelloResp>> AsyncSayHelloStrict(::grpc::ClientContext* context, const ::hello::HelloReq& request, ::grpc::CompletionQueue* cq) { 59 | return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::hello::HelloResp>>(AsyncSayHelloStrictRaw(context, request, cq)); 60 | } 61 | 62 | private: 63 | std::shared_ptr< ::grpc::ChannelInterface> channel_; 64 | ::grpc::ClientAsyncResponseReader< ::hello::HelloResp>* AsyncSayHelloRaw(::grpc::ClientContext* context, const ::hello::HelloReq& request, ::grpc::CompletionQueue* cq) override; 65 | ::grpc::ClientAsyncResponseReader< ::hello::HelloResp>* AsyncSayHelloStrictRaw(::grpc::ClientContext* context, const ::hello::HelloReq& request, ::grpc::CompletionQueue* cq) override; 66 | const ::grpc::RpcMethod rpcmethod_SayHello_; 67 | const ::grpc::RpcMethod rpcmethod_SayHelloStrict_; 68 | }; 69 | static std::unique_ptr NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options = ::grpc::StubOptions()); 70 | 71 | class Service : public ::grpc::Service { 72 | public: 73 | Service(); 74 | virtual ~Service(); 75 | // This thing just says Hello to anyone 76 | // SayHello('Euler') -> Hello, Euler! 77 | virtual ::grpc::Status SayHello(::grpc::ServerContext* context, const ::hello::HelloReq* request, ::hello::HelloResp* response); 78 | // Strict Version responds only to requests which have `Name` length 79 | // less than 10 characters 80 | virtual ::grpc::Status SayHelloStrict(::grpc::ServerContext* context, const ::hello::HelloReq* request, ::hello::HelloResp* response); 81 | }; 82 | template 83 | class WithAsyncMethod_SayHello : public BaseClass { 84 | private: 85 | void BaseClassMustBeDerivedFromService(const Service *service) {} 86 | public: 87 | WithAsyncMethod_SayHello() { 88 | ::grpc::Service::MarkMethodAsync(0); 89 | } 90 | ~WithAsyncMethod_SayHello() override { 91 | BaseClassMustBeDerivedFromService(this); 92 | } 93 | // disable synchronous version of this method 94 | ::grpc::Status SayHello(::grpc::ServerContext* context, const ::hello::HelloReq* request, ::hello::HelloResp* response) final override { 95 | abort(); 96 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 97 | } 98 | void RequestSayHello(::grpc::ServerContext* context, ::hello::HelloReq* request, ::grpc::ServerAsyncResponseWriter< ::hello::HelloResp>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { 99 | ::grpc::Service::RequestAsyncUnary(0, context, request, response, new_call_cq, notification_cq, tag); 100 | } 101 | }; 102 | template 103 | class WithAsyncMethod_SayHelloStrict : public BaseClass { 104 | private: 105 | void BaseClassMustBeDerivedFromService(const Service *service) {} 106 | public: 107 | WithAsyncMethod_SayHelloStrict() { 108 | ::grpc::Service::MarkMethodAsync(1); 109 | } 110 | ~WithAsyncMethod_SayHelloStrict() override { 111 | BaseClassMustBeDerivedFromService(this); 112 | } 113 | // disable synchronous version of this method 114 | ::grpc::Status SayHelloStrict(::grpc::ServerContext* context, const ::hello::HelloReq* request, ::hello::HelloResp* response) final override { 115 | abort(); 116 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 117 | } 118 | void RequestSayHelloStrict(::grpc::ServerContext* context, ::hello::HelloReq* request, ::grpc::ServerAsyncResponseWriter< ::hello::HelloResp>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { 119 | ::grpc::Service::RequestAsyncUnary(1, context, request, response, new_call_cq, notification_cq, tag); 120 | } 121 | }; 122 | typedef WithAsyncMethod_SayHello > AsyncService; 123 | template 124 | class WithGenericMethod_SayHello : public BaseClass { 125 | private: 126 | void BaseClassMustBeDerivedFromService(const Service *service) {} 127 | public: 128 | WithGenericMethod_SayHello() { 129 | ::grpc::Service::MarkMethodGeneric(0); 130 | } 131 | ~WithGenericMethod_SayHello() override { 132 | BaseClassMustBeDerivedFromService(this); 133 | } 134 | // disable synchronous version of this method 135 | ::grpc::Status SayHello(::grpc::ServerContext* context, const ::hello::HelloReq* request, ::hello::HelloResp* response) final override { 136 | abort(); 137 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 138 | } 139 | }; 140 | template 141 | class WithGenericMethod_SayHelloStrict : public BaseClass { 142 | private: 143 | void BaseClassMustBeDerivedFromService(const Service *service) {} 144 | public: 145 | WithGenericMethod_SayHelloStrict() { 146 | ::grpc::Service::MarkMethodGeneric(1); 147 | } 148 | ~WithGenericMethod_SayHelloStrict() override { 149 | BaseClassMustBeDerivedFromService(this); 150 | } 151 | // disable synchronous version of this method 152 | ::grpc::Status SayHelloStrict(::grpc::ServerContext* context, const ::hello::HelloReq* request, ::hello::HelloResp* response) final override { 153 | abort(); 154 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 155 | } 156 | }; 157 | template 158 | class WithStreamedUnaryMethod_SayHello : public BaseClass { 159 | private: 160 | void BaseClassMustBeDerivedFromService(const Service *service) {} 161 | public: 162 | WithStreamedUnaryMethod_SayHello() { 163 | ::grpc::Service::MarkMethodStreamed(0, 164 | new ::grpc::StreamedUnaryHandler< ::hello::HelloReq, ::hello::HelloResp>(std::bind(&WithStreamedUnaryMethod_SayHello::StreamedSayHello, this, std::placeholders::_1, std::placeholders::_2))); 165 | } 166 | ~WithStreamedUnaryMethod_SayHello() override { 167 | BaseClassMustBeDerivedFromService(this); 168 | } 169 | // disable regular version of this method 170 | ::grpc::Status SayHello(::grpc::ServerContext* context, const ::hello::HelloReq* request, ::hello::HelloResp* response) final override { 171 | abort(); 172 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 173 | } 174 | // replace default version of method with streamed unary 175 | virtual ::grpc::Status StreamedSayHello(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::hello::HelloReq,::hello::HelloResp>* server_unary_streamer) = 0; 176 | }; 177 | template 178 | class WithStreamedUnaryMethod_SayHelloStrict : public BaseClass { 179 | private: 180 | void BaseClassMustBeDerivedFromService(const Service *service) {} 181 | public: 182 | WithStreamedUnaryMethod_SayHelloStrict() { 183 | ::grpc::Service::MarkMethodStreamed(1, 184 | new ::grpc::StreamedUnaryHandler< ::hello::HelloReq, ::hello::HelloResp>(std::bind(&WithStreamedUnaryMethod_SayHelloStrict::StreamedSayHelloStrict, this, std::placeholders::_1, std::placeholders::_2))); 185 | } 186 | ~WithStreamedUnaryMethod_SayHelloStrict() override { 187 | BaseClassMustBeDerivedFromService(this); 188 | } 189 | // disable regular version of this method 190 | ::grpc::Status SayHelloStrict(::grpc::ServerContext* context, const ::hello::HelloReq* request, ::hello::HelloResp* response) final override { 191 | abort(); 192 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 193 | } 194 | // replace default version of method with streamed unary 195 | virtual ::grpc::Status StreamedSayHelloStrict(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::hello::HelloReq,::hello::HelloResp>* server_unary_streamer) = 0; 196 | }; 197 | typedef WithStreamedUnaryMethod_SayHello > StreamedUnaryService; 198 | typedef Service SplitStreamedService; 199 | typedef WithStreamedUnaryMethod_SayHello > StreamedService; 200 | }; 201 | 202 | } // namespace hello 203 | 204 | 205 | #endif // GRPC_hello_2eproto__INCLUDED 206 | -------------------------------------------------------------------------------- /cpp/hello.pb.h: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: hello.proto 3 | 4 | #ifndef PROTOBUF_hello_2eproto__INCLUDED 5 | #define PROTOBUF_hello_2eproto__INCLUDED 6 | 7 | #include 8 | 9 | #include 10 | 11 | #if GOOGLE_PROTOBUF_VERSION < 3002000 12 | #error This file was generated by a newer version of protoc which is 13 | #error incompatible with your Protocol Buffer headers. Please update 14 | #error your headers. 15 | #endif 16 | #if 3002000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 17 | #error This file was generated by an older version of protoc which is 18 | #error incompatible with your Protocol Buffer headers. Please 19 | #error regenerate this file with a newer version of protoc. 20 | #endif 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include // IWYU pragma: export 29 | #include // IWYU pragma: export 30 | #include 31 | // @@protoc_insertion_point(includes) 32 | namespace hello { 33 | class HelloReq; 34 | class HelloReqDefaultTypeInternal; 35 | extern HelloReqDefaultTypeInternal _HelloReq_default_instance_; 36 | class HelloResp; 37 | class HelloRespDefaultTypeInternal; 38 | extern HelloRespDefaultTypeInternal _HelloResp_default_instance_; 39 | } // namespace hello 40 | 41 | namespace hello { 42 | 43 | namespace protobuf_hello_2eproto { 44 | // Internal implementation detail -- do not call these. 45 | struct TableStruct { 46 | static const ::google::protobuf::uint32 offsets[]; 47 | static void InitDefaultsImpl(); 48 | static void Shutdown(); 49 | }; 50 | void AddDescriptors(); 51 | void InitDefaults(); 52 | } // namespace protobuf_hello_2eproto 53 | 54 | // =================================================================== 55 | 56 | class HelloReq : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:hello.HelloReq) */ { 57 | public: 58 | HelloReq(); 59 | virtual ~HelloReq(); 60 | 61 | HelloReq(const HelloReq& from); 62 | 63 | inline HelloReq& operator=(const HelloReq& from) { 64 | CopyFrom(from); 65 | return *this; 66 | } 67 | 68 | static const ::google::protobuf::Descriptor* descriptor(); 69 | static const HelloReq& default_instance(); 70 | 71 | static inline const HelloReq* internal_default_instance() { 72 | return reinterpret_cast( 73 | &_HelloReq_default_instance_); 74 | } 75 | 76 | void Swap(HelloReq* other); 77 | 78 | // implements Message ---------------------------------------------- 79 | 80 | inline HelloReq* New() const PROTOBUF_FINAL { return New(NULL); } 81 | 82 | HelloReq* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL; 83 | void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; 84 | void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; 85 | void CopyFrom(const HelloReq& from); 86 | void MergeFrom(const HelloReq& from); 87 | void Clear() PROTOBUF_FINAL; 88 | bool IsInitialized() const PROTOBUF_FINAL; 89 | 90 | size_t ByteSizeLong() const PROTOBUF_FINAL; 91 | bool MergePartialFromCodedStream( 92 | ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL; 93 | void SerializeWithCachedSizes( 94 | ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; 95 | ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( 96 | bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; 97 | ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) 98 | const PROTOBUF_FINAL { 99 | return InternalSerializeWithCachedSizesToArray( 100 | ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); 101 | } 102 | int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } 103 | private: 104 | void SharedCtor(); 105 | void SharedDtor(); 106 | void SetCachedSize(int size) const PROTOBUF_FINAL; 107 | void InternalSwap(HelloReq* other); 108 | private: 109 | inline ::google::protobuf::Arena* GetArenaNoVirtual() const { 110 | return NULL; 111 | } 112 | inline void* MaybeArenaPtr() const { 113 | return NULL; 114 | } 115 | public: 116 | 117 | ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL; 118 | 119 | // nested types ---------------------------------------------------- 120 | 121 | // accessors ------------------------------------------------------- 122 | 123 | // string Name = 1; 124 | void clear_name(); 125 | static const int kNameFieldNumber = 1; 126 | const ::std::string& name() const; 127 | void set_name(const ::std::string& value); 128 | #if LANG_CXX11 129 | void set_name(::std::string&& value); 130 | #endif 131 | void set_name(const char* value); 132 | void set_name(const char* value, size_t size); 133 | ::std::string* mutable_name(); 134 | ::std::string* release_name(); 135 | void set_allocated_name(::std::string* name); 136 | 137 | // @@protoc_insertion_point(class_scope:hello.HelloReq) 138 | private: 139 | 140 | ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; 141 | ::google::protobuf::internal::ArenaStringPtr name_; 142 | mutable int _cached_size_; 143 | friend struct protobuf_hello_2eproto::TableStruct; 144 | }; 145 | // ------------------------------------------------------------------- 146 | 147 | class HelloResp : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:hello.HelloResp) */ { 148 | public: 149 | HelloResp(); 150 | virtual ~HelloResp(); 151 | 152 | HelloResp(const HelloResp& from); 153 | 154 | inline HelloResp& operator=(const HelloResp& from) { 155 | CopyFrom(from); 156 | return *this; 157 | } 158 | 159 | static const ::google::protobuf::Descriptor* descriptor(); 160 | static const HelloResp& default_instance(); 161 | 162 | static inline const HelloResp* internal_default_instance() { 163 | return reinterpret_cast( 164 | &_HelloResp_default_instance_); 165 | } 166 | 167 | void Swap(HelloResp* other); 168 | 169 | // implements Message ---------------------------------------------- 170 | 171 | inline HelloResp* New() const PROTOBUF_FINAL { return New(NULL); } 172 | 173 | HelloResp* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL; 174 | void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; 175 | void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; 176 | void CopyFrom(const HelloResp& from); 177 | void MergeFrom(const HelloResp& from); 178 | void Clear() PROTOBUF_FINAL; 179 | bool IsInitialized() const PROTOBUF_FINAL; 180 | 181 | size_t ByteSizeLong() const PROTOBUF_FINAL; 182 | bool MergePartialFromCodedStream( 183 | ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL; 184 | void SerializeWithCachedSizes( 185 | ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; 186 | ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( 187 | bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; 188 | ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) 189 | const PROTOBUF_FINAL { 190 | return InternalSerializeWithCachedSizesToArray( 191 | ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); 192 | } 193 | int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } 194 | private: 195 | void SharedCtor(); 196 | void SharedDtor(); 197 | void SetCachedSize(int size) const PROTOBUF_FINAL; 198 | void InternalSwap(HelloResp* other); 199 | private: 200 | inline ::google::protobuf::Arena* GetArenaNoVirtual() const { 201 | return NULL; 202 | } 203 | inline void* MaybeArenaPtr() const { 204 | return NULL; 205 | } 206 | public: 207 | 208 | ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL; 209 | 210 | // nested types ---------------------------------------------------- 211 | 212 | // accessors ------------------------------------------------------- 213 | 214 | // string Result = 1; 215 | void clear_result(); 216 | static const int kResultFieldNumber = 1; 217 | const ::std::string& result() const; 218 | void set_result(const ::std::string& value); 219 | #if LANG_CXX11 220 | void set_result(::std::string&& value); 221 | #endif 222 | void set_result(const char* value); 223 | void set_result(const char* value, size_t size); 224 | ::std::string* mutable_result(); 225 | ::std::string* release_result(); 226 | void set_allocated_result(::std::string* result); 227 | 228 | // @@protoc_insertion_point(class_scope:hello.HelloResp) 229 | private: 230 | 231 | ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; 232 | ::google::protobuf::internal::ArenaStringPtr result_; 233 | mutable int _cached_size_; 234 | friend struct protobuf_hello_2eproto::TableStruct; 235 | }; 236 | // =================================================================== 237 | 238 | 239 | // =================================================================== 240 | 241 | #if !PROTOBUF_INLINE_NOT_IN_HEADERS 242 | // HelloReq 243 | 244 | // string Name = 1; 245 | inline void HelloReq::clear_name() { 246 | name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 247 | } 248 | inline const ::std::string& HelloReq::name() const { 249 | // @@protoc_insertion_point(field_get:hello.HelloReq.Name) 250 | return name_.GetNoArena(); 251 | } 252 | inline void HelloReq::set_name(const ::std::string& value) { 253 | 254 | name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); 255 | // @@protoc_insertion_point(field_set:hello.HelloReq.Name) 256 | } 257 | #if LANG_CXX11 258 | inline void HelloReq::set_name(::std::string&& value) { 259 | 260 | name_.SetNoArena( 261 | &::google::protobuf::internal::GetEmptyStringAlreadyInited(), std::move(value)); 262 | // @@protoc_insertion_point(field_set_rvalue:hello.HelloReq.Name) 263 | } 264 | #endif 265 | inline void HelloReq::set_name(const char* value) { 266 | 267 | name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); 268 | // @@protoc_insertion_point(field_set_char:hello.HelloReq.Name) 269 | } 270 | inline void HelloReq::set_name(const char* value, size_t size) { 271 | 272 | name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), 273 | ::std::string(reinterpret_cast(value), size)); 274 | // @@protoc_insertion_point(field_set_pointer:hello.HelloReq.Name) 275 | } 276 | inline ::std::string* HelloReq::mutable_name() { 277 | 278 | // @@protoc_insertion_point(field_mutable:hello.HelloReq.Name) 279 | return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 280 | } 281 | inline ::std::string* HelloReq::release_name() { 282 | // @@protoc_insertion_point(field_release:hello.HelloReq.Name) 283 | 284 | return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 285 | } 286 | inline void HelloReq::set_allocated_name(::std::string* name) { 287 | if (name != NULL) { 288 | 289 | } else { 290 | 291 | } 292 | name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); 293 | // @@protoc_insertion_point(field_set_allocated:hello.HelloReq.Name) 294 | } 295 | 296 | // ------------------------------------------------------------------- 297 | 298 | // HelloResp 299 | 300 | // string Result = 1; 301 | inline void HelloResp::clear_result() { 302 | result_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 303 | } 304 | inline const ::std::string& HelloResp::result() const { 305 | // @@protoc_insertion_point(field_get:hello.HelloResp.Result) 306 | return result_.GetNoArena(); 307 | } 308 | inline void HelloResp::set_result(const ::std::string& value) { 309 | 310 | result_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); 311 | // @@protoc_insertion_point(field_set:hello.HelloResp.Result) 312 | } 313 | #if LANG_CXX11 314 | inline void HelloResp::set_result(::std::string&& value) { 315 | 316 | result_.SetNoArena( 317 | &::google::protobuf::internal::GetEmptyStringAlreadyInited(), std::move(value)); 318 | // @@protoc_insertion_point(field_set_rvalue:hello.HelloResp.Result) 319 | } 320 | #endif 321 | inline void HelloResp::set_result(const char* value) { 322 | 323 | result_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); 324 | // @@protoc_insertion_point(field_set_char:hello.HelloResp.Result) 325 | } 326 | inline void HelloResp::set_result(const char* value, size_t size) { 327 | 328 | result_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), 329 | ::std::string(reinterpret_cast(value), size)); 330 | // @@protoc_insertion_point(field_set_pointer:hello.HelloResp.Result) 331 | } 332 | inline ::std::string* HelloResp::mutable_result() { 333 | 334 | // @@protoc_insertion_point(field_mutable:hello.HelloResp.Result) 335 | return result_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 336 | } 337 | inline ::std::string* HelloResp::release_result() { 338 | // @@protoc_insertion_point(field_release:hello.HelloResp.Result) 339 | 340 | return result_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 341 | } 342 | inline void HelloResp::set_allocated_result(::std::string* result) { 343 | if (result != NULL) { 344 | 345 | } else { 346 | 347 | } 348 | result_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), result); 349 | // @@protoc_insertion_point(field_set_allocated:hello.HelloResp.Result) 350 | } 351 | 352 | #endif // !PROTOBUF_INLINE_NOT_IN_HEADERS 353 | // ------------------------------------------------------------------- 354 | 355 | 356 | // @@protoc_insertion_point(namespace_scope) 357 | 358 | 359 | } // namespace hello 360 | 361 | // @@protoc_insertion_point(global_scope) 362 | 363 | #endif // PROTOBUF_hello_2eproto__INCLUDED 364 | -------------------------------------------------------------------------------- /cpp/server.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | #include "hello.grpc.pb.h" 8 | 9 | using grpc::Server; 10 | using grpc::ServerBuilder; 11 | using grpc::ServerContext; 12 | using grpc::Status; 13 | using grpc::StatusCode; 14 | using hello::HelloReq; 15 | using hello::HelloResp; 16 | using hello::HelloService; 17 | 18 | class HelloServiceImpl final : public HelloService::Service { 19 | 20 | Status SayHello(ServerContext* context, const HelloReq* request, 21 | HelloResp* reply) override { 22 | reply->set_result("Hey, " + request->name() + "!"); 23 | return Status::OK; 24 | } 25 | 26 | Status SayHelloStrict(ServerContext* context, const HelloReq* request, 27 | HelloResp* reply) override { 28 | std::string name(request->name()); 29 | if (name.length() >= 10) { 30 | std::string msg("Length of `Name` cannot be more than 10 characters"); 31 | return Status(StatusCode::INVALID_ARGUMENT, msg); 32 | } 33 | reply->set_result("Hey, " + name + "!"); 34 | return Status::OK; 35 | } 36 | 37 | }; 38 | 39 | void RunServer() { 40 | std::string server_address("0.0.0.0:50051"); 41 | HelloServiceImpl service; 42 | ServerBuilder builder; 43 | builder.AddListeningPort(server_address, grpc::InsecureServerCredentials()); 44 | builder.RegisterService(&service); 45 | std::unique_ptr server(builder.BuildAndStart()); 46 | std::cout << "Server listening on " << server_address << std::endl; 47 | server->Wait(); 48 | } 49 | 50 | int main(int argc, char** argv) { 51 | RunServer(); 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /csharp/Hello/Hello.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hello", "Hello\Hello.csproj", "{1C6E2002-B032-4822-A725-3032FDAFD2B5}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloClient", "HelloClient\HelloClient.csproj", "{39345BFB-E318-437D-8846-BB1056A2062E}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloServer", "HelloServer\HelloServer.csproj", "{DE5DD14D-31E3-4847-9B6C-76F0338CE3CD}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|x86 = Debug|x86 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {1C6E2002-B032-4822-A725-3032FDAFD2B5}.Debug|x86.ActiveCfg = Debug|x86 17 | {1C6E2002-B032-4822-A725-3032FDAFD2B5}.Debug|x86.Build.0 = Debug|x86 18 | {1C6E2002-B032-4822-A725-3032FDAFD2B5}.Release|x86.ActiveCfg = Release|x86 19 | {1C6E2002-B032-4822-A725-3032FDAFD2B5}.Release|x86.Build.0 = Release|x86 20 | {39345BFB-E318-437D-8846-BB1056A2062E}.Debug|x86.ActiveCfg = Debug|x86 21 | {39345BFB-E318-437D-8846-BB1056A2062E}.Debug|x86.Build.0 = Debug|x86 22 | {39345BFB-E318-437D-8846-BB1056A2062E}.Release|x86.ActiveCfg = Release|x86 23 | {39345BFB-E318-437D-8846-BB1056A2062E}.Release|x86.Build.0 = Release|x86 24 | {DE5DD14D-31E3-4847-9B6C-76F0338CE3CD}.Debug|x86.ActiveCfg = Debug|x86 25 | {DE5DD14D-31E3-4847-9B6C-76F0338CE3CD}.Debug|x86.Build.0 = Debug|x86 26 | {DE5DD14D-31E3-4847-9B6C-76F0338CE3CD}.Release|x86.ActiveCfg = Release|x86 27 | {DE5DD14D-31E3-4847-9B6C-76F0338CE3CD}.Release|x86.Build.0 = Release|x86 28 | EndGlobalSection 29 | EndGlobal 30 | -------------------------------------------------------------------------------- /csharp/Hello/Hello/Hello.cs: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: hello.proto 3 | #pragma warning disable 1591, 0612, 3021 4 | #region Designer generated code 5 | 6 | using pb = global::Google.Protobuf; 7 | using pbc = global::Google.Protobuf.Collections; 8 | using pbr = global::Google.Protobuf.Reflection; 9 | using scg = global::System.Collections.Generic; 10 | namespace Hello { 11 | 12 | /// Holder for reflection information generated from hello.proto 13 | public static partial class HelloReflection { 14 | 15 | #region Descriptor 16 | /// File descriptor for hello.proto 17 | public static pbr::FileDescriptor Descriptor { 18 | get { return descriptor; } 19 | } 20 | private static pbr::FileDescriptor descriptor; 21 | 22 | static HelloReflection() { 23 | byte[] descriptorData = global::System.Convert.FromBase64String( 24 | string.Concat( 25 | "CgtoZWxsby5wcm90bxIFaGVsbG8iGAoISGVsbG9SZXESDAoETmFtZRgBIAEo", 26 | "CSIbCglIZWxsb1Jlc3ASDgoGUmVzdWx0GAEgASgJMnYKDEhlbGxvU2Vydmlj", 27 | "ZRIvCghTYXlIZWxsbxIPLmhlbGxvLkhlbGxvUmVxGhAuaGVsbG8uSGVsbG9S", 28 | "ZXNwIgASNQoOU2F5SGVsbG9TdHJpY3QSDy5oZWxsby5IZWxsb1JlcRoQLmhl", 29 | "bGxvLkhlbGxvUmVzcCIAYgZwcm90bzM=")); 30 | descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, 31 | new pbr::FileDescriptor[] { }, 32 | new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { 33 | new pbr::GeneratedClrTypeInfo(typeof(global::Hello.HelloReq), global::Hello.HelloReq.Parser, new[]{ "Name" }, null, null, null), 34 | new pbr::GeneratedClrTypeInfo(typeof(global::Hello.HelloResp), global::Hello.HelloResp.Parser, new[]{ "Result" }, null, null, null) 35 | })); 36 | } 37 | #endregion 38 | 39 | } 40 | #region Messages 41 | public sealed partial class HelloReq : pb::IMessage { 42 | private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new HelloReq()); 43 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 44 | public static pb::MessageParser Parser { get { return _parser; } } 45 | 46 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 47 | public static pbr::MessageDescriptor Descriptor { 48 | get { return global::Hello.HelloReflection.Descriptor.MessageTypes[0]; } 49 | } 50 | 51 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 52 | pbr::MessageDescriptor pb::IMessage.Descriptor { 53 | get { return Descriptor; } 54 | } 55 | 56 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 57 | public HelloReq() { 58 | OnConstruction(); 59 | } 60 | 61 | partial void OnConstruction(); 62 | 63 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 64 | public HelloReq(HelloReq other) : this() { 65 | name_ = other.name_; 66 | } 67 | 68 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 69 | public HelloReq Clone() { 70 | return new HelloReq(this); 71 | } 72 | 73 | /// Field number for the "Name" field. 74 | public const int NameFieldNumber = 1; 75 | private string name_ = ""; 76 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 77 | public string Name { 78 | get { return name_; } 79 | set { 80 | name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); 81 | } 82 | } 83 | 84 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 85 | public override bool Equals(object other) { 86 | return Equals(other as HelloReq); 87 | } 88 | 89 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 90 | public bool Equals(HelloReq other) { 91 | if (ReferenceEquals(other, null)) { 92 | return false; 93 | } 94 | if (ReferenceEquals(other, this)) { 95 | return true; 96 | } 97 | if (Name != other.Name) return false; 98 | return true; 99 | } 100 | 101 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 102 | public override int GetHashCode() { 103 | int hash = 1; 104 | if (Name.Length != 0) hash ^= Name.GetHashCode(); 105 | return hash; 106 | } 107 | 108 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 109 | public override string ToString() { 110 | return pb::JsonFormatter.ToDiagnosticString(this); 111 | } 112 | 113 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 114 | public void WriteTo(pb::CodedOutputStream output) { 115 | if (Name.Length != 0) { 116 | output.WriteRawTag(10); 117 | output.WriteString(Name); 118 | } 119 | } 120 | 121 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 122 | public int CalculateSize() { 123 | int size = 0; 124 | if (Name.Length != 0) { 125 | size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); 126 | } 127 | return size; 128 | } 129 | 130 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 131 | public void MergeFrom(HelloReq other) { 132 | if (other == null) { 133 | return; 134 | } 135 | if (other.Name.Length != 0) { 136 | Name = other.Name; 137 | } 138 | } 139 | 140 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 141 | public void MergeFrom(pb::CodedInputStream input) { 142 | uint tag; 143 | while ((tag = input.ReadTag()) != 0) { 144 | switch(tag) { 145 | default: 146 | input.SkipLastField(); 147 | break; 148 | case 10: { 149 | Name = input.ReadString(); 150 | break; 151 | } 152 | } 153 | } 154 | } 155 | 156 | } 157 | 158 | public sealed partial class HelloResp : pb::IMessage { 159 | private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new HelloResp()); 160 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 161 | public static pb::MessageParser Parser { get { return _parser; } } 162 | 163 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 164 | public static pbr::MessageDescriptor Descriptor { 165 | get { return global::Hello.HelloReflection.Descriptor.MessageTypes[1]; } 166 | } 167 | 168 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 169 | pbr::MessageDescriptor pb::IMessage.Descriptor { 170 | get { return Descriptor; } 171 | } 172 | 173 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 174 | public HelloResp() { 175 | OnConstruction(); 176 | } 177 | 178 | partial void OnConstruction(); 179 | 180 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 181 | public HelloResp(HelloResp other) : this() { 182 | result_ = other.result_; 183 | } 184 | 185 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 186 | public HelloResp Clone() { 187 | return new HelloResp(this); 188 | } 189 | 190 | /// Field number for the "Result" field. 191 | public const int ResultFieldNumber = 1; 192 | private string result_ = ""; 193 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 194 | public string Result { 195 | get { return result_; } 196 | set { 197 | result_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); 198 | } 199 | } 200 | 201 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 202 | public override bool Equals(object other) { 203 | return Equals(other as HelloResp); 204 | } 205 | 206 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 207 | public bool Equals(HelloResp other) { 208 | if (ReferenceEquals(other, null)) { 209 | return false; 210 | } 211 | if (ReferenceEquals(other, this)) { 212 | return true; 213 | } 214 | if (Result != other.Result) return false; 215 | return true; 216 | } 217 | 218 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 219 | public override int GetHashCode() { 220 | int hash = 1; 221 | if (Result.Length != 0) hash ^= Result.GetHashCode(); 222 | return hash; 223 | } 224 | 225 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 226 | public override string ToString() { 227 | return pb::JsonFormatter.ToDiagnosticString(this); 228 | } 229 | 230 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 231 | public void WriteTo(pb::CodedOutputStream output) { 232 | if (Result.Length != 0) { 233 | output.WriteRawTag(10); 234 | output.WriteString(Result); 235 | } 236 | } 237 | 238 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 239 | public int CalculateSize() { 240 | int size = 0; 241 | if (Result.Length != 0) { 242 | size += 1 + pb::CodedOutputStream.ComputeStringSize(Result); 243 | } 244 | return size; 245 | } 246 | 247 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 248 | public void MergeFrom(HelloResp other) { 249 | if (other == null) { 250 | return; 251 | } 252 | if (other.Result.Length != 0) { 253 | Result = other.Result; 254 | } 255 | } 256 | 257 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute] 258 | public void MergeFrom(pb::CodedInputStream input) { 259 | uint tag; 260 | while ((tag = input.ReadTag()) != 0) { 261 | switch(tag) { 262 | default: 263 | input.SkipLastField(); 264 | break; 265 | case 10: { 266 | Result = input.ReadString(); 267 | break; 268 | } 269 | } 270 | } 271 | } 272 | 273 | } 274 | 275 | #endregion 276 | 277 | } 278 | 279 | #endregion Designer generated code 280 | -------------------------------------------------------------------------------- /csharp/Hello/Hello/Hello.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | x86 6 | {1C6E2002-B032-4822-A725-3032FDAFD2B5} 7 | Library 8 | Hello 9 | Hello 10 | v4.5 11 | 12 | 13 | true 14 | full 15 | false 16 | bin\Debug 17 | DEBUG; 18 | prompt 19 | 4 20 | true 21 | x86 22 | 23 | 24 | true 25 | bin\Release 26 | prompt 27 | 4 28 | true 29 | x86 30 | 31 | 32 | 33 | 34 | ..\packages\Google.Protobuf.3.0.0\lib\net45\Google.Protobuf.dll 35 | 36 | 37 | ..\packages\Grpc.Core.1.0.1\lib\net45\Grpc.Core.dll 38 | 39 | 40 | ..\packages\System.Interactive.Async.3.0.0\lib\net45\System.Interactive.Async.dll 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /csharp/Hello/Hello/HelloGrpc.cs: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: hello.proto 3 | #region Designer generated code 4 | 5 | using System; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | using grpc = global::Grpc.Core; 9 | 10 | namespace Hello { 11 | public static partial class HelloService 12 | { 13 | static readonly string __ServiceName = "hello.HelloService"; 14 | 15 | static readonly grpc::Marshaller __Marshaller_HelloReq = grpc::Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Hello.HelloReq.Parser.ParseFrom); 16 | static readonly grpc::Marshaller __Marshaller_HelloResp = grpc::Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Hello.HelloResp.Parser.ParseFrom); 17 | 18 | static readonly grpc::Method __Method_SayHello = new grpc::Method( 19 | grpc::MethodType.Unary, 20 | __ServiceName, 21 | "SayHello", 22 | __Marshaller_HelloReq, 23 | __Marshaller_HelloResp); 24 | 25 | static readonly grpc::Method __Method_SayHelloStrict = new grpc::Method( 26 | grpc::MethodType.Unary, 27 | __ServiceName, 28 | "SayHelloStrict", 29 | __Marshaller_HelloReq, 30 | __Marshaller_HelloResp); 31 | 32 | /// Service descriptor 33 | public static global::Google.Protobuf.Reflection.ServiceDescriptor Descriptor 34 | { 35 | get { return global::Hello.HelloReflection.Descriptor.Services[0]; } 36 | } 37 | 38 | /// Base class for server-side implementations of HelloService 39 | public abstract partial class HelloServiceBase 40 | { 41 | /// 42 | /// This thing just says Hello to anyone 43 | /// SayHello('Euler') -> Hello, Euler! 44 | /// 45 | /// The request received from the client. 46 | /// The context of the server-side call handler being invoked. 47 | /// The response to send back to the client (wrapped by a task). 48 | public virtual global::System.Threading.Tasks.Task SayHello(global::Hello.HelloReq request, grpc::ServerCallContext context) 49 | { 50 | throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, "")); 51 | } 52 | 53 | /// 54 | /// Strict Version responds only to requests which have `Name` length 55 | /// less than 10 characters 56 | /// 57 | /// The request received from the client. 58 | /// The context of the server-side call handler being invoked. 59 | /// The response to send back to the client (wrapped by a task). 60 | public virtual global::System.Threading.Tasks.Task SayHelloStrict(global::Hello.HelloReq request, grpc::ServerCallContext context) 61 | { 62 | throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, "")); 63 | } 64 | 65 | } 66 | 67 | /// Client for HelloService 68 | public partial class HelloServiceClient : grpc::ClientBase 69 | { 70 | /// Creates a new client for HelloService 71 | /// The channel to use to make remote calls. 72 | public HelloServiceClient(grpc::Channel channel) : base(channel) 73 | { 74 | } 75 | /// Creates a new client for HelloService that uses a custom CallInvoker. 76 | /// The callInvoker to use to make remote calls. 77 | public HelloServiceClient(grpc::CallInvoker callInvoker) : base(callInvoker) 78 | { 79 | } 80 | /// Protected parameterless constructor to allow creation of test doubles. 81 | protected HelloServiceClient() : base() 82 | { 83 | } 84 | /// Protected constructor to allow creation of configured clients. 85 | /// The client configuration. 86 | protected HelloServiceClient(ClientBaseConfiguration configuration) : base(configuration) 87 | { 88 | } 89 | 90 | /// 91 | /// This thing just says Hello to anyone 92 | /// SayHello('Euler') -> Hello, Euler! 93 | /// 94 | /// The request to send to the server. 95 | /// The initial metadata to send with the call. This parameter is optional. 96 | /// An optional deadline for the call. The call will be cancelled if deadline is hit. 97 | /// An optional token for canceling the call. 98 | /// The response received from the server. 99 | public virtual global::Hello.HelloResp SayHello(global::Hello.HelloReq request, grpc::Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)) 100 | { 101 | return SayHello(request, new grpc::CallOptions(headers, deadline, cancellationToken)); 102 | } 103 | /// 104 | /// This thing just says Hello to anyone 105 | /// SayHello('Euler') -> Hello, Euler! 106 | /// 107 | /// The request to send to the server. 108 | /// The options for the call. 109 | /// The response received from the server. 110 | public virtual global::Hello.HelloResp SayHello(global::Hello.HelloReq request, grpc::CallOptions options) 111 | { 112 | return CallInvoker.BlockingUnaryCall(__Method_SayHello, null, options, request); 113 | } 114 | /// 115 | /// This thing just says Hello to anyone 116 | /// SayHello('Euler') -> Hello, Euler! 117 | /// 118 | /// The request to send to the server. 119 | /// The initial metadata to send with the call. This parameter is optional. 120 | /// An optional deadline for the call. The call will be cancelled if deadline is hit. 121 | /// An optional token for canceling the call. 122 | /// The call object. 123 | public virtual grpc::AsyncUnaryCall SayHelloAsync(global::Hello.HelloReq request, grpc::Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)) 124 | { 125 | return SayHelloAsync(request, new grpc::CallOptions(headers, deadline, cancellationToken)); 126 | } 127 | /// 128 | /// This thing just says Hello to anyone 129 | /// SayHello('Euler') -> Hello, Euler! 130 | /// 131 | /// The request to send to the server. 132 | /// The options for the call. 133 | /// The call object. 134 | public virtual grpc::AsyncUnaryCall SayHelloAsync(global::Hello.HelloReq request, grpc::CallOptions options) 135 | { 136 | return CallInvoker.AsyncUnaryCall(__Method_SayHello, null, options, request); 137 | } 138 | /// 139 | /// Strict Version responds only to requests which have `Name` length 140 | /// less than 10 characters 141 | /// 142 | /// The request to send to the server. 143 | /// The initial metadata to send with the call. This parameter is optional. 144 | /// An optional deadline for the call. The call will be cancelled if deadline is hit. 145 | /// An optional token for canceling the call. 146 | /// The response received from the server. 147 | public virtual global::Hello.HelloResp SayHelloStrict(global::Hello.HelloReq request, grpc::Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)) 148 | { 149 | return SayHelloStrict(request, new grpc::CallOptions(headers, deadline, cancellationToken)); 150 | } 151 | /// 152 | /// Strict Version responds only to requests which have `Name` length 153 | /// less than 10 characters 154 | /// 155 | /// The request to send to the server. 156 | /// The options for the call. 157 | /// The response received from the server. 158 | public virtual global::Hello.HelloResp SayHelloStrict(global::Hello.HelloReq request, grpc::CallOptions options) 159 | { 160 | return CallInvoker.BlockingUnaryCall(__Method_SayHelloStrict, null, options, request); 161 | } 162 | /// 163 | /// Strict Version responds only to requests which have `Name` length 164 | /// less than 10 characters 165 | /// 166 | /// The request to send to the server. 167 | /// The initial metadata to send with the call. This parameter is optional. 168 | /// An optional deadline for the call. The call will be cancelled if deadline is hit. 169 | /// An optional token for canceling the call. 170 | /// The call object. 171 | public virtual grpc::AsyncUnaryCall SayHelloStrictAsync(global::Hello.HelloReq request, grpc::Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)) 172 | { 173 | return SayHelloStrictAsync(request, new grpc::CallOptions(headers, deadline, cancellationToken)); 174 | } 175 | /// 176 | /// Strict Version responds only to requests which have `Name` length 177 | /// less than 10 characters 178 | /// 179 | /// The request to send to the server. 180 | /// The options for the call. 181 | /// The call object. 182 | public virtual grpc::AsyncUnaryCall SayHelloStrictAsync(global::Hello.HelloReq request, grpc::CallOptions options) 183 | { 184 | return CallInvoker.AsyncUnaryCall(__Method_SayHelloStrict, null, options, request); 185 | } 186 | /// Creates a new instance of client from given ClientBaseConfiguration. 187 | protected override HelloServiceClient NewInstance(ClientBaseConfiguration configuration) 188 | { 189 | return new HelloServiceClient(configuration); 190 | } 191 | } 192 | 193 | /// Creates service definition that can be registered with a server 194 | /// An object implementing the server-side handling logic. 195 | public static grpc::ServerServiceDefinition BindService(HelloServiceBase serviceImpl) 196 | { 197 | return grpc::ServerServiceDefinition.CreateBuilder() 198 | .AddMethod(__Method_SayHello, serviceImpl.SayHello) 199 | .AddMethod(__Method_SayHelloStrict, serviceImpl.SayHelloStrict).Build(); 200 | } 201 | 202 | } 203 | } 204 | #endregion 205 | -------------------------------------------------------------------------------- /csharp/Hello/Hello/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | // Information about this assembly is defined by the following attributes. 5 | // Change them to the values specific to your project. 6 | 7 | [assembly: AssemblyTitle("Hello")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("")] 12 | [assembly: AssemblyCopyright("${AuthorCopyright}")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". 17 | // The form "{Major}.{Minor}.*" will automatically update the build and revision, 18 | // and "{Major}.{Minor}.{Build}.*" will update just the revision. 19 | 20 | [assembly: AssemblyVersion("1.0.*")] 21 | 22 | // The following attributes are used to specify the signing key for the assembly, 23 | // if desired. See the Mono documentation for more information about signing. 24 | 25 | //[assembly: AssemblyDelaySign(false)] 26 | //[assembly: AssemblyKeyFile("")] 27 | -------------------------------------------------------------------------------- /csharp/Hello/Hello/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /csharp/Hello/HelloClient/HelloClient.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | x86 6 | {39345BFB-E318-437D-8846-BB1056A2062E} 7 | Exe 8 | HelloClient 9 | HelloClient 10 | v4.5 11 | 12 | 13 | true 14 | full 15 | false 16 | bin\Debug 17 | DEBUG; 18 | prompt 19 | 4 20 | true 21 | x86 22 | 23 | 24 | true 25 | bin\Release 26 | prompt 27 | 4 28 | true 29 | x86 30 | 31 | 32 | 33 | 34 | ..\packages\Google.Protobuf.3.0.0\lib\net45\Google.Protobuf.dll 35 | 36 | 37 | ..\packages\Grpc.Core.1.0.1\lib\net45\Grpc.Core.dll 38 | 39 | 40 | ..\packages\System.Interactive.Async.3.0.0\lib\net45\System.Interactive.Async.dll 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | {1C6E2002-B032-4822-A725-3032FDAFD2B5} 50 | Hello 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /csharp/Hello/HelloClient/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Grpc.Core; 3 | using Hello; 4 | 5 | namespace HelloClient 6 | { 7 | class Program 8 | { 9 | public static void Main(string[] args) 10 | { 11 | Channel channel = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure); 12 | 13 | var client = new HelloService.HelloServiceClient(channel); 14 | // ideally you should check for errors here too 15 | var reply = client.SayHello(new HelloReq { Name = "Euler" }); 16 | Console.WriteLine(reply.Result); 17 | 18 | try 19 | { 20 | reply = client.SayHelloStrict(new HelloReq { Name = "Leonhard Euler" }); 21 | Console.WriteLine(reply.Result); 22 | } 23 | catch (RpcException e) 24 | { 25 | // ouch! 26 | // lets print the gRPC error message 27 | // which is "Length of `Name` cannot be more than 10 characters" 28 | Console.WriteLine(e.Status.Detail); 29 | // lets access the error code, which is `INVALID_ARGUMENT` 30 | Console.WriteLine(e.Status.StatusCode); 31 | // Want its int version for some reason? 32 | // you shouldn't actually do this, but if you need for debugging, 33 | // you can access `e.Status.StatusCode` which will give you `3` 34 | Console.WriteLine((int)e.Status.StatusCode); 35 | // Want to take specific action based on specific error? 36 | if (e.Status.StatusCode == Grpc.Core.StatusCode.InvalidArgument) { 37 | // do your thing 38 | } 39 | } 40 | 41 | channel.ShutdownAsync().Wait(); 42 | Console.WriteLine("Press any key to exit..."); 43 | Console.ReadKey(); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /csharp/Hello/HelloClient/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | // Information about this assembly is defined by the following attributes. 5 | // Change them to the values specific to your project. 6 | 7 | [assembly: AssemblyTitle("HelloClient")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("")] 12 | [assembly: AssemblyCopyright("${AuthorCopyright}")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". 17 | // The form "{Major}.{Minor}.*" will automatically update the build and revision, 18 | // and "{Major}.{Minor}.{Build}.*" will update just the revision. 19 | 20 | [assembly: AssemblyVersion("1.0.*")] 21 | 22 | // The following attributes are used to specify the signing key for the assembly, 23 | // if desired. See the Mono documentation for more information about signing. 24 | 25 | //[assembly: AssemblyDelaySign(false)] 26 | //[assembly: AssemblyKeyFile("")] 27 | -------------------------------------------------------------------------------- /csharp/Hello/HelloClient/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /csharp/Hello/HelloServer/HelloServer.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | x86 6 | {DE5DD14D-31E3-4847-9B6C-76F0338CE3CD} 7 | Exe 8 | HelloServer 9 | HelloServer 10 | v4.5 11 | 12 | 13 | true 14 | full 15 | false 16 | bin\Debug 17 | DEBUG; 18 | prompt 19 | 4 20 | true 21 | x86 22 | 23 | 24 | true 25 | bin\Release 26 | prompt 27 | 4 28 | true 29 | x86 30 | 31 | 32 | 33 | 34 | ..\packages\Google.Protobuf.3.0.0\lib\net45\Google.Protobuf.dll 35 | 36 | 37 | ..\packages\Grpc.Core.1.0.1\lib\net45\Grpc.Core.dll 38 | 39 | 40 | ..\packages\System.Interactive.Async.3.0.0\lib\net45\System.Interactive.Async.dll 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | {1C6E2002-B032-4822-A725-3032FDAFD2B5} 50 | Hello 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /csharp/Hello/HelloServer/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using Grpc.Core; 4 | using Hello; 5 | 6 | namespace HelloServer 7 | { 8 | class HelloServerImpl : HelloService.HelloServiceBase 9 | { 10 | public override Task SayHello(HelloReq request, ServerCallContext context) 11 | { 12 | return Task.FromResult(new HelloResp { Result = "Hey, " + request.Name + "!"}); 13 | } 14 | 15 | public override Task SayHelloStrict(HelloReq request, ServerCallContext context) 16 | { 17 | if (request.Name.Length >= 10) { 18 | const string msg = "Length of `Name` cannot be more than 10 characters"; 19 | throw new RpcException(new Status(StatusCode.InvalidArgument, msg)); 20 | } 21 | return Task.FromResult(new HelloResp { Result = "Hey, " + request.Name + "!"}); 22 | } 23 | } 24 | 25 | class Program 26 | { 27 | const int Port = 50051; 28 | 29 | public static void Main(string[] args) 30 | { 31 | 32 | Server server = new Server 33 | { 34 | Services = { HelloService.BindService(new HelloServerImpl()) }, 35 | Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) } 36 | }; 37 | 38 | server.Start(); 39 | 40 | Console.WriteLine("Hello server listening on port " + Port); 41 | Console.WriteLine("Press any key to stop the server..."); 42 | Console.ReadKey(); 43 | 44 | server.ShutdownAsync().Wait(); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /csharp/Hello/HelloServer/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | // Information about this assembly is defined by the following attributes. 5 | // Change them to the values specific to your project. 6 | 7 | [assembly: AssemblyTitle("HelloServer")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("")] 12 | [assembly: AssemblyCopyright("${AuthorCopyright}")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". 17 | // The form "{Major}.{Minor}.*" will automatically update the build and revision, 18 | // and "{Major}.{Minor}.{Build}.*" will update just the revision. 19 | 20 | [assembly: AssemblyVersion("1.0.*")] 21 | 22 | // The following attributes are used to specify the signing key for the assembly, 23 | // if desired. See the Mono documentation for more information about signing. 24 | 25 | //[assembly: AssemblyDelaySign(false)] 26 | //[assembly: AssemblyKeyFile("")] 27 | -------------------------------------------------------------------------------- /csharp/Hello/HelloServer/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /csharp/README.md: -------------------------------------------------------------------------------- 1 | # C# gRPC 2 | 3 | ## Instructions 4 | 5 | C# examples use Xamarin studio. To generate protobuf files: 6 | 7 | $ protoc --plugin=protoc-gen-grpc=`which grpc_csharp_plugin` -I=../ --csharp_out Hello/Hello --grpc_out Hello/Hello ../hello.proto 8 | 9 | ## To run 10 | 11 | 1. Open the solution `Hello.sln` with Xamarin Studio. 12 | 2. Install the dependencies: `Project` -> `Restore NuGet Packages` 13 | 3. Build the solution 14 | 4. Run server and client -------------------------------------------------------------------------------- /go/README.md: -------------------------------------------------------------------------------- 1 | # Go gRPC 2 | 3 | ## Instructions 4 | 5 | Generate protobuf files: 6 | 7 | $ protoc -I ../ ../hello.proto --go_out=hello --go_opt=module=github.com/avinassh/grpc-errors/go/hello 8 | $ protoc -I ../ ../hello.proto --go-grpc_out=hello --go-grpc_opt=module=github.com/avinassh/grpc-errors/go/hello 9 | 10 | Build server and client, and run: 11 | 12 | $ go build server.go 13 | $ go build client.go 14 | $ ./server & 15 | $ ./client -------------------------------------------------------------------------------- /go/client.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | 7 | "golang.org/x/net/context" 8 | "google.golang.org/grpc" 9 | "google.golang.org/grpc/codes" 10 | "google.golang.org/grpc/status" 11 | 12 | api "github.com/avinassh/grpc-errors/go/hello" 13 | ) 14 | 15 | func main() { 16 | conn, err := grpc.Dial("localhost:50051", grpc.WithInsecure()) 17 | if err != nil { 18 | log.Fatalf("Did not connect: %v", err) 19 | } 20 | defer conn.Close() 21 | c := api.NewHelloServiceClient(conn) 22 | 23 | // ideally, you should handle error here too, for brevity 24 | // I am ignoring that 25 | resp, _ := c.SayHello( 26 | context.Background(), 27 | &api.HelloReq{Name: "Euler"}, 28 | ) 29 | fmt.Println(resp.GetResult()) 30 | 31 | resp, err = c.SayHelloStrict( 32 | context.Background(), 33 | &api.HelloReq{Name: "Leonhard Euler"}, 34 | ) 35 | 36 | if err != nil { 37 | // ouch! 38 | // lets print the gRPC error message 39 | // which is "Length of `Name` cannot be more than 10 characters" 40 | errStatus, _ := status.FromError(err) 41 | fmt.Println(errStatus.Message()) 42 | // lets print the error code which is `INVALID_ARGUMENT` 43 | fmt.Println(errStatus.Code()) 44 | // Want its int version for some reason? 45 | // you shouldn't actullay do this, but if you need for debugging, 46 | // you can do `int(status_code)` which will give you `3` 47 | // 48 | // Want to take specific action based on specific error? 49 | if codes.InvalidArgument == errStatus.Code() { 50 | // do your stuff here 51 | log.Fatal() 52 | } 53 | } 54 | 55 | fmt.Println(resp.GetResult()) 56 | } 57 | -------------------------------------------------------------------------------- /go/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/avinassh/grpc-errors/go 2 | 3 | go 1.17 4 | 5 | require ( 6 | github.com/golang/protobuf v1.5.2 7 | golang.org/x/net v0.0.0-20211116231205-47ca1ff31462 8 | google.golang.org/grpc v1.42.0 9 | ) 10 | 11 | require ( 12 | golang.org/x/sys v0.0.0-20210423082822-04245dca01da // indirect 13 | golang.org/x/text v0.3.6 // indirect 14 | google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect 15 | google.golang.org/protobuf v1.26.0 // indirect 16 | ) 17 | -------------------------------------------------------------------------------- /go/go.sum: -------------------------------------------------------------------------------- 1 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 2 | cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 3 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 4 | github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= 5 | github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= 6 | github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= 7 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= 8 | github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= 9 | github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= 10 | github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI= 11 | github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= 12 | github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= 13 | github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= 14 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 15 | github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= 16 | github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= 17 | github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= 18 | github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= 19 | github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0= 20 | github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= 21 | github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= 22 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= 23 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 24 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 25 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 26 | github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= 27 | github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= 28 | github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= 29 | github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= 30 | github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= 31 | github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= 32 | github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= 33 | github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= 34 | github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= 35 | github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= 36 | github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= 37 | github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= 38 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= 39 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 40 | github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 41 | github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 42 | github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 43 | github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= 44 | github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 45 | github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 46 | github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= 47 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 48 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 49 | github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= 50 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 51 | github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= 52 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 53 | go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= 54 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 55 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 56 | golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 57 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 58 | golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= 59 | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 60 | golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 61 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 62 | golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 63 | golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 64 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 65 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 66 | golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= 67 | golang.org/x/net v0.0.0-20211116231205-47ca1ff31462 h1:2vmJlzGKvQ7e/X9XT0XydeWDxmqx8DnegiIMRT+5ssI= 68 | golang.org/x/net v0.0.0-20211116231205-47ca1ff31462/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= 69 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= 70 | golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 71 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 72 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 73 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 74 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 75 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 76 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 77 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 78 | golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 79 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 80 | golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c= 81 | golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 82 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 83 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 84 | golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= 85 | golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 86 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 87 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 88 | golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= 89 | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 90 | golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 91 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 92 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= 93 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 94 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= 95 | google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 96 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= 97 | google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= 98 | google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= 99 | google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= 100 | google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= 101 | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= 102 | google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= 103 | google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= 104 | google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= 105 | google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= 106 | google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= 107 | google.golang.org/grpc v1.42.0 h1:XT2/MFpuPFsEX2fWh3YQtHkZ+WYZFQRfaUgLZYj/p6A= 108 | google.golang.org/grpc v1.42.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= 109 | google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= 110 | google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= 111 | google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= 112 | google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= 113 | google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= 114 | google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= 115 | google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= 116 | google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= 117 | google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= 118 | google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= 119 | google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= 120 | google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= 121 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 122 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 123 | gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 124 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 125 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 126 | honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 127 | -------------------------------------------------------------------------------- /go/hello/hello.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // versions: 3 | // protoc-gen-go v1.26.0 4 | // protoc v3.17.3 5 | // source: hello.proto 6 | 7 | // for Golang 8 | 9 | package hello 10 | 11 | import ( 12 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 13 | protoimpl "google.golang.org/protobuf/runtime/protoimpl" 14 | reflect "reflect" 15 | sync "sync" 16 | ) 17 | 18 | const ( 19 | // Verify that this generated code is sufficiently up-to-date. 20 | _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) 21 | // Verify that runtime/protoimpl is sufficiently up-to-date. 22 | _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) 23 | ) 24 | 25 | type HelloReq struct { 26 | state protoimpl.MessageState 27 | sizeCache protoimpl.SizeCache 28 | unknownFields protoimpl.UnknownFields 29 | 30 | Name string `protobuf:"bytes,1,opt,name=Name,proto3" json:"Name,omitempty"` 31 | } 32 | 33 | func (x *HelloReq) Reset() { 34 | *x = HelloReq{} 35 | if protoimpl.UnsafeEnabled { 36 | mi := &file_hello_proto_msgTypes[0] 37 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 38 | ms.StoreMessageInfo(mi) 39 | } 40 | } 41 | 42 | func (x *HelloReq) String() string { 43 | return protoimpl.X.MessageStringOf(x) 44 | } 45 | 46 | func (*HelloReq) ProtoMessage() {} 47 | 48 | func (x *HelloReq) ProtoReflect() protoreflect.Message { 49 | mi := &file_hello_proto_msgTypes[0] 50 | if protoimpl.UnsafeEnabled && x != nil { 51 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 52 | if ms.LoadMessageInfo() == nil { 53 | ms.StoreMessageInfo(mi) 54 | } 55 | return ms 56 | } 57 | return mi.MessageOf(x) 58 | } 59 | 60 | // Deprecated: Use HelloReq.ProtoReflect.Descriptor instead. 61 | func (*HelloReq) Descriptor() ([]byte, []int) { 62 | return file_hello_proto_rawDescGZIP(), []int{0} 63 | } 64 | 65 | func (x *HelloReq) GetName() string { 66 | if x != nil { 67 | return x.Name 68 | } 69 | return "" 70 | } 71 | 72 | type HelloResp struct { 73 | state protoimpl.MessageState 74 | sizeCache protoimpl.SizeCache 75 | unknownFields protoimpl.UnknownFields 76 | 77 | Result string `protobuf:"bytes,1,opt,name=Result,proto3" json:"Result,omitempty"` 78 | } 79 | 80 | func (x *HelloResp) Reset() { 81 | *x = HelloResp{} 82 | if protoimpl.UnsafeEnabled { 83 | mi := &file_hello_proto_msgTypes[1] 84 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 85 | ms.StoreMessageInfo(mi) 86 | } 87 | } 88 | 89 | func (x *HelloResp) String() string { 90 | return protoimpl.X.MessageStringOf(x) 91 | } 92 | 93 | func (*HelloResp) ProtoMessage() {} 94 | 95 | func (x *HelloResp) ProtoReflect() protoreflect.Message { 96 | mi := &file_hello_proto_msgTypes[1] 97 | if protoimpl.UnsafeEnabled && x != nil { 98 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 99 | if ms.LoadMessageInfo() == nil { 100 | ms.StoreMessageInfo(mi) 101 | } 102 | return ms 103 | } 104 | return mi.MessageOf(x) 105 | } 106 | 107 | // Deprecated: Use HelloResp.ProtoReflect.Descriptor instead. 108 | func (*HelloResp) Descriptor() ([]byte, []int) { 109 | return file_hello_proto_rawDescGZIP(), []int{1} 110 | } 111 | 112 | func (x *HelloResp) GetResult() string { 113 | if x != nil { 114 | return x.Result 115 | } 116 | return "" 117 | } 118 | 119 | var File_hello_proto protoreflect.FileDescriptor 120 | 121 | var file_hello_proto_rawDesc = []byte{ 122 | 0x0a, 0x0b, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x68, 123 | 0x65, 0x6c, 0x6c, 0x6f, 0x22, 0x1e, 0x0a, 0x08, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 124 | 0x12, 0x12, 0x0a, 0x04, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 125 | 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x23, 0x0a, 0x09, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x73, 126 | 0x70, 0x12, 0x16, 0x0a, 0x06, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 127 | 0x09, 0x52, 0x06, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x32, 0x76, 0x0a, 0x0c, 0x48, 0x65, 0x6c, 128 | 0x6c, 0x6f, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x2f, 0x0a, 0x08, 0x53, 0x61, 0x79, 129 | 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x12, 0x0f, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x48, 0x65, 130 | 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x1a, 0x10, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x48, 131 | 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x35, 0x0a, 0x0e, 0x53, 0x61, 132 | 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x53, 0x74, 0x72, 0x69, 0x63, 0x74, 0x12, 0x0f, 0x2e, 0x68, 133 | 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x1a, 0x10, 0x2e, 134 | 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x22, 135 | 0x00, 0x42, 0x2a, 0x5a, 0x28, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 136 | 0x61, 0x76, 0x69, 0x6e, 0x61, 0x73, 0x73, 0x68, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2d, 0x65, 0x72, 137 | 0x72, 0x6f, 0x72, 0x73, 0x2f, 0x67, 0x6f, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x62, 0x06, 0x70, 138 | 0x72, 0x6f, 0x74, 0x6f, 0x33, 139 | } 140 | 141 | var ( 142 | file_hello_proto_rawDescOnce sync.Once 143 | file_hello_proto_rawDescData = file_hello_proto_rawDesc 144 | ) 145 | 146 | func file_hello_proto_rawDescGZIP() []byte { 147 | file_hello_proto_rawDescOnce.Do(func() { 148 | file_hello_proto_rawDescData = protoimpl.X.CompressGZIP(file_hello_proto_rawDescData) 149 | }) 150 | return file_hello_proto_rawDescData 151 | } 152 | 153 | var file_hello_proto_msgTypes = make([]protoimpl.MessageInfo, 2) 154 | var file_hello_proto_goTypes = []interface{}{ 155 | (*HelloReq)(nil), // 0: hello.HelloReq 156 | (*HelloResp)(nil), // 1: hello.HelloResp 157 | } 158 | var file_hello_proto_depIdxs = []int32{ 159 | 0, // 0: hello.HelloService.SayHello:input_type -> hello.HelloReq 160 | 0, // 1: hello.HelloService.SayHelloStrict:input_type -> hello.HelloReq 161 | 1, // 2: hello.HelloService.SayHello:output_type -> hello.HelloResp 162 | 1, // 3: hello.HelloService.SayHelloStrict:output_type -> hello.HelloResp 163 | 2, // [2:4] is the sub-list for method output_type 164 | 0, // [0:2] is the sub-list for method input_type 165 | 0, // [0:0] is the sub-list for extension type_name 166 | 0, // [0:0] is the sub-list for extension extendee 167 | 0, // [0:0] is the sub-list for field type_name 168 | } 169 | 170 | func init() { file_hello_proto_init() } 171 | func file_hello_proto_init() { 172 | if File_hello_proto != nil { 173 | return 174 | } 175 | if !protoimpl.UnsafeEnabled { 176 | file_hello_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { 177 | switch v := v.(*HelloReq); i { 178 | case 0: 179 | return &v.state 180 | case 1: 181 | return &v.sizeCache 182 | case 2: 183 | return &v.unknownFields 184 | default: 185 | return nil 186 | } 187 | } 188 | file_hello_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { 189 | switch v := v.(*HelloResp); i { 190 | case 0: 191 | return &v.state 192 | case 1: 193 | return &v.sizeCache 194 | case 2: 195 | return &v.unknownFields 196 | default: 197 | return nil 198 | } 199 | } 200 | } 201 | type x struct{} 202 | out := protoimpl.TypeBuilder{ 203 | File: protoimpl.DescBuilder{ 204 | GoPackagePath: reflect.TypeOf(x{}).PkgPath(), 205 | RawDescriptor: file_hello_proto_rawDesc, 206 | NumEnums: 0, 207 | NumMessages: 2, 208 | NumExtensions: 0, 209 | NumServices: 1, 210 | }, 211 | GoTypes: file_hello_proto_goTypes, 212 | DependencyIndexes: file_hello_proto_depIdxs, 213 | MessageInfos: file_hello_proto_msgTypes, 214 | }.Build() 215 | File_hello_proto = out.File 216 | file_hello_proto_rawDesc = nil 217 | file_hello_proto_goTypes = nil 218 | file_hello_proto_depIdxs = nil 219 | } 220 | -------------------------------------------------------------------------------- /go/hello/hello_grpc.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go-grpc. DO NOT EDIT. 2 | 3 | package hello 4 | 5 | import ( 6 | context "context" 7 | grpc "google.golang.org/grpc" 8 | codes "google.golang.org/grpc/codes" 9 | status "google.golang.org/grpc/status" 10 | ) 11 | 12 | // This is a compile-time assertion to ensure that this generated file 13 | // is compatible with the grpc package it is being compiled against. 14 | // Requires gRPC-Go v1.32.0 or later. 15 | const _ = grpc.SupportPackageIsVersion7 16 | 17 | // HelloServiceClient is the client API for HelloService service. 18 | // 19 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. 20 | type HelloServiceClient interface { 21 | // This thing just says Hello to anyone 22 | // SayHello('Euler') -> Hello, Euler! 23 | SayHello(ctx context.Context, in *HelloReq, opts ...grpc.CallOption) (*HelloResp, error) 24 | // Strict Version responds only to requests which have `Name` length 25 | // less than 10 characters 26 | SayHelloStrict(ctx context.Context, in *HelloReq, opts ...grpc.CallOption) (*HelloResp, error) 27 | } 28 | 29 | type helloServiceClient struct { 30 | cc grpc.ClientConnInterface 31 | } 32 | 33 | func NewHelloServiceClient(cc grpc.ClientConnInterface) HelloServiceClient { 34 | return &helloServiceClient{cc} 35 | } 36 | 37 | func (c *helloServiceClient) SayHello(ctx context.Context, in *HelloReq, opts ...grpc.CallOption) (*HelloResp, error) { 38 | out := new(HelloResp) 39 | err := c.cc.Invoke(ctx, "/hello.HelloService/SayHello", in, out, opts...) 40 | if err != nil { 41 | return nil, err 42 | } 43 | return out, nil 44 | } 45 | 46 | func (c *helloServiceClient) SayHelloStrict(ctx context.Context, in *HelloReq, opts ...grpc.CallOption) (*HelloResp, error) { 47 | out := new(HelloResp) 48 | err := c.cc.Invoke(ctx, "/hello.HelloService/SayHelloStrict", in, out, opts...) 49 | if err != nil { 50 | return nil, err 51 | } 52 | return out, nil 53 | } 54 | 55 | // HelloServiceServer is the server API for HelloService service. 56 | // All implementations must embed UnimplementedHelloServiceServer 57 | // for forward compatibility 58 | type HelloServiceServer interface { 59 | // This thing just says Hello to anyone 60 | // SayHello('Euler') -> Hello, Euler! 61 | SayHello(context.Context, *HelloReq) (*HelloResp, error) 62 | // Strict Version responds only to requests which have `Name` length 63 | // less than 10 characters 64 | SayHelloStrict(context.Context, *HelloReq) (*HelloResp, error) 65 | mustEmbedUnimplementedHelloServiceServer() 66 | } 67 | 68 | // UnimplementedHelloServiceServer must be embedded to have forward compatible implementations. 69 | type UnimplementedHelloServiceServer struct { 70 | } 71 | 72 | func (UnimplementedHelloServiceServer) SayHello(context.Context, *HelloReq) (*HelloResp, error) { 73 | return nil, status.Errorf(codes.Unimplemented, "method SayHello not implemented") 74 | } 75 | func (UnimplementedHelloServiceServer) SayHelloStrict(context.Context, *HelloReq) (*HelloResp, error) { 76 | return nil, status.Errorf(codes.Unimplemented, "method SayHelloStrict not implemented") 77 | } 78 | func (UnimplementedHelloServiceServer) mustEmbedUnimplementedHelloServiceServer() {} 79 | 80 | // UnsafeHelloServiceServer may be embedded to opt out of forward compatibility for this service. 81 | // Use of this interface is not recommended, as added methods to HelloServiceServer will 82 | // result in compilation errors. 83 | type UnsafeHelloServiceServer interface { 84 | mustEmbedUnimplementedHelloServiceServer() 85 | } 86 | 87 | func RegisterHelloServiceServer(s grpc.ServiceRegistrar, srv HelloServiceServer) { 88 | s.RegisterService(&HelloService_ServiceDesc, srv) 89 | } 90 | 91 | func _HelloService_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 92 | in := new(HelloReq) 93 | if err := dec(in); err != nil { 94 | return nil, err 95 | } 96 | if interceptor == nil { 97 | return srv.(HelloServiceServer).SayHello(ctx, in) 98 | } 99 | info := &grpc.UnaryServerInfo{ 100 | Server: srv, 101 | FullMethod: "/hello.HelloService/SayHello", 102 | } 103 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 104 | return srv.(HelloServiceServer).SayHello(ctx, req.(*HelloReq)) 105 | } 106 | return interceptor(ctx, in, info, handler) 107 | } 108 | 109 | func _HelloService_SayHelloStrict_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 110 | in := new(HelloReq) 111 | if err := dec(in); err != nil { 112 | return nil, err 113 | } 114 | if interceptor == nil { 115 | return srv.(HelloServiceServer).SayHelloStrict(ctx, in) 116 | } 117 | info := &grpc.UnaryServerInfo{ 118 | Server: srv, 119 | FullMethod: "/hello.HelloService/SayHelloStrict", 120 | } 121 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 122 | return srv.(HelloServiceServer).SayHelloStrict(ctx, req.(*HelloReq)) 123 | } 124 | return interceptor(ctx, in, info, handler) 125 | } 126 | 127 | // HelloService_ServiceDesc is the grpc.ServiceDesc for HelloService service. 128 | // It's only intended for direct use with grpc.RegisterService, 129 | // and not to be introspected or modified (even as a copy) 130 | var HelloService_ServiceDesc = grpc.ServiceDesc{ 131 | ServiceName: "hello.HelloService", 132 | HandlerType: (*HelloServiceServer)(nil), 133 | Methods: []grpc.MethodDesc{ 134 | { 135 | MethodName: "SayHello", 136 | Handler: _HelloService_SayHello_Handler, 137 | }, 138 | { 139 | MethodName: "SayHelloStrict", 140 | Handler: _HelloService_SayHelloStrict_Handler, 141 | }, 142 | }, 143 | Streams: []grpc.StreamDesc{}, 144 | Metadata: "hello.proto", 145 | } 146 | -------------------------------------------------------------------------------- /go/server.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "net" 7 | 8 | "golang.org/x/net/context" 9 | "google.golang.org/grpc" 10 | "google.golang.org/grpc/codes" 11 | "google.golang.org/grpc/status" 12 | 13 | api "github.com/avinassh/grpc-errors/go/hello" 14 | ) 15 | 16 | type HelloServer struct { 17 | api.UnimplementedHelloServiceServer 18 | } 19 | 20 | func (s *HelloServer) SayHello(ctx context.Context, req *api.HelloReq) (*api.HelloResp, error) { 21 | return &api.HelloResp{Result: fmt.Sprintf("Hey, %s!", req.GetName())}, nil 22 | } 23 | 24 | func (s *HelloServer) SayHelloStrict(ctx context.Context, req *api.HelloReq) (*api.HelloResp, error) { 25 | if len(req.GetName()) >= 10 { 26 | return nil, status.Errorf(codes.InvalidArgument, 27 | "Length of `Name` cannot be more than 10 characters") 28 | } 29 | 30 | return &api.HelloResp{Result: fmt.Sprintf("Hey, %s!", req.GetName())}, nil 31 | } 32 | 33 | func Serve() { 34 | addr := fmt.Sprintf(":%d", 50051) 35 | conn, err := net.Listen("tcp", addr) 36 | if err != nil { 37 | log.Fatalf("Cannot listen to address %s", addr) 38 | } 39 | s := grpc.NewServer() 40 | api.RegisterHelloServiceServer(s, &HelloServer{}) 41 | if err := s.Serve(conn); err != nil { 42 | log.Fatalf("failed to serve: %v", err) 43 | } 44 | } 45 | 46 | func main() { 47 | Serve() 48 | } 49 | -------------------------------------------------------------------------------- /hello.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | // for Golang 3 | package hello; 4 | 5 | option go_package = "github.com/avinassh/grpc-errors/go/hello"; 6 | 7 | service HelloService { 8 | // This thing just says Hello to anyone 9 | // SayHello('Euler') -> Hello, Euler! 10 | rpc SayHello(HelloReq) returns (HelloResp) {}; 11 | // Strict Version responds only to requests which have `Name` length 12 | // less than 10 characters 13 | rpc SayHelloStrict(HelloReq) returns (HelloResp) {}; 14 | } 15 | 16 | message HelloReq { 17 | string Name = 1; 18 | } 19 | 20 | message HelloResp { 21 | string Result = 1; 22 | } 23 | -------------------------------------------------------------------------------- /node/README.md: -------------------------------------------------------------------------------- 1 | # Node gRPC 2 | 3 | ## Instructions 4 | 5 | In this example, protobuf JS APIs are generated on the fly, so no need to generate them. 6 | 7 | Install the dependencies: 8 | 9 | $ npm install 10 | 11 | To run: 12 | 13 | $ node server.js & 14 | $ node client.js -------------------------------------------------------------------------------- /node/client.js: -------------------------------------------------------------------------------- 1 | const PROTO_PATH = __dirname + '/../hello.proto'; 2 | 3 | var grpc = require('grpc'); 4 | var api = grpc.load(PROTO_PATH).hello; 5 | 6 | function main() { 7 | var client = new api.HelloService('localhost:50051', grpc.credentials.createInsecure()); 8 | 9 | client.sayHello({Name: 'Euler'}, function(err, response) { 10 | // check for `err` here too, which I am ignoring for brevity 11 | console.log(response.Result); 12 | }); 13 | 14 | client.sayHelloStrict({Name: 'Leonhard Euler'}, function(err, response) { 15 | if (err) { 16 | // ouch! 17 | // lets print the gRPC error message 18 | // which is "Length of `Name` cannot be more than 10 characters" 19 | console.log(err.message) 20 | // Want to take specific action based on specific error? 21 | if (err.code === grpc.status.INVALID_ARGUMENT) { 22 | // your code here 23 | } 24 | } 25 | }); 26 | } 27 | 28 | main(); -------------------------------------------------------------------------------- /node/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "grpc-errors", 3 | "version": "1.0.0", 4 | "description": "A handy guide to gRPC errors (in Node)", 5 | "author": "Avinash Sajjanshetty", 6 | "license": "MIT", 7 | "dependencies": { 8 | "google-protobuf": "^3.2.0", 9 | "grpc": "^1.2.0" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /node/server.js: -------------------------------------------------------------------------------- 1 | const PROTO_PATH = __dirname + '/../hello.proto'; 2 | 3 | var grpc = require('grpc'); 4 | var api = grpc.load(PROTO_PATH).hello; 5 | 6 | function sayHello(call, callback) { 7 | callback(null, {Result: 'Hey, ' + call.request.Name + '!'}); 8 | } 9 | 10 | function sayHelloStrict(call, callback) { 11 | if (call.request.Name.length >= 10) { 12 | return callback({ 13 | code: grpc.status.INVALID_ARGUMENT, 14 | message: "Length of `Name` cannot be more than 10 characters", 15 | }); 16 | } 17 | callback(null, {Result: 'Hey, ' + call.request.Name + '!'}); 18 | } 19 | 20 | function main() { 21 | var server = new grpc.Server(); 22 | server.addProtoService(api.HelloService.service, 23 | {sayHello: sayHello, sayHelloStrict: sayHelloStrict}); 24 | server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure()); 25 | server.start(); 26 | } 27 | 28 | main(); -------------------------------------------------------------------------------- /objective-c/HelloClient/Hello.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod spec lint Hello.podspec' to ensure this is a 3 | # valid spec and to remove all comments including this before submitting the spec. 4 | # 5 | # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html 6 | # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | 11 | # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 12 | # 13 | # These will help people to find your library, and whilst it 14 | # can feel like a chore to fill in it's definitely to your advantage. The 15 | # summary should be tweet-length, and the description more in depth. 16 | # 17 | 18 | s.name = "Hello" 19 | s.version = "0.0.1" 20 | s.summary = "A handy guide to gRPC errors." 21 | s.homepage = "http://avi.im/grpc-errors" 22 | 23 | # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 24 | # 25 | # Licensing your code is important. See http://choosealicense.com for more info. 26 | # CocoaPods will detect a license file if there is a named LICENSE* 27 | # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'. 28 | # 29 | 30 | s.license = "MIT" 31 | # s.license = { :type => "MIT", :file => "FILE_LICENSE" } 32 | 33 | 34 | # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 35 | # 36 | # Specify the authors of the library, with email addresses. Email addresses 37 | # of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also 38 | # accepts just a name if you'd rather not provide an email address. 39 | # 40 | # Specify a social_media_url where others can refer to, for example a twitter 41 | # profile URL. 42 | # 43 | 44 | s.author = { "Avinash Sajjanshetty" => "hi@avi.im" } 45 | # Or just: s.author = "Avinash Sajjanshetty" 46 | # s.authors = { "Avinash Sajjanshetty" => "hi@avi.im" } 47 | # s.social_media_url = "http://twitter.com/iavins" 48 | 49 | # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 50 | # 51 | # If this Pod runs only on iOS or OS X, then specify the platform and 52 | # the deployment target. You can optionally include the target after the platform. 53 | # 54 | 55 | # s.platform = :ios 56 | # s.platform = :ios, "5.0" 57 | 58 | # When using multiple platforms 59 | s.ios.deployment_target = "9.1" 60 | s.osx.deployment_target = "10.10" 61 | # s.watchos.deployment_target = "2.0" 62 | # s.tvos.deployment_target = "9.0" 63 | 64 | 65 | # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 66 | # 67 | # Specify the location from where the source should be retrieved. 68 | # Supports git, hg, bzr, svn and HTTP. 69 | # 70 | 71 | s.source = { :git => "https://github.com/avinassh/grpc-errors.git" } 72 | 73 | 74 | # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 75 | # 76 | # CocoaPods is smart about how it includes source code. For source files 77 | # giving a folder will include any swift, h, m, mm, c & cpp files. 78 | # For header files it will include any header in the folder. 79 | # Not including the public_header_files will make all headers public. 80 | # 81 | # Base directory where the .proto files are. 82 | src = "../../" 83 | 84 | # Run protoc with the Objective-C and gRPC plugins to generate protocol messages and gRPC clients. 85 | s.dependency "!ProtoCompiler-gRPCPlugin", "~> 1.0" 86 | 87 | # Pods directory corresponding to this app's Podfile, relative to the location of this podspec. 88 | pods_root = 'Pods' 89 | 90 | # Path where Cocoapods downloads protoc and the gRPC plugin. 91 | protoc_dir = "#{pods_root}/!ProtoCompiler" 92 | protoc = "#{protoc_dir}/protoc" 93 | plugin = "#{pods_root}/!ProtoCompiler-gRPCPlugin/grpc_objective_c_plugin" 94 | 95 | # Directory where the generated files will be placed. 96 | dir = "#{pods_root}/#{s.name}" 97 | 98 | s.prepare_command = <<-CMD 99 | mkdir -p #{dir} 100 | #{protoc} \ 101 | --plugin=protoc-gen-grpc=#{plugin} \ 102 | --objc_out=#{dir} \ 103 | --grpc_out=#{dir} \ 104 | -I #{src} \ 105 | -I #{protoc_dir} \ 106 | #{src}/hello.proto 107 | CMD 108 | 109 | # Files generated by protoc 110 | s.subspec "Messages" do |ms| 111 | ms.source_files = "#{dir}/*.pbobjc.{h,m}", "#{dir}/**/*.pbobjc.{h,m}" 112 | ms.header_mappings_dir = dir 113 | ms.requires_arc = false 114 | # The generated files depend on the protobuf runtime. 115 | ms.dependency "Protobuf" 116 | end 117 | 118 | # Files generated by the gRPC plugin 119 | s.subspec "Services" do |ss| 120 | ss.source_files = "#{dir}/*.pbrpc.{h,m}", "#{dir}/**/*.pbrpc.{h,m}" 121 | ss.header_mappings_dir = dir 122 | ss.requires_arc = true 123 | # The generated files depend on the gRPC runtime, and on the files generated by protoc. 124 | ss.dependency "gRPC-ProtoRPC" 125 | ss.dependency "#{s.name}/Messages" 126 | end 127 | 128 | s.pod_target_xcconfig = { 129 | # This is needed by all pods that depend on Protobuf: 130 | 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1', 131 | # This is needed by all pods that depend on gRPC-RxLibrary: 132 | 'CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES' => 'YES', 133 | } 134 | end 135 | -------------------------------------------------------------------------------- /objective-c/HelloClient/HelloClient.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 80F204C5D4475988B79A3D99 /* libPods-HelloClient.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6853CC74A053BF254CFC76DF /* libPods-HelloClient.a */; }; 11 | 825BE5F21E8BA02700A6E519 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 825BE5F11E8BA02700A6E519 /* main.m */; }; 12 | 825BE5F51E8BA02700A6E519 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 825BE5F41E8BA02700A6E519 /* AppDelegate.m */; }; 13 | 825BE5F81E8BA02700A6E519 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 825BE5F71E8BA02700A6E519 /* ViewController.m */; }; 14 | 825BE5FB1E8BA02700A6E519 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 825BE5F91E8BA02700A6E519 /* Main.storyboard */; }; 15 | 825BE5FD1E8BA02700A6E519 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 825BE5FC1E8BA02700A6E519 /* Assets.xcassets */; }; 16 | 825BE6001E8BA02700A6E519 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 825BE5FE1E8BA02700A6E519 /* LaunchScreen.storyboard */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | 0F345C0D19B25DA324E46801 /* Pods-HelloClient.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HelloClient.release.xcconfig"; path = "Pods/Target Support Files/Pods-HelloClient/Pods-HelloClient.release.xcconfig"; sourceTree = ""; }; 21 | 244B54F52428089E62EBF736 /* Pods-HelloClient.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HelloClient.debug.xcconfig"; path = "Pods/Target Support Files/Pods-HelloClient/Pods-HelloClient.debug.xcconfig"; sourceTree = ""; }; 22 | 6853CC74A053BF254CFC76DF /* libPods-HelloClient.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-HelloClient.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 23 | 825BE5ED1E8BA02700A6E519 /* HelloClient.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HelloClient.app; sourceTree = BUILT_PRODUCTS_DIR; }; 24 | 825BE5F11E8BA02700A6E519 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 25 | 825BE5F31E8BA02700A6E519 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 26 | 825BE5F41E8BA02700A6E519 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 27 | 825BE5F61E8BA02700A6E519 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 28 | 825BE5F71E8BA02700A6E519 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 29 | 825BE5FA1E8BA02700A6E519 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 30 | 825BE5FC1E8BA02700A6E519 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 31 | 825BE5FF1E8BA02700A6E519 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 32 | 825BE6011E8BA02700A6E519 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 33 | /* End PBXFileReference section */ 34 | 35 | /* Begin PBXFrameworksBuildPhase section */ 36 | 825BE5EA1E8BA02700A6E519 /* Frameworks */ = { 37 | isa = PBXFrameworksBuildPhase; 38 | buildActionMask = 2147483647; 39 | files = ( 40 | 80F204C5D4475988B79A3D99 /* libPods-HelloClient.a in Frameworks */, 41 | ); 42 | runOnlyForDeploymentPostprocessing = 0; 43 | }; 44 | /* End PBXFrameworksBuildPhase section */ 45 | 46 | /* Begin PBXGroup section */ 47 | 0C26355E200DC46957E45488 /* Pods */ = { 48 | isa = PBXGroup; 49 | children = ( 50 | 244B54F52428089E62EBF736 /* Pods-HelloClient.debug.xcconfig */, 51 | 0F345C0D19B25DA324E46801 /* Pods-HelloClient.release.xcconfig */, 52 | ); 53 | name = Pods; 54 | sourceTree = ""; 55 | }; 56 | 825BE5E41E8BA02700A6E519 = { 57 | isa = PBXGroup; 58 | children = ( 59 | 825BE5EF1E8BA02700A6E519 /* HelloClient */, 60 | 825BE5EE1E8BA02700A6E519 /* Products */, 61 | 0C26355E200DC46957E45488 /* Pods */, 62 | F5060577E1F3BDB6AEB5A741 /* Frameworks */, 63 | ); 64 | sourceTree = ""; 65 | }; 66 | 825BE5EE1E8BA02700A6E519 /* Products */ = { 67 | isa = PBXGroup; 68 | children = ( 69 | 825BE5ED1E8BA02700A6E519 /* HelloClient.app */, 70 | ); 71 | name = Products; 72 | sourceTree = ""; 73 | }; 74 | 825BE5EF1E8BA02700A6E519 /* HelloClient */ = { 75 | isa = PBXGroup; 76 | children = ( 77 | 825BE5F31E8BA02700A6E519 /* AppDelegate.h */, 78 | 825BE5F41E8BA02700A6E519 /* AppDelegate.m */, 79 | 825BE5F61E8BA02700A6E519 /* ViewController.h */, 80 | 825BE5F71E8BA02700A6E519 /* ViewController.m */, 81 | 825BE5F91E8BA02700A6E519 /* Main.storyboard */, 82 | 825BE5FC1E8BA02700A6E519 /* Assets.xcassets */, 83 | 825BE5FE1E8BA02700A6E519 /* LaunchScreen.storyboard */, 84 | 825BE6011E8BA02700A6E519 /* Info.plist */, 85 | 825BE5F01E8BA02700A6E519 /* Supporting Files */, 86 | ); 87 | path = HelloClient; 88 | sourceTree = ""; 89 | }; 90 | 825BE5F01E8BA02700A6E519 /* Supporting Files */ = { 91 | isa = PBXGroup; 92 | children = ( 93 | 825BE5F11E8BA02700A6E519 /* main.m */, 94 | ); 95 | name = "Supporting Files"; 96 | sourceTree = ""; 97 | }; 98 | F5060577E1F3BDB6AEB5A741 /* Frameworks */ = { 99 | isa = PBXGroup; 100 | children = ( 101 | 6853CC74A053BF254CFC76DF /* libPods-HelloClient.a */, 102 | ); 103 | name = Frameworks; 104 | sourceTree = ""; 105 | }; 106 | /* End PBXGroup section */ 107 | 108 | /* Begin PBXNativeTarget section */ 109 | 825BE5EC1E8BA02700A6E519 /* HelloClient */ = { 110 | isa = PBXNativeTarget; 111 | buildConfigurationList = 825BE6041E8BA02700A6E519 /* Build configuration list for PBXNativeTarget "HelloClient" */; 112 | buildPhases = ( 113 | A8B5493F421CF0307D27BAFA /* [CP] Check Pods Manifest.lock */, 114 | 825BE5E91E8BA02700A6E519 /* Sources */, 115 | 825BE5EA1E8BA02700A6E519 /* Frameworks */, 116 | 825BE5EB1E8BA02700A6E519 /* Resources */, 117 | 4735EFC9F61011047426F257 /* [CP] Embed Pods Frameworks */, 118 | CF5ECCEBF500CF16BB141B4A /* [CP] Copy Pods Resources */, 119 | ); 120 | buildRules = ( 121 | ); 122 | dependencies = ( 123 | ); 124 | name = HelloClient; 125 | productName = HelloClient; 126 | productReference = 825BE5ED1E8BA02700A6E519 /* HelloClient.app */; 127 | productType = "com.apple.product-type.application"; 128 | }; 129 | /* End PBXNativeTarget section */ 130 | 131 | /* Begin PBXProject section */ 132 | 825BE5E51E8BA02700A6E519 /* Project object */ = { 133 | isa = PBXProject; 134 | attributes = { 135 | LastUpgradeCheck = 0730; 136 | ORGANIZATIONNAME = avi.im; 137 | TargetAttributes = { 138 | 825BE5EC1E8BA02700A6E519 = { 139 | CreatedOnToolsVersion = 7.3.1; 140 | }; 141 | }; 142 | }; 143 | buildConfigurationList = 825BE5E81E8BA02700A6E519 /* Build configuration list for PBXProject "HelloClient" */; 144 | compatibilityVersion = "Xcode 3.2"; 145 | developmentRegion = English; 146 | hasScannedForEncodings = 0; 147 | knownRegions = ( 148 | en, 149 | Base, 150 | ); 151 | mainGroup = 825BE5E41E8BA02700A6E519; 152 | productRefGroup = 825BE5EE1E8BA02700A6E519 /* Products */; 153 | projectDirPath = ""; 154 | projectRoot = ""; 155 | targets = ( 156 | 825BE5EC1E8BA02700A6E519 /* HelloClient */, 157 | ); 158 | }; 159 | /* End PBXProject section */ 160 | 161 | /* Begin PBXResourcesBuildPhase section */ 162 | 825BE5EB1E8BA02700A6E519 /* Resources */ = { 163 | isa = PBXResourcesBuildPhase; 164 | buildActionMask = 2147483647; 165 | files = ( 166 | 825BE6001E8BA02700A6E519 /* LaunchScreen.storyboard in Resources */, 167 | 825BE5FD1E8BA02700A6E519 /* Assets.xcassets in Resources */, 168 | 825BE5FB1E8BA02700A6E519 /* Main.storyboard in Resources */, 169 | ); 170 | runOnlyForDeploymentPostprocessing = 0; 171 | }; 172 | /* End PBXResourcesBuildPhase section */ 173 | 174 | /* Begin PBXShellScriptBuildPhase section */ 175 | 4735EFC9F61011047426F257 /* [CP] Embed Pods Frameworks */ = { 176 | isa = PBXShellScriptBuildPhase; 177 | buildActionMask = 2147483647; 178 | files = ( 179 | ); 180 | inputPaths = ( 181 | ); 182 | name = "[CP] Embed Pods Frameworks"; 183 | outputPaths = ( 184 | ); 185 | runOnlyForDeploymentPostprocessing = 0; 186 | shellPath = /bin/sh; 187 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-HelloClient/Pods-HelloClient-frameworks.sh\"\n"; 188 | showEnvVarsInLog = 0; 189 | }; 190 | A8B5493F421CF0307D27BAFA /* [CP] Check Pods Manifest.lock */ = { 191 | isa = PBXShellScriptBuildPhase; 192 | buildActionMask = 2147483647; 193 | files = ( 194 | ); 195 | inputPaths = ( 196 | ); 197 | name = "[CP] Check Pods Manifest.lock"; 198 | outputPaths = ( 199 | ); 200 | runOnlyForDeploymentPostprocessing = 0; 201 | shellPath = /bin/sh; 202 | shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; 203 | showEnvVarsInLog = 0; 204 | }; 205 | CF5ECCEBF500CF16BB141B4A /* [CP] Copy Pods Resources */ = { 206 | isa = PBXShellScriptBuildPhase; 207 | buildActionMask = 2147483647; 208 | files = ( 209 | ); 210 | inputPaths = ( 211 | ); 212 | name = "[CP] Copy Pods Resources"; 213 | outputPaths = ( 214 | ); 215 | runOnlyForDeploymentPostprocessing = 0; 216 | shellPath = /bin/sh; 217 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-HelloClient/Pods-HelloClient-resources.sh\"\n"; 218 | showEnvVarsInLog = 0; 219 | }; 220 | /* End PBXShellScriptBuildPhase section */ 221 | 222 | /* Begin PBXSourcesBuildPhase section */ 223 | 825BE5E91E8BA02700A6E519 /* Sources */ = { 224 | isa = PBXSourcesBuildPhase; 225 | buildActionMask = 2147483647; 226 | files = ( 227 | 825BE5F81E8BA02700A6E519 /* ViewController.m in Sources */, 228 | 825BE5F51E8BA02700A6E519 /* AppDelegate.m in Sources */, 229 | 825BE5F21E8BA02700A6E519 /* main.m in Sources */, 230 | ); 231 | runOnlyForDeploymentPostprocessing = 0; 232 | }; 233 | /* End PBXSourcesBuildPhase section */ 234 | 235 | /* Begin PBXVariantGroup section */ 236 | 825BE5F91E8BA02700A6E519 /* Main.storyboard */ = { 237 | isa = PBXVariantGroup; 238 | children = ( 239 | 825BE5FA1E8BA02700A6E519 /* Base */, 240 | ); 241 | name = Main.storyboard; 242 | sourceTree = ""; 243 | }; 244 | 825BE5FE1E8BA02700A6E519 /* LaunchScreen.storyboard */ = { 245 | isa = PBXVariantGroup; 246 | children = ( 247 | 825BE5FF1E8BA02700A6E519 /* Base */, 248 | ); 249 | name = LaunchScreen.storyboard; 250 | sourceTree = ""; 251 | }; 252 | /* End PBXVariantGroup section */ 253 | 254 | /* Begin XCBuildConfiguration section */ 255 | 825BE6021E8BA02700A6E519 /* Debug */ = { 256 | isa = XCBuildConfiguration; 257 | buildSettings = { 258 | ALWAYS_SEARCH_USER_PATHS = NO; 259 | CLANG_ANALYZER_NONNULL = YES; 260 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 261 | CLANG_CXX_LIBRARY = "libc++"; 262 | CLANG_ENABLE_MODULES = YES; 263 | CLANG_ENABLE_OBJC_ARC = YES; 264 | CLANG_WARN_BOOL_CONVERSION = YES; 265 | CLANG_WARN_CONSTANT_CONVERSION = YES; 266 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 267 | CLANG_WARN_EMPTY_BODY = YES; 268 | CLANG_WARN_ENUM_CONVERSION = YES; 269 | CLANG_WARN_INT_CONVERSION = YES; 270 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 271 | CLANG_WARN_UNREACHABLE_CODE = YES; 272 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 273 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 274 | COPY_PHASE_STRIP = NO; 275 | DEBUG_INFORMATION_FORMAT = dwarf; 276 | ENABLE_STRICT_OBJC_MSGSEND = YES; 277 | ENABLE_TESTABILITY = YES; 278 | GCC_C_LANGUAGE_STANDARD = gnu99; 279 | GCC_DYNAMIC_NO_PIC = NO; 280 | GCC_NO_COMMON_BLOCKS = YES; 281 | GCC_OPTIMIZATION_LEVEL = 0; 282 | GCC_PREPROCESSOR_DEFINITIONS = ( 283 | "DEBUG=1", 284 | "$(inherited)", 285 | ); 286 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 287 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 288 | GCC_WARN_UNDECLARED_SELECTOR = YES; 289 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 290 | GCC_WARN_UNUSED_FUNCTION = YES; 291 | GCC_WARN_UNUSED_VARIABLE = YES; 292 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 293 | MTL_ENABLE_DEBUG_INFO = YES; 294 | ONLY_ACTIVE_ARCH = YES; 295 | SDKROOT = iphoneos; 296 | }; 297 | name = Debug; 298 | }; 299 | 825BE6031E8BA02700A6E519 /* Release */ = { 300 | isa = XCBuildConfiguration; 301 | buildSettings = { 302 | ALWAYS_SEARCH_USER_PATHS = NO; 303 | CLANG_ANALYZER_NONNULL = YES; 304 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 305 | CLANG_CXX_LIBRARY = "libc++"; 306 | CLANG_ENABLE_MODULES = YES; 307 | CLANG_ENABLE_OBJC_ARC = YES; 308 | CLANG_WARN_BOOL_CONVERSION = YES; 309 | CLANG_WARN_CONSTANT_CONVERSION = YES; 310 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 311 | CLANG_WARN_EMPTY_BODY = YES; 312 | CLANG_WARN_ENUM_CONVERSION = YES; 313 | CLANG_WARN_INT_CONVERSION = YES; 314 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 315 | CLANG_WARN_UNREACHABLE_CODE = YES; 316 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 317 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 318 | COPY_PHASE_STRIP = NO; 319 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 320 | ENABLE_NS_ASSERTIONS = NO; 321 | ENABLE_STRICT_OBJC_MSGSEND = YES; 322 | GCC_C_LANGUAGE_STANDARD = gnu99; 323 | GCC_NO_COMMON_BLOCKS = YES; 324 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 325 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 326 | GCC_WARN_UNDECLARED_SELECTOR = YES; 327 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 328 | GCC_WARN_UNUSED_FUNCTION = YES; 329 | GCC_WARN_UNUSED_VARIABLE = YES; 330 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 331 | MTL_ENABLE_DEBUG_INFO = NO; 332 | SDKROOT = iphoneos; 333 | VALIDATE_PRODUCT = YES; 334 | }; 335 | name = Release; 336 | }; 337 | 825BE6051E8BA02700A6E519 /* Debug */ = { 338 | isa = XCBuildConfiguration; 339 | baseConfigurationReference = 244B54F52428089E62EBF736 /* Pods-HelloClient.debug.xcconfig */; 340 | buildSettings = { 341 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 342 | INFOPLIST_FILE = HelloClient/Info.plist; 343 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 344 | PRODUCT_BUNDLE_IDENTIFIER = im.avi.HelloClient; 345 | PRODUCT_NAME = "$(TARGET_NAME)"; 346 | }; 347 | name = Debug; 348 | }; 349 | 825BE6061E8BA02700A6E519 /* Release */ = { 350 | isa = XCBuildConfiguration; 351 | baseConfigurationReference = 0F345C0D19B25DA324E46801 /* Pods-HelloClient.release.xcconfig */; 352 | buildSettings = { 353 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 354 | INFOPLIST_FILE = HelloClient/Info.plist; 355 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 356 | PRODUCT_BUNDLE_IDENTIFIER = im.avi.HelloClient; 357 | PRODUCT_NAME = "$(TARGET_NAME)"; 358 | }; 359 | name = Release; 360 | }; 361 | /* End XCBuildConfiguration section */ 362 | 363 | /* Begin XCConfigurationList section */ 364 | 825BE5E81E8BA02700A6E519 /* Build configuration list for PBXProject "HelloClient" */ = { 365 | isa = XCConfigurationList; 366 | buildConfigurations = ( 367 | 825BE6021E8BA02700A6E519 /* Debug */, 368 | 825BE6031E8BA02700A6E519 /* Release */, 369 | ); 370 | defaultConfigurationIsVisible = 0; 371 | defaultConfigurationName = Release; 372 | }; 373 | 825BE6041E8BA02700A6E519 /* Build configuration list for PBXNativeTarget "HelloClient" */ = { 374 | isa = XCConfigurationList; 375 | buildConfigurations = ( 376 | 825BE6051E8BA02700A6E519 /* Debug */, 377 | 825BE6061E8BA02700A6E519 /* Release */, 378 | ); 379 | defaultConfigurationIsVisible = 0; 380 | }; 381 | /* End XCConfigurationList section */ 382 | }; 383 | rootObject = 825BE5E51E8BA02700A6E519 /* Project object */; 384 | } 385 | -------------------------------------------------------------------------------- /objective-c/HelloClient/HelloClient.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /objective-c/HelloClient/HelloClient.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /objective-c/HelloClient/HelloClient/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface AppDelegate : UIResponder 4 | 5 | @property (strong, nonatomic) UIWindow *window; 6 | 7 | 8 | @end 9 | 10 | -------------------------------------------------------------------------------- /objective-c/HelloClient/HelloClient/AppDelegate.m: -------------------------------------------------------------------------------- 1 | #import "AppDelegate.h" 2 | 3 | @interface AppDelegate () 4 | 5 | @end 6 | 7 | @implementation AppDelegate 8 | 9 | 10 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 11 | // Override point for customization after application launch. 12 | return YES; 13 | } 14 | 15 | - (void)applicationWillResignActive:(UIApplication *)application { 16 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 17 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 18 | } 19 | 20 | - (void)applicationDidEnterBackground:(UIApplication *)application { 21 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 22 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 23 | } 24 | 25 | - (void)applicationWillEnterForeground:(UIApplication *)application { 26 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 27 | } 28 | 29 | - (void)applicationDidBecomeActive:(UIApplication *)application { 30 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 31 | } 32 | 33 | - (void)applicationWillTerminate:(UIApplication *)application { 34 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 35 | } 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /objective-c/HelloClient/HelloClient/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /objective-c/HelloClient/HelloClient/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /objective-c/HelloClient/HelloClient/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /objective-c/HelloClient/HelloClient/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /objective-c/HelloClient/HelloClient/ViewController.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface ViewController : UIViewController 4 | 5 | 6 | @end 7 | 8 | -------------------------------------------------------------------------------- /objective-c/HelloClient/HelloClient/ViewController.m: -------------------------------------------------------------------------------- 1 | #import "ViewController.h" 2 | 3 | @interface ViewController () 4 | 5 | @end 6 | 7 | @implementation ViewController 8 | 9 | - (void)viewDidLoad { 10 | [super viewDidLoad]; 11 | // Do any additional setup after loading the view, typically from a nib. 12 | } 13 | 14 | - (void)didReceiveMemoryWarning { 15 | [super didReceiveMemoryWarning]; 16 | // Dispose of any resources that can be recreated. 17 | } 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /objective-c/HelloClient/HelloClient/main.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import "AppDelegate.h" 3 | 4 | #import 5 | #import 6 | #import 7 | #import 8 | 9 | static NSString * const kHostAddress = @"localhost:50051"; 10 | 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | 15 | [GRPCCall useInsecureConnectionsForHost:kHostAddress]; 16 | [GRPCCall setUserAgentPrefix:@"HelloWorld/1.0" forHost:kHostAddress]; 17 | 18 | HelloService *client = [[HelloService alloc] initWithHost:kHostAddress]; 19 | 20 | HelloReq *request = [HelloReq message]; 21 | request.name = @"Euler"; 22 | 23 | // ideally you should check for errors here too 24 | [client sayHelloWithRequest:request handler:^(HelloResp *response, NSError *error) { 25 | NSLog(@"%@", response.result); 26 | }]; 27 | 28 | // lets try the failing case 29 | request.name = @"Leonhard Euler"; 30 | [client sayHelloStrictWithRequest:request handler:^(HelloResp *response, NSError *error) { 31 | 32 | if (error.code == GRPC_STATUS_OK) { 33 | NSLog(@"%@", response.result); 34 | } else { 35 | // ouch! 36 | // lets print the gRPC error message 37 | // which is "Length of `Name` cannot be more than 10 characters" 38 | NSLog(@"%@", error.localizedDescription); 39 | // Want its int version for some reason? 40 | // you shouldn't actually do this, but if you need for debugging, 41 | // you can access `error.code` which will give you `3` 42 | NSLog(@"%ld", (long)error.code); 43 | // Want to take specific action based on specific error? 44 | if (error.code == GRPC_STATUS_INVALID_ARGUMENT) { 45 | // do your thing 46 | } 47 | } 48 | }]; 49 | 50 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /objective-c/HelloClient/Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment the next line to define a global platform for your project 2 | # platform :ios, '9.0' 3 | 4 | target 'HelloClient' do 5 | # Uncomment the next line if you're using Swift or would like to use dynamic frameworks 6 | # use_frameworks! 7 | 8 | pod 'Hello', :path => '.' 9 | 10 | end 11 | -------------------------------------------------------------------------------- /objective-c/HelloClient/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - "!ProtoCompiler (3.2.0)": 3 | - Protobuf (~> 3.0) 4 | - "!ProtoCompiler-gRPCPlugin (1.2.0)": 5 | - "!ProtoCompiler (= 3.2.0)" 6 | - gRPC-ProtoRPC (= 1.2.0) 7 | - BoringSSL (8.0): 8 | - BoringSSL/Implementation (= 8.0) 9 | - BoringSSL/Interface (= 8.0) 10 | - BoringSSL/Implementation (8.0): 11 | - BoringSSL/Interface (= 8.0) 12 | - BoringSSL/Interface (8.0) 13 | - gRPC (1.2.0): 14 | - gRPC-Core (= 1.2.0) 15 | - gRPC-RxLibrary (= 1.2.0) 16 | - gRPC-Core (1.2.0): 17 | - gRPC-Core/Implementation (= 1.2.0) 18 | - gRPC-Core/Interface (= 1.2.0) 19 | - gRPC-Core/Implementation (1.2.0): 20 | - BoringSSL (~> 8.0) 21 | - gRPC-Core/Interface (= 1.2.0) 22 | - gRPC-Core/Interface (1.2.0) 23 | - gRPC-ProtoRPC (1.2.0): 24 | - gRPC (= 1.2.0) 25 | - gRPC-RxLibrary (= 1.2.0) 26 | - Protobuf (~> 3.0) 27 | - gRPC-RxLibrary (1.2.0) 28 | - Hello (0.0.1): 29 | - "!ProtoCompiler-gRPCPlugin (~> 1.0)" 30 | - Hello/Messages (= 0.0.1) 31 | - Hello/Services (= 0.0.1) 32 | - Hello/Messages (0.0.1): 33 | - "!ProtoCompiler-gRPCPlugin (~> 1.0)" 34 | - Protobuf 35 | - Hello/Services (0.0.1): 36 | - "!ProtoCompiler-gRPCPlugin (~> 1.0)" 37 | - gRPC-ProtoRPC 38 | - Hello/Messages 39 | - Protobuf (3.2.0) 40 | 41 | DEPENDENCIES: 42 | - Hello (from `.`) 43 | 44 | EXTERNAL SOURCES: 45 | Hello: 46 | :path: "." 47 | 48 | SPEC CHECKSUMS: 49 | "!ProtoCompiler": b66c7c0c1d911ad1490dcbfce30e1508739d8309 50 | "!ProtoCompiler-gRPCPlugin": e971571341f3b0e834e5592eb684de97b4978382 51 | BoringSSL: bafdcc5b88bac8ee45d7d207c507697f8c75b2fc 52 | gRPC: a7cdb9882aff57b83a1a96d7f1b902527abee3ff 53 | gRPC-Core: 81c86a58e64f62d5635697e9141b300ec6023132 54 | gRPC-ProtoRPC: 01d9c0ba95d63e402fa7a9251bd439c5dc5ccb2e 55 | gRPC-RxLibrary: 0da081dd7e8cd31313affcd65f36f80124b013c0 56 | Hello: e7fef98ea4761c9d2ed2af1e0d673d4028cad3a3 57 | Protobuf: 745f59e122e5de98d4d7ef291e264a0eef80f58e 58 | 59 | PODFILE CHECKSUM: e649788bd7ebf89468505c5c99e2c1d60c587bc8 60 | 61 | COCOAPODS: 1.2.0 62 | -------------------------------------------------------------------------------- /objective-c/README.md: -------------------------------------------------------------------------------- 1 | # Objective C gRPC 2 | 3 | Note that this example has only client version of Objective C. For server, you can use any of the available server implementations. Following instructions show running a Go server. 4 | 5 | ## Instructions 6 | 7 | Install the dependencies and generate protobuf file: 8 | 9 | $ pod install 10 | 11 | Run the server ([instructions](../go/README.md)): 12 | 13 | $ ./server & 14 | 15 | Run the client: 16 | 17 | 1. Open `HelloClient.xcworkspace` 18 | 2. Run -------------------------------------------------------------------------------- /python/README.md: -------------------------------------------------------------------------------- 1 | # Python gRPC 2 | 3 | ## Instructions 4 | 5 | Install the dependencies: 6 | 7 | $ pip install -r requirements.txt 8 | 9 | Generate protobuf files: 10 | 11 | $ python -m grpc_tools.protoc -I../ --python_out=. --grpc_python_out=. ../hello.proto 12 | 13 | Run client and server: 14 | 15 | $ python server.py & 16 | $ python client.py -------------------------------------------------------------------------------- /python/client.py: -------------------------------------------------------------------------------- 1 | import grpc 2 | 3 | import hello_pb2 4 | import hello_pb2_grpc 5 | 6 | 7 | def run(): 8 | channel = grpc.insecure_channel('localhost:50051') 9 | stub = hello_pb2_grpc.HelloServiceStub(channel) 10 | # ideally, you should have try catch block here too 11 | response = stub.SayHello(hello_pb2.HelloReq(Name='Euler')) 12 | print(response.Result) 13 | 14 | try: 15 | response = stub.SayHelloStrict(hello_pb2.HelloReq( 16 | Name='Leonhard Euler')) 17 | except grpc.RpcError as e: 18 | # ouch! 19 | # lets print the gRPC error message 20 | # which is "Length of `Name` cannot be more than 10 characters" 21 | print(e.details()) 22 | # lets access the error code, which is `INVALID_ARGUMENT` 23 | # `type` of `status_code` is `grpc.StatusCode` 24 | status_code = e.code() 25 | # should print `INVALID_ARGUMENT` 26 | print(status_code.name) 27 | # should print `(3, 'invalid argument')` 28 | print(status_code.value) 29 | # want to do some specific action based on the error? 30 | if grpc.StatusCode.INVALID_ARGUMENT == status_code: 31 | # do your stuff here 32 | pass 33 | else: 34 | print(response.Result) 35 | 36 | 37 | if __name__ == '__main__': 38 | run() 39 | -------------------------------------------------------------------------------- /python/hello_pb2.py: -------------------------------------------------------------------------------- 1 | # Generated by the protocol buffer compiler. DO NOT EDIT! 2 | # source: hello.proto 3 | 4 | import sys 5 | _b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) 6 | from google.protobuf import descriptor as _descriptor 7 | from google.protobuf import message as _message 8 | from google.protobuf import reflection as _reflection 9 | from google.protobuf import symbol_database as _symbol_database 10 | from google.protobuf import descriptor_pb2 11 | # @@protoc_insertion_point(imports) 12 | 13 | _sym_db = _symbol_database.Default() 14 | 15 | 16 | 17 | 18 | DESCRIPTOR = _descriptor.FileDescriptor( 19 | name='hello.proto', 20 | package='hello', 21 | syntax='proto3', 22 | serialized_pb=_b('\n\x0bhello.proto\x12\x05hello\"\x18\n\x08HelloReq\x12\x0c\n\x04Name\x18\x01 \x01(\t\"\x1b\n\tHelloResp\x12\x0e\n\x06Result\x18\x01 \x01(\t2v\n\x0cHelloService\x12/\n\x08SayHello\x12\x0f.hello.HelloReq\x1a\x10.hello.HelloResp\"\x00\x12\x35\n\x0eSayHelloStrict\x12\x0f.hello.HelloReq\x1a\x10.hello.HelloResp\"\x00\x62\x06proto3') 23 | ) 24 | _sym_db.RegisterFileDescriptor(DESCRIPTOR) 25 | 26 | 27 | 28 | 29 | _HELLOREQ = _descriptor.Descriptor( 30 | name='HelloReq', 31 | full_name='hello.HelloReq', 32 | filename=None, 33 | file=DESCRIPTOR, 34 | containing_type=None, 35 | fields=[ 36 | _descriptor.FieldDescriptor( 37 | name='Name', full_name='hello.HelloReq.Name', index=0, 38 | number=1, type=9, cpp_type=9, label=1, 39 | has_default_value=False, default_value=_b("").decode('utf-8'), 40 | message_type=None, enum_type=None, containing_type=None, 41 | is_extension=False, extension_scope=None, 42 | options=None), 43 | ], 44 | extensions=[ 45 | ], 46 | nested_types=[], 47 | enum_types=[ 48 | ], 49 | options=None, 50 | is_extendable=False, 51 | syntax='proto3', 52 | extension_ranges=[], 53 | oneofs=[ 54 | ], 55 | serialized_start=22, 56 | serialized_end=46, 57 | ) 58 | 59 | 60 | _HELLORESP = _descriptor.Descriptor( 61 | name='HelloResp', 62 | full_name='hello.HelloResp', 63 | filename=None, 64 | file=DESCRIPTOR, 65 | containing_type=None, 66 | fields=[ 67 | _descriptor.FieldDescriptor( 68 | name='Result', full_name='hello.HelloResp.Result', index=0, 69 | number=1, type=9, cpp_type=9, label=1, 70 | has_default_value=False, default_value=_b("").decode('utf-8'), 71 | message_type=None, enum_type=None, containing_type=None, 72 | is_extension=False, extension_scope=None, 73 | options=None), 74 | ], 75 | extensions=[ 76 | ], 77 | nested_types=[], 78 | enum_types=[ 79 | ], 80 | options=None, 81 | is_extendable=False, 82 | syntax='proto3', 83 | extension_ranges=[], 84 | oneofs=[ 85 | ], 86 | serialized_start=48, 87 | serialized_end=75, 88 | ) 89 | 90 | DESCRIPTOR.message_types_by_name['HelloReq'] = _HELLOREQ 91 | DESCRIPTOR.message_types_by_name['HelloResp'] = _HELLORESP 92 | 93 | HelloReq = _reflection.GeneratedProtocolMessageType('HelloReq', (_message.Message,), dict( 94 | DESCRIPTOR = _HELLOREQ, 95 | __module__ = 'hello_pb2' 96 | # @@protoc_insertion_point(class_scope:hello.HelloReq) 97 | )) 98 | _sym_db.RegisterMessage(HelloReq) 99 | 100 | HelloResp = _reflection.GeneratedProtocolMessageType('HelloResp', (_message.Message,), dict( 101 | DESCRIPTOR = _HELLORESP, 102 | __module__ = 'hello_pb2' 103 | # @@protoc_insertion_point(class_scope:hello.HelloResp) 104 | )) 105 | _sym_db.RegisterMessage(HelloResp) 106 | 107 | 108 | try: 109 | # THESE ELEMENTS WILL BE DEPRECATED. 110 | # Please use the generated *_pb2_grpc.py files instead. 111 | import grpc 112 | from grpc.framework.common import cardinality 113 | from grpc.framework.interfaces.face import utilities as face_utilities 114 | from grpc.beta import implementations as beta_implementations 115 | from grpc.beta import interfaces as beta_interfaces 116 | 117 | 118 | class HelloServiceStub(object): 119 | 120 | def __init__(self, channel): 121 | """Constructor. 122 | 123 | Args: 124 | channel: A grpc.Channel. 125 | """ 126 | self.SayHello = channel.unary_unary( 127 | '/hello.HelloService/SayHello', 128 | request_serializer=HelloReq.SerializeToString, 129 | response_deserializer=HelloResp.FromString, 130 | ) 131 | self.SayHelloStrict = channel.unary_unary( 132 | '/hello.HelloService/SayHelloStrict', 133 | request_serializer=HelloReq.SerializeToString, 134 | response_deserializer=HelloResp.FromString, 135 | ) 136 | 137 | 138 | class HelloServiceServicer(object): 139 | 140 | def SayHello(self, request, context): 141 | """This thing just says Hello to anyone 142 | SayHello('Euler') -> Hello, Euler! 143 | """ 144 | context.set_code(grpc.StatusCode.UNIMPLEMENTED) 145 | context.set_details('Method not implemented!') 146 | raise NotImplementedError('Method not implemented!') 147 | 148 | def SayHelloStrict(self, request, context): 149 | """Strict Version responds only to requests which have `Name` length 150 | less than 10 characters 151 | """ 152 | context.set_code(grpc.StatusCode.UNIMPLEMENTED) 153 | context.set_details('Method not implemented!') 154 | raise NotImplementedError('Method not implemented!') 155 | 156 | 157 | def add_HelloServiceServicer_to_server(servicer, server): 158 | rpc_method_handlers = { 159 | 'SayHello': grpc.unary_unary_rpc_method_handler( 160 | servicer.SayHello, 161 | request_deserializer=HelloReq.FromString, 162 | response_serializer=HelloResp.SerializeToString, 163 | ), 164 | 'SayHelloStrict': grpc.unary_unary_rpc_method_handler( 165 | servicer.SayHelloStrict, 166 | request_deserializer=HelloReq.FromString, 167 | response_serializer=HelloResp.SerializeToString, 168 | ), 169 | } 170 | generic_handler = grpc.method_handlers_generic_handler( 171 | 'hello.HelloService', rpc_method_handlers) 172 | server.add_generic_rpc_handlers((generic_handler,)) 173 | 174 | 175 | class BetaHelloServiceServicer(object): 176 | """The Beta API is deprecated for 0.15.0 and later. 177 | 178 | It is recommended to use the GA API (classes and functions in this 179 | file not marked beta) for all further purposes. This class was generated 180 | only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0.""" 181 | def SayHello(self, request, context): 182 | """This thing just says Hello to anyone 183 | SayHello('Euler') -> Hello, Euler! 184 | """ 185 | context.code(beta_interfaces.StatusCode.UNIMPLEMENTED) 186 | def SayHelloStrict(self, request, context): 187 | """Strict Version responds only to requests which have `Name` length 188 | less than 10 characters 189 | """ 190 | context.code(beta_interfaces.StatusCode.UNIMPLEMENTED) 191 | 192 | 193 | class BetaHelloServiceStub(object): 194 | """The Beta API is deprecated for 0.15.0 and later. 195 | 196 | It is recommended to use the GA API (classes and functions in this 197 | file not marked beta) for all further purposes. This class was generated 198 | only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0.""" 199 | def SayHello(self, request, timeout, metadata=None, with_call=False, protocol_options=None): 200 | """This thing just says Hello to anyone 201 | SayHello('Euler') -> Hello, Euler! 202 | """ 203 | raise NotImplementedError() 204 | SayHello.future = None 205 | def SayHelloStrict(self, request, timeout, metadata=None, with_call=False, protocol_options=None): 206 | """Strict Version responds only to requests which have `Name` length 207 | less than 10 characters 208 | """ 209 | raise NotImplementedError() 210 | SayHelloStrict.future = None 211 | 212 | 213 | def beta_create_HelloService_server(servicer, pool=None, pool_size=None, default_timeout=None, maximum_timeout=None): 214 | """The Beta API is deprecated for 0.15.0 and later. 215 | 216 | It is recommended to use the GA API (classes and functions in this 217 | file not marked beta) for all further purposes. This function was 218 | generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0""" 219 | request_deserializers = { 220 | ('hello.HelloService', 'SayHello'): HelloReq.FromString, 221 | ('hello.HelloService', 'SayHelloStrict'): HelloReq.FromString, 222 | } 223 | response_serializers = { 224 | ('hello.HelloService', 'SayHello'): HelloResp.SerializeToString, 225 | ('hello.HelloService', 'SayHelloStrict'): HelloResp.SerializeToString, 226 | } 227 | method_implementations = { 228 | ('hello.HelloService', 'SayHello'): face_utilities.unary_unary_inline(servicer.SayHello), 229 | ('hello.HelloService', 'SayHelloStrict'): face_utilities.unary_unary_inline(servicer.SayHelloStrict), 230 | } 231 | server_options = beta_implementations.server_options(request_deserializers=request_deserializers, response_serializers=response_serializers, thread_pool=pool, thread_pool_size=pool_size, default_timeout=default_timeout, maximum_timeout=maximum_timeout) 232 | return beta_implementations.server(method_implementations, options=server_options) 233 | 234 | 235 | def beta_create_HelloService_stub(channel, host=None, metadata_transformer=None, pool=None, pool_size=None): 236 | """The Beta API is deprecated for 0.15.0 and later. 237 | 238 | It is recommended to use the GA API (classes and functions in this 239 | file not marked beta) for all further purposes. This function was 240 | generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0""" 241 | request_serializers = { 242 | ('hello.HelloService', 'SayHello'): HelloReq.SerializeToString, 243 | ('hello.HelloService', 'SayHelloStrict'): HelloReq.SerializeToString, 244 | } 245 | response_deserializers = { 246 | ('hello.HelloService', 'SayHello'): HelloResp.FromString, 247 | ('hello.HelloService', 'SayHelloStrict'): HelloResp.FromString, 248 | } 249 | cardinalities = { 250 | 'SayHello': cardinality.Cardinality.UNARY_UNARY, 251 | 'SayHelloStrict': cardinality.Cardinality.UNARY_UNARY, 252 | } 253 | stub_options = beta_implementations.stub_options(host=host, metadata_transformer=metadata_transformer, request_serializers=request_serializers, response_deserializers=response_deserializers, thread_pool=pool, thread_pool_size=pool_size) 254 | return beta_implementations.dynamic_stub(channel, 'hello.HelloService', cardinalities, options=stub_options) 255 | except ImportError: 256 | pass 257 | # @@protoc_insertion_point(module_scope) 258 | -------------------------------------------------------------------------------- /python/hello_pb2_grpc.py: -------------------------------------------------------------------------------- 1 | # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! 2 | import grpc 3 | from grpc.framework.common import cardinality 4 | from grpc.framework.interfaces.face import utilities as face_utilities 5 | 6 | import hello_pb2 as hello__pb2 7 | 8 | 9 | class HelloServiceStub(object): 10 | 11 | def __init__(self, channel): 12 | """Constructor. 13 | 14 | Args: 15 | channel: A grpc.Channel. 16 | """ 17 | self.SayHello = channel.unary_unary( 18 | '/hello.HelloService/SayHello', 19 | request_serializer=hello__pb2.HelloReq.SerializeToString, 20 | response_deserializer=hello__pb2.HelloResp.FromString, 21 | ) 22 | self.SayHelloStrict = channel.unary_unary( 23 | '/hello.HelloService/SayHelloStrict', 24 | request_serializer=hello__pb2.HelloReq.SerializeToString, 25 | response_deserializer=hello__pb2.HelloResp.FromString, 26 | ) 27 | 28 | 29 | class HelloServiceServicer(object): 30 | 31 | def SayHello(self, request, context): 32 | """This thing just says Hello to anyone 33 | SayHello('Euler') -> Hello, Euler! 34 | """ 35 | context.set_code(grpc.StatusCode.UNIMPLEMENTED) 36 | context.set_details('Method not implemented!') 37 | raise NotImplementedError('Method not implemented!') 38 | 39 | def SayHelloStrict(self, request, context): 40 | """Strict Version responds only to requests which have `Name` length 41 | less than 10 characters 42 | """ 43 | context.set_code(grpc.StatusCode.UNIMPLEMENTED) 44 | context.set_details('Method not implemented!') 45 | raise NotImplementedError('Method not implemented!') 46 | 47 | 48 | def add_HelloServiceServicer_to_server(servicer, server): 49 | rpc_method_handlers = { 50 | 'SayHello': grpc.unary_unary_rpc_method_handler( 51 | servicer.SayHello, 52 | request_deserializer=hello__pb2.HelloReq.FromString, 53 | response_serializer=hello__pb2.HelloResp.SerializeToString, 54 | ), 55 | 'SayHelloStrict': grpc.unary_unary_rpc_method_handler( 56 | servicer.SayHelloStrict, 57 | request_deserializer=hello__pb2.HelloReq.FromString, 58 | response_serializer=hello__pb2.HelloResp.SerializeToString, 59 | ), 60 | } 61 | generic_handler = grpc.method_handlers_generic_handler( 62 | 'hello.HelloService', rpc_method_handlers) 63 | server.add_generic_rpc_handlers((generic_handler,)) 64 | -------------------------------------------------------------------------------- /python/requirements.txt: -------------------------------------------------------------------------------- 1 | grpcio-tools==1.2.0 2 | -------------------------------------------------------------------------------- /python/server.py: -------------------------------------------------------------------------------- 1 | import time 2 | from concurrent import futures 3 | 4 | import grpc 5 | 6 | import hello_pb2 7 | import hello_pb2_grpc 8 | 9 | _ONE_DAY_IN_SECONDS = 60 * 60 * 24 10 | 11 | 12 | class HelloServicer(hello_pb2_grpc.HelloServiceServicer): 13 | 14 | def SayHello(self, request, context): 15 | return hello_pb2.HelloResp(Result="Hey, {}!".format(request.Name)) 16 | 17 | def SayHelloStrict(self, request, context): 18 | if len(request.Name) >= 10: 19 | msg = 'Length of `Name` cannot be more than 10 characters' 20 | context.set_details(msg) 21 | context.set_code(grpc.StatusCode.INVALID_ARGUMENT) 22 | return hello_pb2.HelloResp() 23 | 24 | return hello_pb2.HelloResp(Result="Hey, {}!".format(request.Name)) 25 | 26 | 27 | def serve(): 28 | server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) 29 | hello_pb2_grpc.add_HelloServiceServicer_to_server(HelloServicer(), server) 30 | server.add_insecure_port('[::]:50051') 31 | server.start() 32 | try: 33 | while True: 34 | time.sleep(_ONE_DAY_IN_SECONDS) 35 | except KeyboardInterrupt: 36 | server.stop(0) 37 | 38 | 39 | if __name__ == '__main__': 40 | serve() 41 | -------------------------------------------------------------------------------- /ruby/README.md: -------------------------------------------------------------------------------- 1 | # Ruby gRPC 2 | 3 | ## Instructions 4 | 5 | Install the dependencies: 6 | 7 | $ gem install grpc 8 | $ gem install grpc-tools 9 | 10 | Generate protobuf files: 11 | 12 | $ grpc_tools_ruby_protoc -I ../ --ruby_out=. --grpc_out=. ../hello.proto 13 | 14 | Run the server and client: 15 | 16 | $ ruby server.rb & 17 | $ ruby client.rb 18 | 19 | Note: 20 | 21 | There is some issue the way gRPC files are being generated, the class seems have capitalised symbols, which is not allowed. So I had to edit them manually. -------------------------------------------------------------------------------- /ruby/client.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | this_dir = File.expand_path(File.dirname(__FILE__)) 4 | $LOAD_PATH.unshift(this_dir) unless $LOAD_PATH.include?(this_dir) 5 | 6 | require 'grpc' 7 | require_relative 'hello_services_pb' 8 | 9 | def main 10 | stub = Hello::HelloService::Stub.new('localhost:50051', :this_channel_is_insecure) 11 | response = stub.say_hello(Hello::HelloReq.new(name: 'Euler')) 12 | p "#{response.result}" 13 | 14 | # lets try the failing case 15 | begin 16 | response = stub.say_hello_strict(Hello::HelloReq.new(name: 'Leonhard Euler')) 17 | rescue GRPC::BadStatus => e 18 | # ouch! 19 | # lets print the gRPC error message 20 | # which is "Length of `Name` cannot be more than 10 characters" 21 | puts "#{e.details}" 22 | # Want its int version for some reason? 23 | # you shouldn't actually do this, but if you need for debugging, 24 | # you can access `e.code` which will give you `3` 25 | # 26 | # puts "#{e.code}" 27 | # 28 | # Want to take specific action based on specific error? 29 | if e.code == GRPC::Core::StatusCodes::INVALID_ARGUMENT 30 | # do your thing here 31 | end 32 | end 33 | end 34 | 35 | main 36 | -------------------------------------------------------------------------------- /ruby/hello_pb.rb: -------------------------------------------------------------------------------- 1 | # Generated by the protocol buffer compiler. DO NOT EDIT! 2 | # source: hello.proto 3 | 4 | require 'google/protobuf' 5 | 6 | Google::Protobuf::DescriptorPool.generated_pool.build do 7 | add_message "hello.HelloReq" do 8 | optional :name, :string, 1 9 | end 10 | add_message "hello.HelloResp" do 11 | optional :result, :string, 1 12 | end 13 | end 14 | 15 | module Hello 16 | HelloReq = Google::Protobuf::DescriptorPool.generated_pool.lookup("hello.HelloReq").msgclass 17 | HelloResp = Google::Protobuf::DescriptorPool.generated_pool.lookup("hello.HelloResp").msgclass 18 | end 19 | -------------------------------------------------------------------------------- /ruby/hello_services_pb.rb: -------------------------------------------------------------------------------- 1 | # Generated by the protocol buffer compiler. DO NOT EDIT! 2 | # Source: hello.proto for package 'hello' 3 | 4 | require 'grpc' 5 | require 'hello_pb' 6 | 7 | module Hello 8 | module HelloService 9 | class Service 10 | 11 | include GRPC::GenericService 12 | 13 | self.marshal_class_method = :encode 14 | self.unmarshal_class_method = :decode 15 | self.service_name = 'hello.HelloService' 16 | 17 | # This thing just says Hello to anyone 18 | # SayHello('Euler') -> Hello, Euler! 19 | rpc :SayHello, HelloReq, HelloResp 20 | # Strict Version responds only to requests which have `Name` length 21 | # less than 10 characters 22 | rpc :SayHelloStrict, HelloReq, HelloResp 23 | end 24 | 25 | Stub = Service.rpc_stub_class 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /ruby/server.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | this_dir = File.expand_path(File.dirname(__FILE__)) 4 | $LOAD_PATH.unshift(this_dir) unless $LOAD_PATH.include?(this_dir) 5 | 6 | require 'grpc' 7 | require 'hello_services_pb' 8 | 9 | class HelloServer < Hello::HelloService::Service 10 | 11 | def say_hello(hello_req, _unused_call) 12 | Hello::HelloResp.new(result: "Hey, #{hello_req.name}!") 13 | end 14 | 15 | def say_hello_strict(hello_req, _unused_call) 16 | if hello_req.name.length >= 10 17 | msg = 'Length of `Name` cannot be more than 10 characters' 18 | raise GRPC::BadStatus.new(GRPC::Core::StatusCodes::INVALID_ARGUMENT, msg) 19 | end 20 | Hello::HelloResp.new(result: "Hey, #{hello_req.name}!") 21 | end 22 | 23 | end 24 | 25 | def main 26 | s = GRPC::RpcServer.new 27 | s.add_http2_port('0.0.0.0:50051', :this_port_is_insecure) 28 | s.handle(HelloServer) 29 | s.run_till_terminated 30 | end 31 | 32 | main 33 | -------------------------------------------------------------------------------- /rust/.gitignore: -------------------------------------------------------------------------------- 1 | !/Cargo.lock 2 | /src/proto/* 3 | !/src/proto/mod.rs 4 | target 5 | -------------------------------------------------------------------------------- /rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust" 3 | version = "0.1.0" 4 | authors = ["Rodolphe Marques "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | grpcio = { version = "0.4.1", default-features = false, features = ["protobuf-codec"] } 9 | protobuf = "2.0.2" 10 | futures = "0.1.25" 11 | 12 | [build-dependencies] 13 | protoc-grpcio = "0.3.1" 14 | 15 | [[bin]] 16 | name = "server" 17 | path = "src/server.rs" 18 | 19 | [[bin]] 20 | name = "client" 21 | path = "src/client.rs" 22 | -------------------------------------------------------------------------------- /rust/README.md: -------------------------------------------------------------------------------- 1 | # Rust gRPC 2 | 3 | gRPC-errors example using rust. 4 | 5 | It uses the [grpc-rs](https://github.com/pingcap/grpc-rs) crate which is a rust 6 | wrapper of [grpc](https://github.com/grpc/grpc). 7 | 8 | ## System requirements 9 | 10 | - CMake >= 3.8.0 11 | - rustup: You can install `rustup` on your system follow the [install 12 | instructions](https://doc.rust-lang.org/book/ch01-01-installation.html) of 13 | the rust documentation. 14 | 15 | ## Instructions 16 | 17 | The generation of the protobuf files is integrated into the cargo build stage 18 | (see [build.rs](./build.rs)) so there is no extra step to generate the files. 19 | 20 | Run server: 21 | ```bash 22 | $ cargo run --bin server 23 | ``` 24 | 25 | Run client: 26 | ```bash 27 | $ cargo run --bin client 28 | ``` 29 | 30 | 31 | -------------------------------------------------------------------------------- /rust/build.rs: -------------------------------------------------------------------------------- 1 | use std::path::Path; 2 | 3 | fn main() { 4 | let proto_out = "src/proto"; 5 | let proto_root = Path::new("../").canonicalize().unwrap(); 6 | let proto_file = Path::new("../hello.proto").canonicalize().unwrap(); 7 | 8 | protoc_grpcio::compile_grpc_protos( 9 | &[proto_file], 10 | &[proto_root], 11 | &proto_out 12 | ).expect("Failed to compile gRPC definitions!"); 13 | } 14 | -------------------------------------------------------------------------------- /rust/src/client.rs: -------------------------------------------------------------------------------- 1 | use std::sync::Arc; 2 | 3 | use grpcio::{ChannelBuilder, EnvBuilder}; 4 | 5 | use rust::proto::hello::HelloReq; 6 | use rust::proto::hello_grpc::HelloServiceClient; 7 | 8 | fn main() { 9 | let env = Arc::new(EnvBuilder::new().build()); 10 | let ch = ChannelBuilder::new(env).connect("localhost:50051"); 11 | let client = HelloServiceClient::new(ch); 12 | 13 | let mut req = HelloReq::new(); 14 | req.set_Name("Euler".to_owned()); 15 | 16 | let reply = client.say_hello(&req); 17 | println!("{:?}", reply); 18 | 19 | // the failing case 20 | let mut req = HelloReq::new(); 21 | req.set_Name("Leonhard Euler".to_owned()); 22 | 23 | let reply = client.say_hello_strict(&req); 24 | println!("{:?}", reply); 25 | } 26 | -------------------------------------------------------------------------------- /rust/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod proto; 2 | 3 | use crate::proto::hello::{HelloReq, HelloResp}; 4 | use crate::proto::hello_grpc::HelloService; 5 | 6 | use futures::Future; 7 | use grpcio::{RpcContext, RpcStatus, RpcStatusCode, UnarySink}; 8 | 9 | #[derive(Clone)] 10 | pub struct GrpcHelloService; 11 | 12 | impl HelloService for GrpcHelloService { 13 | fn say_hello(&mut self, ctx: RpcContext, req: HelloReq, sink: UnarySink) { 14 | let name = req.get_Name(); 15 | let reply_msg = format!("Hey, {}!", name); 16 | 17 | let mut reply = HelloResp::new(); 18 | reply.set_Result(reply_msg); 19 | 20 | let f = sink 21 | .success(reply) 22 | .map_err(move |e| println!("failed to reply {:?}: {:?}", req, e)); 23 | 24 | ctx.spawn(f); 25 | } 26 | 27 | fn say_hello_strict(&mut self, ctx: RpcContext, req: HelloReq, sink: UnarySink) { 28 | let name = req.get_Name(); 29 | 30 | if name.len() >= 10 { 31 | let reply_msg = "Length of `Name` cannot be more than 10 characters"; 32 | 33 | let f = sink 34 | .fail(RpcStatus::new( 35 | RpcStatusCode::InvalidArgument, 36 | Some(reply_msg.to_string()), 37 | )) 38 | .map_err(move |e| println!("failed to reply {:?}: {:?}", req, e)); 39 | 40 | ctx.spawn(f); 41 | } else { 42 | let reply_msg = format!("Hey, {}!", name); 43 | 44 | let mut reply = HelloResp::new(); 45 | reply.set_Result(reply_msg); 46 | 47 | let f = sink 48 | .success(reply) 49 | .map_err(move |e| println!("failed to reply {:?}: {:?}", req, e)); 50 | 51 | ctx.spawn(f); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /rust/src/proto/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod hello; 2 | pub mod hello_grpc; 3 | -------------------------------------------------------------------------------- /rust/src/server.rs: -------------------------------------------------------------------------------- 1 | use std::io::Read; 2 | use std::sync::Arc; 3 | use std::{io, thread}; 4 | 5 | use futures::sync::oneshot; 6 | use futures::Future; 7 | use grpcio::{Environment, ServerBuilder}; 8 | 9 | use rust::proto::hello_grpc; 10 | use rust::GrpcHelloService; 11 | 12 | fn main() { 13 | let env = Arc::new(Environment::new(1)); 14 | let service = hello_grpc::create_hello_service(GrpcHelloService); 15 | 16 | let mut server = ServerBuilder::new(env) 17 | .register_service(service) 18 | .bind("0.0.0.0", 50051) 19 | .build() 20 | .unwrap(); 21 | 22 | server.start(); 23 | for &(ref host, port) in server.bind_addrs() { 24 | println!("Server listening on {}:{}", host, port); 25 | } 26 | 27 | let (tx, rx) = oneshot::channel(); 28 | thread::spawn(move || { 29 | println!("Press ENTER to exit..."); 30 | let _ = io::stdin().read(&mut [0]).unwrap(); 31 | tx.send(()) 32 | }); 33 | 34 | let _ = rx.wait(); 35 | let _ = server.shutdown().wait(); 36 | } 37 | -------------------------------------------------------------------------------- /scala/.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .idea/* 3 | target 4 | -------------------------------------------------------------------------------- /scala/README.md: -------------------------------------------------------------------------------- 1 | # Scala gRPC 2 | 3 | ## Instructions 4 | 5 | Scala uses the [ScalaPB](https://github.com/scalapb/ScalaPB) SBT plugin, which can integrate with SBT and generate idiomadic Scala code for those that do not want to use grpc-java directly 6 | 7 | To run, in *separate terminals*: 8 | 9 | $ sbt "runMain hello.server.HelloServer" 10 | $ sbt "runMain hello.client.HelloClient" 11 | -------------------------------------------------------------------------------- /scala/build.sbt: -------------------------------------------------------------------------------- 1 | name := "scala" 2 | 3 | version := "0.1" 4 | 5 | scalaVersion := "2.11.12" 6 | 7 | // these two is to make sure we only compile the one proto in the root of the repo and ignore other protos that may 8 | // get pulled in from npm install, virtualenvs in python, etc 9 | includeFilter in PB.generate := "hello.proto" 10 | PB.protoSources in Compile := Seq(baseDirectory.value / "..") 11 | 12 | PB.targets in Compile := Seq( 13 | scalapb.gen() -> (sourceManaged in Compile).value 14 | ) 15 | 16 | libraryDependencies ++= Seq( 17 | "io.grpc" % "grpc-netty" % scalapb.compiler.Version.grpcJavaVersion, 18 | "com.thesamet.scalapb" %% "scalapb-runtime-grpc" % scalapb.compiler.Version.scalapbVersion 19 | ) 20 | 21 | -------------------------------------------------------------------------------- /scala/project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version = 0.13.17 -------------------------------------------------------------------------------- /scala/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("com.thesamet" % "sbt-protoc" % "0.99.18") 2 | 3 | libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.7.1" 4 | -------------------------------------------------------------------------------- /scala/src/main/scala/hello/client/HelloClient.scala: -------------------------------------------------------------------------------- 1 | package hello.client 2 | 3 | import hello.hello.HelloServiceGrpc.{HelloServiceBlockingClient, HelloServiceStub} 4 | import hello.hello.{HelloReq, HelloResp, HelloServiceGrpc} 5 | import io.grpc.{ManagedChannelBuilder, StatusRuntimeException} 6 | 7 | import scala.concurrent.{Await, ExecutionContext, Future} 8 | import scala.concurrent.duration._ 9 | 10 | object HelloClient { 11 | val goodReq = HelloReq("Euler") 12 | val badReq = HelloReq("Leonhard Euler") 13 | 14 | def main(args: Array[String]): Unit = { 15 | val channel = ManagedChannelBuilder 16 | .forAddress("localhost", 50051) 17 | .usePlaintext(true) 18 | .build() 19 | 20 | val asyncStub = HelloServiceGrpc.stub(channel) 21 | val blockingStub: HelloServiceGrpc.HelloServiceBlockingStub = HelloServiceGrpc.blockingStub(channel) 22 | implicit val executionContext = ExecutionContext.global 23 | 24 | blockingExample(blockingStub) 25 | asyncExample(asyncStub) 26 | } 27 | 28 | def blockingExample(stub: HelloServiceBlockingClient): Unit = { 29 | println("Starting blocking example") 30 | val syncResp = stub.sayHello(goodReq) 31 | println(syncResp.result) 32 | 33 | try { 34 | stub.sayHelloStrict(badReq) 35 | } catch { 36 | case rtEx: StatusRuntimeException => 37 | println(s"Blocking implementation description ${rtEx.getStatus.getDescription} and code ${rtEx.getStatus.getCode}") 38 | } 39 | } 40 | 41 | def asyncExample(stub: HelloServiceStub)(implicit ec: ExecutionContext): Unit = { 42 | println("Starting async example") 43 | val f1: Future[HelloResp] = stub.sayHello(goodReq) 44 | val f2: Future[HelloResp] = stub.sayHelloStrict(badReq) 45 | 46 | f1.onSuccess { 47 | case HelloResp(result: String) => println(result) 48 | } 49 | f2 onFailure { 50 | case rtEx: StatusRuntimeException => 51 | println(s"Async implementation description ${rtEx.getStatus.getDescription} and code ${rtEx.getStatus.getCode}") 52 | } 53 | 54 | Await.ready(Future.sequence(Seq(f1, f2)), 1.second) 55 | } 56 | } 57 | 58 | -------------------------------------------------------------------------------- /scala/src/main/scala/hello/server/HelloServer.scala: -------------------------------------------------------------------------------- 1 | package hello.server 2 | 3 | import hello.hello.{HelloReq, HelloResp, HelloServiceGrpc} 4 | import io.grpc.{ServerBuilder, Status} 5 | 6 | import scala.concurrent.{ExecutionContext, Future} 7 | 8 | object HelloServer { 9 | def main(args: Array[String]): Unit = { 10 | val svc = HelloServiceGrpc.bindService(new HelloServer(), ExecutionContext.global) 11 | ServerBuilder 12 | .forPort(50051) 13 | .addService(svc) 14 | .build() 15 | .start() 16 | .awaitTermination() 17 | } 18 | } 19 | 20 | class HelloServer extends HelloServiceGrpc.HelloService { 21 | override def sayHello(request: HelloReq): Future[HelloResp] = { 22 | Future.successful(HelloResp(result=s"Hello ${request.name}")) 23 | } 24 | 25 | override def sayHelloStrict(request: HelloReq): Future[HelloResp] = { 26 | if (request.name.length >= 10) { 27 | Future.failed( 28 | Status 29 | .INVALID_ARGUMENT 30 | .augmentDescription("Length of `Name` cannot be more than 10 characters") 31 | .asRuntimeException() 32 | ) 33 | } else { 34 | Future.successful(HelloResp(result=s"Hello ${request.name}")) 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /swift/HelloClient/Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #ifndef Bridging_Header_h 2 | #define Bridging_Header_h 3 | 4 | #import 5 | #import 6 | #import 7 | 8 | #endif /* Bridging_Header_h */ 9 | -------------------------------------------------------------------------------- /swift/HelloClient/Hello.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod spec lint Hello.podspec' to ensure this is a 3 | # valid spec and to remove all comments including this before submitting the spec. 4 | # 5 | # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html 6 | # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | 11 | # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 12 | # 13 | # These will help people to find your library, and whilst it 14 | # can feel like a chore to fill in it's definitely to your advantage. The 15 | # summary should be tweet-length, and the description more in depth. 16 | # 17 | 18 | s.name = "Hello" 19 | s.version = "0.0.1" 20 | s.summary = "A handy guide to gRPC errors." 21 | s.homepage = "http://avi.im/grpc-errors" 22 | 23 | # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 24 | # 25 | # Licensing your code is important. See http://choosealicense.com for more info. 26 | # CocoaPods will detect a license file if there is a named LICENSE* 27 | # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'. 28 | # 29 | 30 | s.license = "MIT" 31 | # s.license = { :type => "MIT", :file => "FILE_LICENSE" } 32 | 33 | 34 | # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 35 | # 36 | # Specify the authors of the library, with email addresses. Email addresses 37 | # of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also 38 | # accepts just a name if you'd rather not provide an email address. 39 | # 40 | # Specify a social_media_url where others can refer to, for example a twitter 41 | # profile URL. 42 | # 43 | 44 | s.author = { "Avinash Sajjanshetty" => "hi@avi.im" } 45 | # Or just: s.author = "Avinash Sajjanshetty" 46 | # s.authors = { "Avinash Sajjanshetty" => "hi@avi.im" } 47 | # s.social_media_url = "http://twitter.com/iavins" 48 | 49 | # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 50 | # 51 | # If this Pod runs only on iOS or OS X, then specify the platform and 52 | # the deployment target. You can optionally include the target after the platform. 53 | # 54 | 55 | # s.platform = :ios 56 | # s.platform = :ios, "5.0" 57 | 58 | # When using multiple platforms 59 | s.ios.deployment_target = "9.1" 60 | s.osx.deployment_target = "10.10" 61 | # s.watchos.deployment_target = "2.0" 62 | # s.tvos.deployment_target = "9.0" 63 | 64 | 65 | # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 66 | # 67 | # Specify the location from where the source should be retrieved. 68 | # Supports git, hg, bzr, svn and HTTP. 69 | # 70 | 71 | s.source = { :git => "https://github.com/avinassh/grpc-errors.git" } 72 | 73 | 74 | # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 75 | # 76 | # CocoaPods is smart about how it includes source code. For source files 77 | # giving a folder will include any swift, h, m, mm, c & cpp files. 78 | # For header files it will include any header in the folder. 79 | # Not including the public_header_files will make all headers public. 80 | # 81 | # Base directory where the .proto files are. 82 | src = "../../" 83 | 84 | # Run protoc with the Objective-C and gRPC plugins to generate protocol messages and gRPC clients. 85 | s.dependency "!ProtoCompiler-gRPCPlugin", "~> 1.0" 86 | 87 | # Pods directory corresponding to this app's Podfile, relative to the location of this podspec. 88 | pods_root = 'Pods' 89 | 90 | # Path where Cocoapods downloads protoc and the gRPC plugin. 91 | protoc_dir = "#{pods_root}/!ProtoCompiler" 92 | protoc = "#{protoc_dir}/protoc" 93 | plugin = "#{pods_root}/!ProtoCompiler-gRPCPlugin/grpc_objective_c_plugin" 94 | 95 | # Directory where the generated files will be placed. 96 | dir = "#{pods_root}/#{s.name}" 97 | 98 | s.prepare_command = <<-CMD 99 | mkdir -p #{dir} 100 | #{protoc} \ 101 | --plugin=protoc-gen-grpc=#{plugin} \ 102 | --objc_out=#{dir} \ 103 | --grpc_out=#{dir} \ 104 | -I #{src} \ 105 | -I #{protoc_dir} \ 106 | #{src}/hello.proto 107 | CMD 108 | 109 | # Files generated by protoc 110 | s.subspec "Messages" do |ms| 111 | ms.source_files = "#{dir}/*.pbobjc.{h,m}", "#{dir}/**/*.pbobjc.{h,m}" 112 | ms.header_mappings_dir = dir 113 | ms.requires_arc = false 114 | # The generated files depend on the protobuf runtime. 115 | ms.dependency "Protobuf" 116 | end 117 | 118 | # Files generated by the gRPC plugin 119 | s.subspec "Services" do |ss| 120 | ss.source_files = "#{dir}/*.pbrpc.{h,m}", "#{dir}/**/*.pbrpc.{h,m}" 121 | ss.header_mappings_dir = dir 122 | ss.requires_arc = true 123 | # The generated files depend on the gRPC runtime, and on the files generated by protoc. 124 | ss.dependency "gRPC-ProtoRPC" 125 | ss.dependency "#{s.name}/Messages" 126 | end 127 | 128 | s.pod_target_xcconfig = { 129 | # This is needed by all pods that depend on Protobuf: 130 | 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1', 131 | # This is needed by all pods that depend on gRPC-RxLibrary: 132 | 'CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES' => 'YES', 133 | } 134 | end 135 | -------------------------------------------------------------------------------- /swift/HelloClient/HelloClient.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 27CF15E22F19736F74915D10 /* Pods_HelloClient.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 745CAF7BC3F4726AC2851A27 /* Pods_HelloClient.framework */; }; 11 | 825BE6141E8BAA6200A6E519 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 825BE6131E8BAA6200A6E519 /* AppDelegate.swift */; }; 12 | 825BE6161E8BAA6200A6E519 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 825BE6151E8BAA6200A6E519 /* ViewController.swift */; }; 13 | 825BE6191E8BAA6200A6E519 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 825BE6171E8BAA6200A6E519 /* Main.storyboard */; }; 14 | 825BE61B1E8BAA6200A6E519 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 825BE61A1E8BAA6200A6E519 /* Assets.xcassets */; }; 15 | 825BE61E1E8BAA6200A6E519 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 825BE61C1E8BAA6200A6E519 /* LaunchScreen.storyboard */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | 745CAF7BC3F4726AC2851A27 /* Pods_HelloClient.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_HelloClient.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | 7E3C8787F4D8C2C49AB75039 /* Pods-HelloClient.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HelloClient.release.xcconfig"; path = "Pods/Target Support Files/Pods-HelloClient/Pods-HelloClient.release.xcconfig"; sourceTree = ""; }; 21 | 825BE6101E8BAA6200A6E519 /* HelloClient.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HelloClient.app; sourceTree = BUILT_PRODUCTS_DIR; }; 22 | 825BE6131E8BAA6200A6E519 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 23 | 825BE6151E8BAA6200A6E519 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 24 | 825BE6181E8BAA6200A6E519 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 25 | 825BE61A1E8BAA6200A6E519 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 26 | 825BE61D1E8BAA6200A6E519 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 27 | 825BE61F1E8BAA6200A6E519 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 28 | 9219593C9D2A342F654667C7 /* Pods-HelloClient.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HelloClient.debug.xcconfig"; path = "Pods/Target Support Files/Pods-HelloClient/Pods-HelloClient.debug.xcconfig"; sourceTree = ""; }; 29 | /* End PBXFileReference section */ 30 | 31 | /* Begin PBXFrameworksBuildPhase section */ 32 | 825BE60D1E8BAA6200A6E519 /* Frameworks */ = { 33 | isa = PBXFrameworksBuildPhase; 34 | buildActionMask = 2147483647; 35 | files = ( 36 | 27CF15E22F19736F74915D10 /* Pods_HelloClient.framework in Frameworks */, 37 | ); 38 | runOnlyForDeploymentPostprocessing = 0; 39 | }; 40 | /* End PBXFrameworksBuildPhase section */ 41 | 42 | /* Begin PBXGroup section */ 43 | 1128C698162F00A6861AD0FB /* Frameworks */ = { 44 | isa = PBXGroup; 45 | children = ( 46 | 745CAF7BC3F4726AC2851A27 /* Pods_HelloClient.framework */, 47 | ); 48 | name = Frameworks; 49 | sourceTree = ""; 50 | }; 51 | 46A4287C4E0B0403CE88674C /* Pods */ = { 52 | isa = PBXGroup; 53 | children = ( 54 | 9219593C9D2A342F654667C7 /* Pods-HelloClient.debug.xcconfig */, 55 | 7E3C8787F4D8C2C49AB75039 /* Pods-HelloClient.release.xcconfig */, 56 | ); 57 | name = Pods; 58 | sourceTree = ""; 59 | }; 60 | 825BE6071E8BAA6200A6E519 = { 61 | isa = PBXGroup; 62 | children = ( 63 | 825BE6121E8BAA6200A6E519 /* HelloClient */, 64 | 825BE6111E8BAA6200A6E519 /* Products */, 65 | 46A4287C4E0B0403CE88674C /* Pods */, 66 | 1128C698162F00A6861AD0FB /* Frameworks */, 67 | ); 68 | sourceTree = ""; 69 | }; 70 | 825BE6111E8BAA6200A6E519 /* Products */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | 825BE6101E8BAA6200A6E519 /* HelloClient.app */, 74 | ); 75 | name = Products; 76 | sourceTree = ""; 77 | }; 78 | 825BE6121E8BAA6200A6E519 /* HelloClient */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | 825BE6131E8BAA6200A6E519 /* AppDelegate.swift */, 82 | 825BE6151E8BAA6200A6E519 /* ViewController.swift */, 83 | 825BE6171E8BAA6200A6E519 /* Main.storyboard */, 84 | 825BE61A1E8BAA6200A6E519 /* Assets.xcassets */, 85 | 825BE61C1E8BAA6200A6E519 /* LaunchScreen.storyboard */, 86 | 825BE61F1E8BAA6200A6E519 /* Info.plist */, 87 | ); 88 | path = HelloClient; 89 | sourceTree = ""; 90 | }; 91 | /* End PBXGroup section */ 92 | 93 | /* Begin PBXNativeTarget section */ 94 | 825BE60F1E8BAA6200A6E519 /* HelloClient */ = { 95 | isa = PBXNativeTarget; 96 | buildConfigurationList = 825BE6221E8BAA6200A6E519 /* Build configuration list for PBXNativeTarget "HelloClient" */; 97 | buildPhases = ( 98 | C7A7B4060A6C82DEB6B32531 /* [CP] Check Pods Manifest.lock */, 99 | 825BE60C1E8BAA6200A6E519 /* Sources */, 100 | 825BE60D1E8BAA6200A6E519 /* Frameworks */, 101 | 825BE60E1E8BAA6200A6E519 /* Resources */, 102 | AAAC03086C57234A8BA0B82C /* [CP] Embed Pods Frameworks */, 103 | 905CDBDD2FB92B892111A2E3 /* [CP] Copy Pods Resources */, 104 | ); 105 | buildRules = ( 106 | ); 107 | dependencies = ( 108 | ); 109 | name = HelloClient; 110 | productName = HelloClient; 111 | productReference = 825BE6101E8BAA6200A6E519 /* HelloClient.app */; 112 | productType = "com.apple.product-type.application"; 113 | }; 114 | /* End PBXNativeTarget section */ 115 | 116 | /* Begin PBXProject section */ 117 | 825BE6081E8BAA6200A6E519 /* Project object */ = { 118 | isa = PBXProject; 119 | attributes = { 120 | LastSwiftUpdateCheck = 0730; 121 | LastUpgradeCheck = 0730; 122 | ORGANIZATIONNAME = avi.im; 123 | TargetAttributes = { 124 | 825BE60F1E8BAA6200A6E519 = { 125 | CreatedOnToolsVersion = 7.3.1; 126 | }; 127 | }; 128 | }; 129 | buildConfigurationList = 825BE60B1E8BAA6200A6E519 /* Build configuration list for PBXProject "HelloClient" */; 130 | compatibilityVersion = "Xcode 3.2"; 131 | developmentRegion = English; 132 | hasScannedForEncodings = 0; 133 | knownRegions = ( 134 | en, 135 | Base, 136 | ); 137 | mainGroup = 825BE6071E8BAA6200A6E519; 138 | productRefGroup = 825BE6111E8BAA6200A6E519 /* Products */; 139 | projectDirPath = ""; 140 | projectRoot = ""; 141 | targets = ( 142 | 825BE60F1E8BAA6200A6E519 /* HelloClient */, 143 | ); 144 | }; 145 | /* End PBXProject section */ 146 | 147 | /* Begin PBXResourcesBuildPhase section */ 148 | 825BE60E1E8BAA6200A6E519 /* Resources */ = { 149 | isa = PBXResourcesBuildPhase; 150 | buildActionMask = 2147483647; 151 | files = ( 152 | 825BE61E1E8BAA6200A6E519 /* LaunchScreen.storyboard in Resources */, 153 | 825BE61B1E8BAA6200A6E519 /* Assets.xcassets in Resources */, 154 | 825BE6191E8BAA6200A6E519 /* Main.storyboard in Resources */, 155 | ); 156 | runOnlyForDeploymentPostprocessing = 0; 157 | }; 158 | /* End PBXResourcesBuildPhase section */ 159 | 160 | /* Begin PBXShellScriptBuildPhase section */ 161 | 905CDBDD2FB92B892111A2E3 /* [CP] Copy Pods Resources */ = { 162 | isa = PBXShellScriptBuildPhase; 163 | buildActionMask = 2147483647; 164 | files = ( 165 | ); 166 | inputPaths = ( 167 | ); 168 | name = "[CP] Copy Pods Resources"; 169 | outputPaths = ( 170 | ); 171 | runOnlyForDeploymentPostprocessing = 0; 172 | shellPath = /bin/sh; 173 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-HelloClient/Pods-HelloClient-resources.sh\"\n"; 174 | showEnvVarsInLog = 0; 175 | }; 176 | AAAC03086C57234A8BA0B82C /* [CP] Embed Pods Frameworks */ = { 177 | isa = PBXShellScriptBuildPhase; 178 | buildActionMask = 2147483647; 179 | files = ( 180 | ); 181 | inputPaths = ( 182 | ); 183 | name = "[CP] Embed Pods Frameworks"; 184 | outputPaths = ( 185 | ); 186 | runOnlyForDeploymentPostprocessing = 0; 187 | shellPath = /bin/sh; 188 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-HelloClient/Pods-HelloClient-frameworks.sh\"\n"; 189 | showEnvVarsInLog = 0; 190 | }; 191 | C7A7B4060A6C82DEB6B32531 /* [CP] Check Pods Manifest.lock */ = { 192 | isa = PBXShellScriptBuildPhase; 193 | buildActionMask = 2147483647; 194 | files = ( 195 | ); 196 | inputPaths = ( 197 | ); 198 | name = "[CP] Check Pods Manifest.lock"; 199 | outputPaths = ( 200 | ); 201 | runOnlyForDeploymentPostprocessing = 0; 202 | shellPath = /bin/sh; 203 | shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; 204 | showEnvVarsInLog = 0; 205 | }; 206 | /* End PBXShellScriptBuildPhase section */ 207 | 208 | /* Begin PBXSourcesBuildPhase section */ 209 | 825BE60C1E8BAA6200A6E519 /* Sources */ = { 210 | isa = PBXSourcesBuildPhase; 211 | buildActionMask = 2147483647; 212 | files = ( 213 | 825BE6161E8BAA6200A6E519 /* ViewController.swift in Sources */, 214 | 825BE6141E8BAA6200A6E519 /* AppDelegate.swift in Sources */, 215 | ); 216 | runOnlyForDeploymentPostprocessing = 0; 217 | }; 218 | /* End PBXSourcesBuildPhase section */ 219 | 220 | /* Begin PBXVariantGroup section */ 221 | 825BE6171E8BAA6200A6E519 /* Main.storyboard */ = { 222 | isa = PBXVariantGroup; 223 | children = ( 224 | 825BE6181E8BAA6200A6E519 /* Base */, 225 | ); 226 | name = Main.storyboard; 227 | sourceTree = ""; 228 | }; 229 | 825BE61C1E8BAA6200A6E519 /* LaunchScreen.storyboard */ = { 230 | isa = PBXVariantGroup; 231 | children = ( 232 | 825BE61D1E8BAA6200A6E519 /* Base */, 233 | ); 234 | name = LaunchScreen.storyboard; 235 | sourceTree = ""; 236 | }; 237 | /* End PBXVariantGroup section */ 238 | 239 | /* Begin XCBuildConfiguration section */ 240 | 825BE6201E8BAA6200A6E519 /* Debug */ = { 241 | isa = XCBuildConfiguration; 242 | buildSettings = { 243 | ALWAYS_SEARCH_USER_PATHS = NO; 244 | CLANG_ANALYZER_NONNULL = YES; 245 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 246 | CLANG_CXX_LIBRARY = "libc++"; 247 | CLANG_ENABLE_MODULES = YES; 248 | CLANG_ENABLE_OBJC_ARC = YES; 249 | CLANG_WARN_BOOL_CONVERSION = YES; 250 | CLANG_WARN_CONSTANT_CONVERSION = YES; 251 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 252 | CLANG_WARN_EMPTY_BODY = YES; 253 | CLANG_WARN_ENUM_CONVERSION = YES; 254 | CLANG_WARN_INT_CONVERSION = YES; 255 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 256 | CLANG_WARN_UNREACHABLE_CODE = YES; 257 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 258 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 259 | COPY_PHASE_STRIP = NO; 260 | DEBUG_INFORMATION_FORMAT = dwarf; 261 | ENABLE_STRICT_OBJC_MSGSEND = YES; 262 | ENABLE_TESTABILITY = YES; 263 | GCC_C_LANGUAGE_STANDARD = gnu99; 264 | GCC_DYNAMIC_NO_PIC = NO; 265 | GCC_NO_COMMON_BLOCKS = YES; 266 | GCC_OPTIMIZATION_LEVEL = 0; 267 | GCC_PREPROCESSOR_DEFINITIONS = ( 268 | "DEBUG=1", 269 | "$(inherited)", 270 | ); 271 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 272 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 273 | GCC_WARN_UNDECLARED_SELECTOR = YES; 274 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 275 | GCC_WARN_UNUSED_FUNCTION = YES; 276 | GCC_WARN_UNUSED_VARIABLE = YES; 277 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 278 | MTL_ENABLE_DEBUG_INFO = YES; 279 | ONLY_ACTIVE_ARCH = YES; 280 | SDKROOT = iphoneos; 281 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 282 | }; 283 | name = Debug; 284 | }; 285 | 825BE6211E8BAA6200A6E519 /* Release */ = { 286 | isa = XCBuildConfiguration; 287 | buildSettings = { 288 | ALWAYS_SEARCH_USER_PATHS = NO; 289 | CLANG_ANALYZER_NONNULL = YES; 290 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 291 | CLANG_CXX_LIBRARY = "libc++"; 292 | CLANG_ENABLE_MODULES = YES; 293 | CLANG_ENABLE_OBJC_ARC = YES; 294 | CLANG_WARN_BOOL_CONVERSION = YES; 295 | CLANG_WARN_CONSTANT_CONVERSION = YES; 296 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 297 | CLANG_WARN_EMPTY_BODY = YES; 298 | CLANG_WARN_ENUM_CONVERSION = YES; 299 | CLANG_WARN_INT_CONVERSION = YES; 300 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 301 | CLANG_WARN_UNREACHABLE_CODE = YES; 302 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 303 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 304 | COPY_PHASE_STRIP = NO; 305 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 306 | ENABLE_NS_ASSERTIONS = NO; 307 | ENABLE_STRICT_OBJC_MSGSEND = YES; 308 | GCC_C_LANGUAGE_STANDARD = gnu99; 309 | GCC_NO_COMMON_BLOCKS = YES; 310 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 311 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 312 | GCC_WARN_UNDECLARED_SELECTOR = YES; 313 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 314 | GCC_WARN_UNUSED_FUNCTION = YES; 315 | GCC_WARN_UNUSED_VARIABLE = YES; 316 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 317 | MTL_ENABLE_DEBUG_INFO = NO; 318 | SDKROOT = iphoneos; 319 | VALIDATE_PRODUCT = YES; 320 | }; 321 | name = Release; 322 | }; 323 | 825BE6231E8BAA6200A6E519 /* Debug */ = { 324 | isa = XCBuildConfiguration; 325 | baseConfigurationReference = 9219593C9D2A342F654667C7 /* Pods-HelloClient.debug.xcconfig */; 326 | buildSettings = { 327 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 328 | INFOPLIST_FILE = HelloClient/Info.plist; 329 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 330 | PRODUCT_BUNDLE_IDENTIFIER = im.avi.HelloClient; 331 | PRODUCT_NAME = "$(TARGET_NAME)"; 332 | SWIFT_OBJC_BRIDGING_HEADER = "Bridging-Header.h"; 333 | }; 334 | name = Debug; 335 | }; 336 | 825BE6241E8BAA6200A6E519 /* Release */ = { 337 | isa = XCBuildConfiguration; 338 | baseConfigurationReference = 7E3C8787F4D8C2C49AB75039 /* Pods-HelloClient.release.xcconfig */; 339 | buildSettings = { 340 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 341 | INFOPLIST_FILE = HelloClient/Info.plist; 342 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 343 | PRODUCT_BUNDLE_IDENTIFIER = im.avi.HelloClient; 344 | PRODUCT_NAME = "$(TARGET_NAME)"; 345 | SWIFT_OBJC_BRIDGING_HEADER = "Bridging-Header.h"; 346 | }; 347 | name = Release; 348 | }; 349 | /* End XCBuildConfiguration section */ 350 | 351 | /* Begin XCConfigurationList section */ 352 | 825BE60B1E8BAA6200A6E519 /* Build configuration list for PBXProject "HelloClient" */ = { 353 | isa = XCConfigurationList; 354 | buildConfigurations = ( 355 | 825BE6201E8BAA6200A6E519 /* Debug */, 356 | 825BE6211E8BAA6200A6E519 /* Release */, 357 | ); 358 | defaultConfigurationIsVisible = 0; 359 | defaultConfigurationName = Release; 360 | }; 361 | 825BE6221E8BAA6200A6E519 /* Build configuration list for PBXNativeTarget "HelloClient" */ = { 362 | isa = XCConfigurationList; 363 | buildConfigurations = ( 364 | 825BE6231E8BAA6200A6E519 /* Debug */, 365 | 825BE6241E8BAA6200A6E519 /* Release */, 366 | ); 367 | defaultConfigurationIsVisible = 0; 368 | defaultConfigurationName = Release; 369 | }; 370 | /* End XCConfigurationList section */ 371 | }; 372 | rootObject = 825BE6081E8BAA6200A6E519 /* Project object */; 373 | } 374 | -------------------------------------------------------------------------------- /swift/HelloClient/HelloClient.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /swift/HelloClient/HelloClient.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /swift/HelloClient/HelloClient/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | @UIApplicationMain 4 | class AppDelegate: UIResponder, UIApplicationDelegate { 5 | 6 | var window: UIWindow? 7 | 8 | 9 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 10 | // Override point for customization after application launch. 11 | return true 12 | } 13 | 14 | func applicationWillResignActive(application: UIApplication) { 15 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 16 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 17 | } 18 | 19 | func applicationDidEnterBackground(application: UIApplication) { 20 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 21 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 22 | } 23 | 24 | func applicationWillEnterForeground(application: UIApplication) { 25 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 26 | } 27 | 28 | func applicationDidBecomeActive(application: UIApplication) { 29 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 30 | } 31 | 32 | func applicationWillTerminate(application: UIApplication) { 33 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 34 | } 35 | 36 | 37 | } 38 | 39 | -------------------------------------------------------------------------------- /swift/HelloClient/HelloClient/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /swift/HelloClient/HelloClient/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /swift/HelloClient/HelloClient/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /swift/HelloClient/HelloClient/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /swift/HelloClient/HelloClient/ViewController.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import GRPCClient 3 | import Hello 4 | import grpc 5 | 6 | let kHostAddress = "localhost:50051" 7 | 8 | class ViewController: UIViewController { 9 | 10 | override func viewDidLoad() { 11 | super.viewDidLoad() 12 | // Do any additional setup after loading the view, typically from a nib. 13 | } 14 | 15 | override func didReceiveMemoryWarning() { 16 | super.didReceiveMemoryWarning() 17 | // Dispose of any resources that can be recreated. 18 | } 19 | 20 | override func viewWillAppear(animated: Bool) { 21 | super.viewWillAppear(animated) 22 | 23 | GRPCCall.useInsecureConnectionsForHost(kHostAddress) 24 | GRPCCall.setUserAgentPrefix("HelloWorld/1.0", forHost: kHostAddress) 25 | let client = HelloService(host: kHostAddress) 26 | let request = HelloReq() 27 | 28 | request.name = "Euler" 29 | client.sayHelloWithRequest(request, handler: {(response: HelloResp?, error: NSError?) in 30 | // ideally you should check for errors here too 31 | print(response!.result) 32 | }) 33 | 34 | // lets try the failing case 35 | request.name = "Leonhard Euler" 36 | client.sayHelloStrictWithRequest(request, handler: { (response: HelloResp?, error: NSError?) in 37 | if let response = response { 38 | print(response.result) 39 | } else { 40 | // ouch! 41 | // lets print the gRPC error message 42 | // which is "Length of `Name` cannot be more than 10 characters" 43 | let error = error! 44 | print(error.localizedDescription) 45 | // Want its int version for some reason? 46 | // you shouldn't actually do this, but if you need for debugging, 47 | // you can access `error.code` which will give you `3` 48 | print(error.code) 49 | // Want to take specific action based on specific error? 50 | if (Int32(error.code) == GRPC_STATUS_INVALID_ARGUMENT.rawValue) { 51 | // do your thing 52 | } 53 | } 54 | }) 55 | } 56 | } 57 | 58 | -------------------------------------------------------------------------------- /swift/HelloClient/Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment the next line to define a global platform for your project 2 | # platform :ios, '9.0' 3 | use_frameworks! 4 | 5 | target 'HelloClient' do 6 | # Uncomment the next line if you're using Swift or would like to use dynamic frameworks 7 | # use_frameworks! 8 | 9 | pod 'Hello', :path => '.' 10 | 11 | end 12 | -------------------------------------------------------------------------------- /swift/HelloClient/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - "!ProtoCompiler (3.2.0)": 3 | - Protobuf (~> 3.0) 4 | - "!ProtoCompiler-gRPCPlugin (1.2.0)": 5 | - "!ProtoCompiler (= 3.2.0)" 6 | - gRPC-ProtoRPC (= 1.2.0) 7 | - BoringSSL (8.0): 8 | - BoringSSL/Implementation (= 8.0) 9 | - BoringSSL/Interface (= 8.0) 10 | - BoringSSL/Implementation (8.0): 11 | - BoringSSL/Interface (= 8.0) 12 | - BoringSSL/Interface (8.0) 13 | - gRPC (1.2.0): 14 | - gRPC-Core (= 1.2.0) 15 | - gRPC-RxLibrary (= 1.2.0) 16 | - gRPC-Core (1.2.0): 17 | - gRPC-Core/Implementation (= 1.2.0) 18 | - gRPC-Core/Interface (= 1.2.0) 19 | - gRPC-Core/Implementation (1.2.0): 20 | - BoringSSL (~> 8.0) 21 | - gRPC-Core/Interface (= 1.2.0) 22 | - gRPC-Core/Interface (1.2.0) 23 | - gRPC-ProtoRPC (1.2.0): 24 | - gRPC (= 1.2.0) 25 | - gRPC-RxLibrary (= 1.2.0) 26 | - Protobuf (~> 3.0) 27 | - gRPC-RxLibrary (1.2.0) 28 | - Hello (0.0.1): 29 | - "!ProtoCompiler-gRPCPlugin (~> 1.0)" 30 | - Hello/Messages (= 0.0.1) 31 | - Hello/Services (= 0.0.1) 32 | - Hello/Messages (0.0.1): 33 | - "!ProtoCompiler-gRPCPlugin (~> 1.0)" 34 | - Protobuf 35 | - Hello/Services (0.0.1): 36 | - "!ProtoCompiler-gRPCPlugin (~> 1.0)" 37 | - gRPC-ProtoRPC 38 | - Hello/Messages 39 | - Protobuf (3.2.0) 40 | 41 | DEPENDENCIES: 42 | - Hello (from `.`) 43 | 44 | EXTERNAL SOURCES: 45 | Hello: 46 | :path: "." 47 | 48 | SPEC CHECKSUMS: 49 | "!ProtoCompiler": b66c7c0c1d911ad1490dcbfce30e1508739d8309 50 | "!ProtoCompiler-gRPCPlugin": e971571341f3b0e834e5592eb684de97b4978382 51 | BoringSSL: bafdcc5b88bac8ee45d7d207c507697f8c75b2fc 52 | gRPC: a7cdb9882aff57b83a1a96d7f1b902527abee3ff 53 | gRPC-Core: 81c86a58e64f62d5635697e9141b300ec6023132 54 | gRPC-ProtoRPC: 01d9c0ba95d63e402fa7a9251bd439c5dc5ccb2e 55 | gRPC-RxLibrary: 0da081dd7e8cd31313affcd65f36f80124b013c0 56 | Hello: e7fef98ea4761c9d2ed2af1e0d673d4028cad3a3 57 | Protobuf: 745f59e122e5de98d4d7ef291e264a0eef80f58e 58 | 59 | PODFILE CHECKSUM: eed473c9ad8e37206bb68394b4cc5b18ecaa5bd7 60 | 61 | COCOAPODS: 1.2.0 62 | -------------------------------------------------------------------------------- /swift/README.md: -------------------------------------------------------------------------------- 1 | # Swift gRPC 2 | 3 | Note that this example has only client version of Swift (written in Swift v2). For server, you can use any of the available server implementations. Following instructions show running a Go server. 4 | 5 | ## Instructions 6 | 7 | Install the dependencies and generate protobuf file: 8 | 9 | $ pod install 10 | 11 | Run the server ([instructions](../go/README.md)): 12 | 13 | $ ./server & 14 | 15 | Run the client: 16 | 17 | 1. Open `HelloClient.xcworkspace` 18 | 2. Run --------------------------------------------------------------------------------