├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── async_streaming_server.cc ├── async_streaming_server_alarm.cc ├── async_streaming_server_queue_to_back.cc ├── async_streaming_server_queue_to_front.cc ├── greeter_streaming_client.cc ├── hellostreamingworld.grpc.pb.cc ├── hellostreamingworld.grpc.pb.h ├── hellostreamingworld.pb.cc └── hellostreamingworld.pb.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015 gRPC authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | HOST_SYSTEM = $(shell uname | cut -f 1 -d_) 18 | SYSTEM ?= $(HOST_SYSTEM) 19 | CXX = g++ 20 | CPPFLAGS += `pkg-config --cflags protobuf grpc` 21 | CXXFLAGS += -std=c++11 22 | ifeq ($(SYSTEM),Darwin) 23 | LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++ grpc`\ 24 | -lgrpc++_reflection\ 25 | -ldl 26 | else 27 | LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++ grpc`\ 28 | -Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed\ 29 | -ldl 30 | endif 31 | PROTOC = protoc 32 | GRPC_CPP_PLUGIN = grpc_cpp_plugin 33 | GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)` 34 | 35 | PROTOS_PATH = ../../protos 36 | 37 | vpath %.proto $(PROTOS_PATH) 38 | 39 | all: system-check greeter_client greeter_server greeter_async_client greeter_async_client2 greeter_async_server async_streaming_server async_streaming_server_alarm greeter_streaming_client async_streaming_server_queue_to_back async_streaming_server_queue_to_front 40 | 41 | greeter_client: helloworld.pb.o helloworld.grpc.pb.o greeter_client.o 42 | $(CXX) $^ $(LDFLAGS) -o $@ 43 | 44 | greeter_server: helloworld.pb.o helloworld.grpc.pb.o greeter_server.o 45 | $(CXX) $^ $(LDFLAGS) -o $@ 46 | 47 | greeter_async_client: helloworld.pb.o helloworld.grpc.pb.o greeter_async_client.o 48 | $(CXX) $^ $(LDFLAGS) -o $@ 49 | 50 | greeter_async_client2: helloworld.pb.o helloworld.grpc.pb.o greeter_async_client2.o 51 | $(CXX) $^ $(LDFLAGS) -o $@ 52 | 53 | greeter_async_server: helloworld.pb.o helloworld.grpc.pb.o greeter_async_server.o 54 | $(CXX) $^ $(LDFLAGS) -o $@ 55 | 56 | async_streaming_server: hellostreamingworld.pb.o hellostreamingworld.grpc.pb.o async_streaming_server.o 57 | $(CXX) $^ $(LDFLAGS) -o $@ 58 | 59 | async_streaming_server_alarm: hellostreamingworld.pb.o hellostreamingworld.grpc.pb.o async_streaming_server_alarm.o 60 | $(CXX) $^ $(LDFLAGS) -o $@ 61 | 62 | greeter_streaming_client: hellostreamingworld.pb.o hellostreamingworld.grpc.pb.o greeter_streaming_client.o 63 | $(CXX) $^ $(LDFLAGS) -o $@ 64 | 65 | async_streaming_server_queue_to_back: hellostreamingworld.pb.o hellostreamingworld.grpc.pb.o async_streaming_server_queue_to_back.o 66 | $(CXX) $^ $(LDFLAGS) -o $@ 67 | 68 | async_streaming_server_queue_to_front: hellostreamingworld.pb.o hellostreamingworld.grpc.pb.o async_streaming_server_queue_to_front.o 69 | $(CXX) $^ $(LDFLAGS) -o $@ 70 | 71 | .PRECIOUS: %.grpc.pb.cc 72 | %.grpc.pb.cc: %.proto 73 | $(PROTOC) -I $(PROTOS_PATH) --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $< 74 | 75 | .PRECIOUS: %.pb.cc 76 | %.pb.cc: %.proto 77 | $(PROTOC) -I $(PROTOS_PATH) --cpp_out=. $< 78 | 79 | clean: 80 | rm -f *.o *.pb.cc *.pb.h greeter_client greeter_server greeter_async_client greeter_async_client2 greeter_async_server async_streaming_server async_streaming_server_alarm greeter_streaming_client async_streaming_server_queue_to_back async_streaming_server_queue_to_front 81 | 82 | 83 | # The following is to test your system and ensure a smoother experience. 84 | # They are by no means necessary to actually compile a grpc-enabled software. 85 | 86 | PROTOC_CMD = which $(PROTOC) 87 | PROTOC_CHECK_CMD = $(PROTOC) --version | grep -q libprotoc.3 88 | PLUGIN_CHECK_CMD = which $(GRPC_CPP_PLUGIN) 89 | HAS_PROTOC = $(shell $(PROTOC_CMD) > /dev/null && echo true || echo false) 90 | ifeq ($(HAS_PROTOC),true) 91 | HAS_VALID_PROTOC = $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false) 92 | endif 93 | HAS_PLUGIN = $(shell $(PLUGIN_CHECK_CMD) > /dev/null && echo true || echo false) 94 | 95 | SYSTEM_OK = false 96 | ifeq ($(HAS_VALID_PROTOC),true) 97 | ifeq ($(HAS_PLUGIN),true) 98 | SYSTEM_OK = true 99 | endif 100 | endif 101 | 102 | system-check: 103 | ifneq ($(HAS_VALID_PROTOC),true) 104 | @echo " DEPENDENCY ERROR" 105 | @echo 106 | @echo "You don't have protoc 3.0.0 installed in your path." 107 | @echo "Please install Google protocol buffers 3.0.0 and its compiler." 108 | @echo "You can find it here:" 109 | @echo 110 | @echo " https://github.com/google/protobuf/releases/tag/v3.0.0" 111 | @echo 112 | @echo "Here is what I get when trying to evaluate your version of protoc:" 113 | @echo 114 | -$(PROTOC) --version 115 | @echo 116 | @echo 117 | endif 118 | ifneq ($(HAS_PLUGIN),true) 119 | @echo " DEPENDENCY ERROR" 120 | @echo 121 | @echo "You don't have the grpc c++ protobuf plugin installed in your path." 122 | @echo "Please install grpc. You can find it here:" 123 | @echo 124 | @echo " https://github.com/grpc/grpc" 125 | @echo 126 | @echo "Here is what I get when trying to detect if you have the plugin:" 127 | @echo 128 | -which $(GRPC_CPP_PLUGIN) 129 | @echo 130 | @echo 131 | endif 132 | ifneq ($(SYSTEM_OK),true) 133 | @false 134 | endif 135 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Status: Archived 2 | 3 | ![status: inactive](https://img.shields.io/badge/status-inactive-red.svg) 4 | 5 | # grpc_async_examples 6 | 7 | These are examples for a G-Research's [blog post](https://www.gresearch.co.uk/2019/03/20/lessons-learnt-from-writing-asynchronous-streaming-grpc-services-in-c/) about gRPC. They are modified versions of the examples from [gRPC's repository](https://github.com/grpc/grpc). 8 | 9 | ## License 10 | 11 | Copyright 2018 G-Research 12 | 13 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use these files except in compliance with the License. 14 | You may obtain a copy of the License at 15 | 16 | http://www.apache.org/licenses/LICENSE-2.0 17 | 18 | Unless required by applicable law or agreed to in writing, software 19 | distributed under the License is distributed on an "AS IS" BASIS, 20 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | See the License for the specific language governing permissions and 22 | limitations under the License. 23 | -------------------------------------------------------------------------------- /async_streaming_server.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2015 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // This is a modification of greeter_async_server.cc from grpc examples. 20 | // Comments have been removed to make it easier to follow the code. 21 | // For comments please refer to the original example. 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | #include "hellostreamingworld.grpc.pb.h" 32 | 33 | using grpc::Server; 34 | using grpc::ServerAsyncWriter; 35 | using grpc::ServerBuilder; 36 | using grpc::ServerContext; 37 | using grpc::ServerCompletionQueue; 38 | using grpc::Status; 39 | using hellostreamingworld::HelloRequest; 40 | using hellostreamingworld::HelloReply; 41 | using hellostreamingworld::MultiGreeter; 42 | 43 | class ServerImpl final 44 | { 45 | public: 46 | ~ServerImpl() 47 | { 48 | server_->Shutdown(); 49 | cq_->Shutdown(); 50 | } 51 | 52 | void Run() 53 | { 54 | std::string server_address("0.0.0.0:50051"); 55 | 56 | ServerBuilder builder; 57 | builder.AddListeningPort(server_address, grpc::InsecureServerCredentials()); 58 | builder.RegisterService(&service_); 59 | 60 | cq_ = builder.AddCompletionQueue(); 61 | server_ = builder.BuildAndStart(); 62 | std::cout << "Server listening on " << server_address << std::endl; 63 | 64 | HandleRpcs(); 65 | } 66 | 67 | private: 68 | class CallData 69 | { 70 | public: 71 | CallData(MultiGreeter::AsyncService* service, ServerCompletionQueue* cq) 72 | : service_(service) 73 | , cq_(cq) 74 | , responder_(&ctx_) 75 | , status_(CREATE) 76 | , times_(0) 77 | { 78 | Proceed(); 79 | } 80 | 81 | void Proceed() 82 | { 83 | if (status_ == CREATE) 84 | { 85 | status_ = PROCESS; 86 | service_->RequestsayHello(&ctx_, &request_, &responder_, cq_, cq_, this); 87 | } 88 | else if (status_ == PROCESS) 89 | { 90 | // Now that we go through this stage multiple times, 91 | // we don't want to create a new instance every time. 92 | // Refer to gRPC's original example if you don't understand 93 | // why we create a new instance of CallData here. 94 | if (times_ == 0) 95 | { 96 | new CallData(service_, cq_); 97 | } 98 | 99 | if (times_++ >= 3) 100 | { 101 | status_ = FINISH; 102 | responder_.Finish(Status::OK, this); 103 | } 104 | else 105 | { 106 | std::string prefix("Hello "); 107 | reply_.set_message(prefix + request_.name() + ", no " + request_.num_greetings()); 108 | 109 | responder_.Write(reply_, this); 110 | } 111 | } 112 | else 113 | { 114 | GPR_ASSERT(status_ == FINISH); 115 | delete this; 116 | } 117 | } 118 | 119 | private: 120 | MultiGreeter::AsyncService* service_; 121 | ServerCompletionQueue* cq_; 122 | ServerContext ctx_; 123 | 124 | HelloRequest request_; 125 | HelloReply reply_; 126 | 127 | ServerAsyncWriter responder_; 128 | 129 | int times_; 130 | 131 | enum CallStatus 132 | { 133 | CREATE, 134 | PROCESS, 135 | FINISH 136 | }; 137 | CallStatus status_; // The current serving state. 138 | }; 139 | 140 | void HandleRpcs() 141 | { 142 | new CallData(&service_, cq_.get()); 143 | void* tag; // uniquely identifies a request. 144 | bool ok; 145 | while (true) 146 | { 147 | GPR_ASSERT(cq_->Next(&tag, &ok)); 148 | GPR_ASSERT(ok); 149 | static_cast(tag)->Proceed(); 150 | } 151 | } 152 | 153 | std::unique_ptr cq_; 154 | MultiGreeter::AsyncService service_; 155 | std::unique_ptr server_; 156 | }; 157 | 158 | int main(int argc, char** argv) 159 | { 160 | ServerImpl server; 161 | server.Run(); 162 | 163 | return 0; 164 | } 165 | -------------------------------------------------------------------------------- /async_streaming_server_alarm.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2015 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // This is a modification of greeter_async_server.cc from grpc examples. 20 | // Comments have been removed to make it easier to follow the code. 21 | // For comments please refer to the original example. 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include "hellostreamingworld.grpc.pb.h" 33 | 34 | using grpc::Alarm; 35 | using grpc::Server; 36 | using grpc::ServerAsyncWriter; 37 | using grpc::ServerBuilder; 38 | using grpc::ServerContext; 39 | using grpc::ServerCompletionQueue; 40 | using grpc::Status; 41 | using hellostreamingworld::HelloRequest; 42 | using hellostreamingworld::HelloReply; 43 | using hellostreamingworld::MultiGreeter; 44 | 45 | class ServerImpl final 46 | { 47 | public: 48 | ~ServerImpl() 49 | { 50 | server_->Shutdown(); 51 | cq_->Shutdown(); 52 | } 53 | 54 | void Run() 55 | { 56 | std::string server_address("0.0.0.0:50051"); 57 | 58 | ServerBuilder builder; 59 | builder.AddListeningPort(server_address, grpc::InsecureServerCredentials()); 60 | builder.RegisterService(&service_); 61 | 62 | cq_ = builder.AddCompletionQueue(); 63 | server_ = builder.BuildAndStart(); 64 | std::cout << "Server listening on " << server_address << std::endl; 65 | 66 | HandleRpcs(); 67 | } 68 | 69 | private: 70 | class CallData 71 | { 72 | public: 73 | CallData(MultiGreeter::AsyncService* service, ServerCompletionQueue* cq) 74 | : service_(service) 75 | , cq_(cq) 76 | , responder_(&ctx_) 77 | , status_(CREATE) 78 | , times_(0) 79 | { 80 | Proceed(); 81 | } 82 | 83 | void Proceed() 84 | { 85 | if (status_ == CREATE) 86 | { 87 | status_ = PROCESS; 88 | service_->RequestsayHello(&ctx_, &request_, &responder_, cq_, cq_, this); 89 | } 90 | else if (status_ == PROCESS) 91 | { 92 | // Now that we go through this stage multiple times, 93 | // we don't want to create a new instance every time. 94 | // Refer to gRPC's original example if you don't understand 95 | // why we create a new instance of CallData here. 96 | if (times_ == 0) 97 | { 98 | new CallData(service_, cq_); 99 | } 100 | 101 | if (times_++ >= 6) 102 | { 103 | status_ = FINISH; 104 | responder_.Finish(Status::OK, this); 105 | } 106 | else 107 | { 108 | if (HasData()) 109 | { 110 | std::string prefix("Hello "); 111 | reply_.set_message(prefix + request_.name() + ", no " + request_.num_greetings()); 112 | 113 | responder_.Write(reply_, this); 114 | } 115 | else 116 | { 117 | // If there's no data to be written, put the task back into the queue 118 | PutTaskBackToQueue(); 119 | } 120 | } 121 | } 122 | else 123 | { 124 | GPR_ASSERT(status_ == FINISH); 125 | delete this; 126 | } 127 | } 128 | 129 | private: 130 | bool HasData() 131 | { 132 | // A dummy condition to make it sometimes have data and sometimes not 133 | return times_ % 2 == 0; 134 | } 135 | 136 | void PutTaskBackToQueue() 137 | { 138 | alarm_.Set(cq_, gpr_now(gpr_clock_type::GPR_CLOCK_REALTIME), this); 139 | } 140 | 141 | MultiGreeter::AsyncService* service_; 142 | ServerCompletionQueue* cq_; 143 | ServerContext ctx_; 144 | 145 | HelloRequest request_; 146 | HelloReply reply_; 147 | 148 | ServerAsyncWriter responder_; 149 | 150 | int times_; 151 | Alarm alarm_; 152 | 153 | enum CallStatus 154 | { 155 | CREATE, 156 | PROCESS, 157 | FINISH 158 | }; 159 | CallStatus status_; // The current serving state. 160 | }; 161 | 162 | void HandleRpcs() 163 | { 164 | new CallData(&service_, cq_.get()); 165 | void* tag; // uniquely identifies a request. 166 | bool ok; 167 | while (true) 168 | { 169 | GPR_ASSERT(cq_->Next(&tag, &ok)); 170 | GPR_ASSERT(ok); 171 | static_cast(tag)->Proceed(); 172 | } 173 | } 174 | 175 | std::unique_ptr cq_; 176 | MultiGreeter::AsyncService service_; 177 | std::unique_ptr server_; 178 | }; 179 | 180 | int main(int argc, char** argv) 181 | { 182 | ServerImpl server; 183 | server.Run(); 184 | 185 | return 0; 186 | } 187 | -------------------------------------------------------------------------------- /async_streaming_server_queue_to_back.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "hellostreamingworld.grpc.pb.h" 11 | 12 | using grpc::Server; 13 | using grpc::ServerAsyncWriter; 14 | using grpc::ServerBuilder; 15 | using grpc::ServerContext; 16 | using grpc::ServerCompletionQueue; 17 | using grpc::Status; 18 | using hellostreamingworld::HelloRequest; 19 | using hellostreamingworld::HelloReply; 20 | using hellostreamingworld::MultiGreeter; 21 | 22 | class ServerImpl final 23 | { 24 | public: 25 | ~ServerImpl() 26 | { 27 | server_->Shutdown(); 28 | cq_->Shutdown(); 29 | } 30 | 31 | void Run() 32 | { 33 | std::string server_address("0.0.0.0:50051"); 34 | 35 | ServerBuilder builder; 36 | builder.AddListeningPort(server_address, grpc::InsecureServerCredentials()); 37 | builder.RegisterService(&service_); 38 | 39 | cq_ = builder.AddCompletionQueue(); 40 | server_ = builder.BuildAndStart(); 41 | std::cout << "Server listening on " << server_address << std::endl; 42 | 43 | HandleRpcs(); 44 | } 45 | 46 | private: 47 | class CallData 48 | { 49 | public: 50 | CallData(MultiGreeter::AsyncService* service, ServerCompletionQueue* cq, int client_id) 51 | : service_(service) 52 | , cq_(cq) 53 | , responder_(&ctx_) 54 | , status_(CREATE) 55 | , times_(0) 56 | , client_id_(client_id) 57 | { 58 | std::cout << "Created CallData " << client_id_ << std::endl; 59 | Proceed(); 60 | } 61 | 62 | void Proceed() 63 | { 64 | if (status_ == CREATE) 65 | { 66 | status_ = PROCESS; 67 | service_->RequestsayHello(&ctx_, &request_, &responder_, cq_, cq_, this); 68 | } 69 | else if (status_ == PROCESS) 70 | { 71 | std::cout << "Client being processed: " << client_id_ << std::endl; 72 | if(times_ == 0) 73 | { 74 | new CallData(service_, cq_, client_id_ + 1); 75 | } 76 | 77 | if (times_++ >= 3) 78 | { 79 | status_ = FINISH; 80 | responder_.Finish(Status::OK, this); 81 | } 82 | else 83 | { 84 | std::string prefix("Hello "); 85 | reply_.set_message(prefix + request_.name() + ", no " + request_.num_greetings()); 86 | 87 | // For illustrating the queue-to-front behaviour 88 | using namespace std::chrono_literals; 89 | std::this_thread::sleep_for(1s); 90 | 91 | responder_.Write(reply_, this); 92 | status_ = PUSH_TO_BACK; 93 | } 94 | } 95 | else if(status_ == PUSH_TO_BACK) 96 | { 97 | status_ = PROCESS; 98 | alarm_.Set(cq_, gpr_now(gpr_clock_type::GPR_CLOCK_REALTIME), this); 99 | } 100 | else 101 | { 102 | GPR_ASSERT(status_ == FINISH); 103 | delete this; 104 | } 105 | } 106 | 107 | void Stop() 108 | { 109 | std::cerr << "Finishing up client " << client_id_ << std::endl; 110 | status_ = CallStatus::FINISH; 111 | } 112 | 113 | private: 114 | MultiGreeter::AsyncService* service_; 115 | ServerCompletionQueue* cq_; 116 | ServerContext ctx_; 117 | 118 | HelloRequest request_; 119 | HelloReply reply_; 120 | 121 | grpc::Alarm alarm_; 122 | 123 | ServerAsyncWriter responder_; 124 | 125 | int times_; 126 | int client_id_; 127 | 128 | enum CallStatus 129 | { 130 | CREATE, 131 | PROCESS, 132 | FINISH, 133 | PUSH_TO_BACK 134 | }; 135 | CallStatus status_; // The current serving state. 136 | }; 137 | 138 | void HandleRpcs() 139 | { 140 | new CallData(&service_, cq_.get(), num_clients_++); 141 | void* tag; // uniquely identifies a request. 142 | bool ok; 143 | while (true) 144 | { 145 | GPR_ASSERT(cq_->Next(&tag, &ok)); 146 | if(!ok) 147 | { 148 | static_cast(tag)->Stop(); 149 | continue; 150 | } 151 | static_cast(tag)->Proceed(); 152 | } 153 | } 154 | 155 | int num_clients_ = 0; 156 | std::unique_ptr cq_; 157 | MultiGreeter::AsyncService service_; 158 | std::unique_ptr server_; 159 | }; 160 | 161 | int main(int argc, char** argv) 162 | { 163 | ServerImpl server; 164 | server.Run(); 165 | 166 | return 0; 167 | } 168 | -------------------------------------------------------------------------------- /async_streaming_server_queue_to_front.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include "hellostreamingworld.grpc.pb.h" 10 | 11 | using grpc::Server; 12 | using grpc::ServerAsyncWriter; 13 | using grpc::ServerBuilder; 14 | using grpc::ServerContext; 15 | using grpc::ServerCompletionQueue; 16 | using grpc::Status; 17 | using hellostreamingworld::HelloRequest; 18 | using hellostreamingworld::HelloReply; 19 | using hellostreamingworld::MultiGreeter; 20 | 21 | class ServerImpl final 22 | { 23 | public: 24 | ~ServerImpl() 25 | { 26 | server_->Shutdown(); 27 | cq_->Shutdown(); 28 | } 29 | 30 | void Run() 31 | { 32 | std::string server_address("0.0.0.0:50051"); 33 | 34 | ServerBuilder builder; 35 | builder.AddListeningPort(server_address, grpc::InsecureServerCredentials()); 36 | builder.RegisterService(&service_); 37 | 38 | cq_ = builder.AddCompletionQueue(); 39 | server_ = builder.BuildAndStart(); 40 | std::cout << "Server listening on " << server_address << std::endl; 41 | 42 | HandleRpcs(); 43 | } 44 | 45 | private: 46 | class CallData 47 | { 48 | public: 49 | CallData(MultiGreeter::AsyncService* service, ServerCompletionQueue* cq, int client_id) 50 | : service_(service) 51 | , cq_(cq) 52 | , responder_(&ctx_) 53 | , status_(CREATE) 54 | , times_(0) 55 | , client_id_(client_id) 56 | { 57 | std::cout << "Created CallData " << client_id_ << std::endl; 58 | Proceed(); 59 | } 60 | 61 | void Proceed() 62 | { 63 | if (status_ == CREATE) 64 | { 65 | status_ = PROCESS; 66 | service_->RequestsayHello(&ctx_, &request_, &responder_, cq_, cq_, this); 67 | } 68 | else if (status_ == PROCESS) 69 | { 70 | std::cout << "Client being processed: " << client_id_ << std::endl; 71 | if(times_ == 0) 72 | { 73 | new CallData(service_, cq_, client_id_ + 1); 74 | } 75 | 76 | if (times_++ >= 3) 77 | { 78 | status_ = FINISH; 79 | responder_.Finish(Status::OK, this); 80 | } 81 | else 82 | { 83 | std::string prefix("Hello "); 84 | reply_.set_message(prefix + request_.name() + ", no " + request_.num_greetings()); 85 | 86 | // For illustrating the queue-to-front behaviour 87 | using namespace std::chrono_literals; 88 | std::this_thread::sleep_for(1s); 89 | 90 | responder_.Write(reply_, this); 91 | } 92 | } 93 | else 94 | { 95 | GPR_ASSERT(status_ == FINISH); 96 | delete this; 97 | } 98 | } 99 | 100 | void Stop() 101 | { 102 | std::cerr << "Finishing up client " << client_id_ << std::endl; 103 | status_ = CallStatus::FINISH; 104 | } 105 | 106 | private: 107 | MultiGreeter::AsyncService* service_; 108 | ServerCompletionQueue* cq_; 109 | ServerContext ctx_; 110 | 111 | HelloRequest request_; 112 | HelloReply reply_; 113 | 114 | ServerAsyncWriter responder_; 115 | 116 | int times_; 117 | int client_id_; 118 | 119 | enum CallStatus 120 | { 121 | CREATE, 122 | PROCESS, 123 | FINISH 124 | }; 125 | CallStatus status_; // The current serving state. 126 | }; 127 | 128 | void HandleRpcs() 129 | { 130 | new CallData(&service_, cq_.get(), num_clients_++); 131 | void* tag; // uniquely identifies a request. 132 | bool ok; 133 | while (true) 134 | { 135 | GPR_ASSERT(cq_->Next(&tag, &ok)); 136 | if(!ok) 137 | { 138 | static_cast(tag)->Stop(); 139 | continue; 140 | } 141 | static_cast(tag)->Proceed(); 142 | } 143 | } 144 | 145 | int num_clients_ = 0; 146 | std::unique_ptr cq_; 147 | MultiGreeter::AsyncService service_; 148 | std::unique_ptr server_; 149 | }; 150 | 151 | int main(int argc, char** argv) 152 | { 153 | ServerImpl server; 154 | server.Run(); 155 | 156 | return 0; 157 | } 158 | -------------------------------------------------------------------------------- /greeter_streaming_client.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2015 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // This is a modification of greeter_client.cc from grpc examples. 20 | // Comments have been removed to make it easier to follow the code. 21 | // For comments please refer to the original example. 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include "hellostreamingworld.grpc.pb.h" 29 | 30 | using grpc::Channel; 31 | using grpc::ClientContext; 32 | using grpc::ClientReader; 33 | using grpc::Status; 34 | using hellostreamingworld::HelloRequest; 35 | using hellostreamingworld::HelloReply; 36 | using hellostreamingworld::MultiGreeter; 37 | 38 | class GreeterClient 39 | { 40 | public: 41 | GreeterClient(std::shared_ptr channel) 42 | : stub_(MultiGreeter::NewStub(channel)) 43 | {} 44 | 45 | void SayHello(const std::string& user, const std::string& num_greetings) 46 | { 47 | HelloRequest request; 48 | request.set_name(user); 49 | request.set_num_greetings(num_greetings); 50 | 51 | ClientContext context; 52 | std::unique_ptr> reader(stub_->sayHello(&context, request)); 53 | 54 | HelloReply reply; 55 | while (reader->Read(&reply)) 56 | { 57 | std::cout << "Got reply: " << reply.message() << std::endl; 58 | } 59 | 60 | Status status = reader->Finish(); 61 | if (status.ok()) 62 | { 63 | std::cout << "sayHello rpc succeeded." << std::endl; 64 | } 65 | else 66 | { 67 | std::cout << "sayHello rpc failed." << std::endl; 68 | std::cout << status.error_code() << ": " << status.error_message() << std::endl; 69 | } 70 | } 71 | 72 | private: 73 | std::unique_ptr stub_; 74 | }; 75 | 76 | int main(int argc, char** argv) 77 | { 78 | GreeterClient greeter(grpc::CreateChannel("localhost:50051", grpc::InsecureChannelCredentials())); 79 | std::string user("world"); 80 | greeter.SayHello(user, "123"); 81 | 82 | return 0; 83 | } 84 | -------------------------------------------------------------------------------- /hellostreamingworld.grpc.pb.cc: -------------------------------------------------------------------------------- 1 | // Generated by the gRPC C++ plugin. 2 | // If you make any local change, they will be lost. 3 | // source: hellostreamingworld.proto 4 | 5 | #include "hellostreamingworld.pb.h" 6 | #include "hellostreamingworld.grpc.pb.h" 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | namespace hellostreamingworld { 20 | 21 | static const char* MultiGreeter_method_names[] = { 22 | "/hellostreamingworld.MultiGreeter/sayHello", 23 | }; 24 | 25 | std::unique_ptr< MultiGreeter::Stub> MultiGreeter::NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options) { 26 | (void)options; 27 | std::unique_ptr< MultiGreeter::Stub> stub(new MultiGreeter::Stub(channel)); 28 | return stub; 29 | } 30 | 31 | MultiGreeter::Stub::Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel) 32 | : channel_(channel), rpcmethod_sayHello_(MultiGreeter_method_names[0], ::grpc::internal::RpcMethod::SERVER_STREAMING, channel) 33 | {} 34 | 35 | ::grpc::ClientReader< ::hellostreamingworld::HelloReply>* MultiGreeter::Stub::sayHelloRaw(::grpc::ClientContext* context, const ::hellostreamingworld::HelloRequest& request) { 36 | return ::grpc::internal::ClientReaderFactory< ::hellostreamingworld::HelloReply>::Create(channel_.get(), rpcmethod_sayHello_, context, request); 37 | } 38 | 39 | ::grpc::ClientAsyncReader< ::hellostreamingworld::HelloReply>* MultiGreeter::Stub::AsyncsayHelloRaw(::grpc::ClientContext* context, const ::hellostreamingworld::HelloRequest& request, ::grpc::CompletionQueue* cq, void* tag) { 40 | return ::grpc::internal::ClientAsyncReaderFactory< ::hellostreamingworld::HelloReply>::Create(channel_.get(), cq, rpcmethod_sayHello_, context, request, true, tag); 41 | } 42 | 43 | ::grpc::ClientAsyncReader< ::hellostreamingworld::HelloReply>* MultiGreeter::Stub::PrepareAsyncsayHelloRaw(::grpc::ClientContext* context, const ::hellostreamingworld::HelloRequest& request, ::grpc::CompletionQueue* cq) { 44 | return ::grpc::internal::ClientAsyncReaderFactory< ::hellostreamingworld::HelloReply>::Create(channel_.get(), cq, rpcmethod_sayHello_, context, request, false, nullptr); 45 | } 46 | 47 | MultiGreeter::Service::Service() { 48 | AddMethod(new ::grpc::internal::RpcServiceMethod( 49 | MultiGreeter_method_names[0], 50 | ::grpc::internal::RpcMethod::SERVER_STREAMING, 51 | new ::grpc::internal::ServerStreamingHandler< MultiGreeter::Service, ::hellostreamingworld::HelloRequest, ::hellostreamingworld::HelloReply>( 52 | std::mem_fn(&MultiGreeter::Service::sayHello), this))); 53 | } 54 | 55 | MultiGreeter::Service::~Service() { 56 | } 57 | 58 | ::grpc::Status MultiGreeter::Service::sayHello(::grpc::ServerContext* context, const ::hellostreamingworld::HelloRequest* request, ::grpc::ServerWriter< ::hellostreamingworld::HelloReply>* writer) { 59 | (void) context; 60 | (void) request; 61 | (void) writer; 62 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 63 | } 64 | 65 | 66 | } // namespace hellostreamingworld 67 | 68 | -------------------------------------------------------------------------------- /hellostreamingworld.grpc.pb.h: -------------------------------------------------------------------------------- 1 | // Generated by the gRPC C++ plugin. 2 | // If you make any local change, they will be lost. 3 | // source: hellostreamingworld.proto 4 | // Original file comments: 5 | // Copyright 2015 gRPC authors. 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | #ifndef GRPC_hellostreamingworld_2eproto__INCLUDED 20 | #define GRPC_hellostreamingworld_2eproto__INCLUDED 21 | 22 | #include "hellostreamingworld.pb.h" 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | namespace grpc { 38 | class CompletionQueue; 39 | class Channel; 40 | class ServerCompletionQueue; 41 | class ServerContext; 42 | } // namespace grpc 43 | 44 | namespace hellostreamingworld { 45 | 46 | // The greeting service definition. 47 | class MultiGreeter final { 48 | public: 49 | static constexpr char const* service_full_name() { 50 | return "hellostreamingworld.MultiGreeter"; 51 | } 52 | class StubInterface { 53 | public: 54 | virtual ~StubInterface() {} 55 | // Sends multiple greetings 56 | std::unique_ptr< ::grpc::ClientReaderInterface< ::hellostreamingworld::HelloReply>> sayHello(::grpc::ClientContext* context, const ::hellostreamingworld::HelloRequest& request) { 57 | return std::unique_ptr< ::grpc::ClientReaderInterface< ::hellostreamingworld::HelloReply>>(sayHelloRaw(context, request)); 58 | } 59 | std::unique_ptr< ::grpc::ClientAsyncReaderInterface< ::hellostreamingworld::HelloReply>> AsyncsayHello(::grpc::ClientContext* context, const ::hellostreamingworld::HelloRequest& request, ::grpc::CompletionQueue* cq, void* tag) { 60 | return std::unique_ptr< ::grpc::ClientAsyncReaderInterface< ::hellostreamingworld::HelloReply>>(AsyncsayHelloRaw(context, request, cq, tag)); 61 | } 62 | std::unique_ptr< ::grpc::ClientAsyncReaderInterface< ::hellostreamingworld::HelloReply>> PrepareAsyncsayHello(::grpc::ClientContext* context, const ::hellostreamingworld::HelloRequest& request, ::grpc::CompletionQueue* cq) { 63 | return std::unique_ptr< ::grpc::ClientAsyncReaderInterface< ::hellostreamingworld::HelloReply>>(PrepareAsyncsayHelloRaw(context, request, cq)); 64 | } 65 | class experimental_async_interface { 66 | public: 67 | virtual ~experimental_async_interface() {} 68 | // Sends multiple greetings 69 | }; 70 | virtual class experimental_async_interface* experimental_async() { return nullptr; } 71 | private: 72 | virtual ::grpc::ClientReaderInterface< ::hellostreamingworld::HelloReply>* sayHelloRaw(::grpc::ClientContext* context, const ::hellostreamingworld::HelloRequest& request) = 0; 73 | virtual ::grpc::ClientAsyncReaderInterface< ::hellostreamingworld::HelloReply>* AsyncsayHelloRaw(::grpc::ClientContext* context, const ::hellostreamingworld::HelloRequest& request, ::grpc::CompletionQueue* cq, void* tag) = 0; 74 | virtual ::grpc::ClientAsyncReaderInterface< ::hellostreamingworld::HelloReply>* PrepareAsyncsayHelloRaw(::grpc::ClientContext* context, const ::hellostreamingworld::HelloRequest& request, ::grpc::CompletionQueue* cq) = 0; 75 | }; 76 | class Stub final : public StubInterface { 77 | public: 78 | Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel); 79 | std::unique_ptr< ::grpc::ClientReader< ::hellostreamingworld::HelloReply>> sayHello(::grpc::ClientContext* context, const ::hellostreamingworld::HelloRequest& request) { 80 | return std::unique_ptr< ::grpc::ClientReader< ::hellostreamingworld::HelloReply>>(sayHelloRaw(context, request)); 81 | } 82 | std::unique_ptr< ::grpc::ClientAsyncReader< ::hellostreamingworld::HelloReply>> AsyncsayHello(::grpc::ClientContext* context, const ::hellostreamingworld::HelloRequest& request, ::grpc::CompletionQueue* cq, void* tag) { 83 | return std::unique_ptr< ::grpc::ClientAsyncReader< ::hellostreamingworld::HelloReply>>(AsyncsayHelloRaw(context, request, cq, tag)); 84 | } 85 | std::unique_ptr< ::grpc::ClientAsyncReader< ::hellostreamingworld::HelloReply>> PrepareAsyncsayHello(::grpc::ClientContext* context, const ::hellostreamingworld::HelloRequest& request, ::grpc::CompletionQueue* cq) { 86 | return std::unique_ptr< ::grpc::ClientAsyncReader< ::hellostreamingworld::HelloReply>>(PrepareAsyncsayHelloRaw(context, request, cq)); 87 | } 88 | class experimental_async final : 89 | public StubInterface::experimental_async_interface { 90 | public: 91 | private: 92 | friend class Stub; 93 | explicit experimental_async(Stub* stub): stub_(stub) { } 94 | Stub* stub() { return stub_; } 95 | Stub* stub_; 96 | }; 97 | class experimental_async_interface* experimental_async() override { return &async_stub_; } 98 | 99 | private: 100 | std::shared_ptr< ::grpc::ChannelInterface> channel_; 101 | class experimental_async async_stub_{this}; 102 | ::grpc::ClientReader< ::hellostreamingworld::HelloReply>* sayHelloRaw(::grpc::ClientContext* context, const ::hellostreamingworld::HelloRequest& request) override; 103 | ::grpc::ClientAsyncReader< ::hellostreamingworld::HelloReply>* AsyncsayHelloRaw(::grpc::ClientContext* context, const ::hellostreamingworld::HelloRequest& request, ::grpc::CompletionQueue* cq, void* tag) override; 104 | ::grpc::ClientAsyncReader< ::hellostreamingworld::HelloReply>* PrepareAsyncsayHelloRaw(::grpc::ClientContext* context, const ::hellostreamingworld::HelloRequest& request, ::grpc::CompletionQueue* cq) override; 105 | const ::grpc::internal::RpcMethod rpcmethod_sayHello_; 106 | }; 107 | static std::unique_ptr NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options = ::grpc::StubOptions()); 108 | 109 | class Service : public ::grpc::Service { 110 | public: 111 | Service(); 112 | virtual ~Service(); 113 | // Sends multiple greetings 114 | virtual ::grpc::Status sayHello(::grpc::ServerContext* context, const ::hellostreamingworld::HelloRequest* request, ::grpc::ServerWriter< ::hellostreamingworld::HelloReply>* writer); 115 | }; 116 | template 117 | class WithAsyncMethod_sayHello : public BaseClass { 118 | private: 119 | void BaseClassMustBeDerivedFromService(const Service *service) {} 120 | public: 121 | WithAsyncMethod_sayHello() { 122 | ::grpc::Service::MarkMethodAsync(0); 123 | } 124 | ~WithAsyncMethod_sayHello() override { 125 | BaseClassMustBeDerivedFromService(this); 126 | } 127 | // disable synchronous version of this method 128 | ::grpc::Status sayHello(::grpc::ServerContext* context, const ::hellostreamingworld::HelloRequest* request, ::grpc::ServerWriter< ::hellostreamingworld::HelloReply>* writer) override { 129 | abort(); 130 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 131 | } 132 | void RequestsayHello(::grpc::ServerContext* context, ::hellostreamingworld::HelloRequest* request, ::grpc::ServerAsyncWriter< ::hellostreamingworld::HelloReply>* writer, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { 133 | ::grpc::Service::RequestAsyncServerStreaming(0, context, request, writer, new_call_cq, notification_cq, tag); 134 | } 135 | }; 136 | typedef WithAsyncMethod_sayHello AsyncService; 137 | template 138 | class ExperimentalWithCallbackMethod_sayHello : public BaseClass { 139 | private: 140 | void BaseClassMustBeDerivedFromService(const Service *service) {} 141 | public: 142 | ExperimentalWithCallbackMethod_sayHello() { 143 | } 144 | ~ExperimentalWithCallbackMethod_sayHello() override { 145 | BaseClassMustBeDerivedFromService(this); 146 | } 147 | // disable synchronous version of this method 148 | ::grpc::Status sayHello(::grpc::ServerContext* context, const ::hellostreamingworld::HelloRequest* request, ::grpc::ServerWriter< ::hellostreamingworld::HelloReply>* writer) override { 149 | abort(); 150 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 151 | } 152 | }; 153 | typedef ExperimentalWithCallbackMethod_sayHello ExperimentalCallbackService; 154 | template 155 | class WithGenericMethod_sayHello : public BaseClass { 156 | private: 157 | void BaseClassMustBeDerivedFromService(const Service *service) {} 158 | public: 159 | WithGenericMethod_sayHello() { 160 | ::grpc::Service::MarkMethodGeneric(0); 161 | } 162 | ~WithGenericMethod_sayHello() override { 163 | BaseClassMustBeDerivedFromService(this); 164 | } 165 | // disable synchronous version of this method 166 | ::grpc::Status sayHello(::grpc::ServerContext* context, const ::hellostreamingworld::HelloRequest* request, ::grpc::ServerWriter< ::hellostreamingworld::HelloReply>* writer) override { 167 | abort(); 168 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 169 | } 170 | }; 171 | template 172 | class WithRawMethod_sayHello : public BaseClass { 173 | private: 174 | void BaseClassMustBeDerivedFromService(const Service *service) {} 175 | public: 176 | WithRawMethod_sayHello() { 177 | ::grpc::Service::MarkMethodRaw(0); 178 | } 179 | ~WithRawMethod_sayHello() override { 180 | BaseClassMustBeDerivedFromService(this); 181 | } 182 | // disable synchronous version of this method 183 | ::grpc::Status sayHello(::grpc::ServerContext* context, const ::hellostreamingworld::HelloRequest* request, ::grpc::ServerWriter< ::hellostreamingworld::HelloReply>* writer) override { 184 | abort(); 185 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 186 | } 187 | void RequestsayHello(::grpc::ServerContext* context, ::grpc::ByteBuffer* request, ::grpc::ServerAsyncWriter< ::grpc::ByteBuffer>* writer, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { 188 | ::grpc::Service::RequestAsyncServerStreaming(0, context, request, writer, new_call_cq, notification_cq, tag); 189 | } 190 | }; 191 | template 192 | class ExperimentalWithRawCallbackMethod_sayHello : public BaseClass { 193 | private: 194 | void BaseClassMustBeDerivedFromService(const Service *service) {} 195 | public: 196 | ExperimentalWithRawCallbackMethod_sayHello() { 197 | } 198 | ~ExperimentalWithRawCallbackMethod_sayHello() override { 199 | BaseClassMustBeDerivedFromService(this); 200 | } 201 | // disable synchronous version of this method 202 | ::grpc::Status sayHello(::grpc::ServerContext* context, const ::hellostreamingworld::HelloRequest* request, ::grpc::ServerWriter< ::hellostreamingworld::HelloReply>* writer) override { 203 | abort(); 204 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 205 | } 206 | }; 207 | typedef Service StreamedUnaryService; 208 | template 209 | class WithSplitStreamingMethod_sayHello : public BaseClass { 210 | private: 211 | void BaseClassMustBeDerivedFromService(const Service *service) {} 212 | public: 213 | WithSplitStreamingMethod_sayHello() { 214 | ::grpc::Service::MarkMethodStreamed(0, 215 | new ::grpc::internal::SplitServerStreamingHandler< ::hellostreamingworld::HelloRequest, ::hellostreamingworld::HelloReply>(std::bind(&WithSplitStreamingMethod_sayHello::StreamedsayHello, this, std::placeholders::_1, std::placeholders::_2))); 216 | } 217 | ~WithSplitStreamingMethod_sayHello() override { 218 | BaseClassMustBeDerivedFromService(this); 219 | } 220 | // disable regular version of this method 221 | ::grpc::Status sayHello(::grpc::ServerContext* context, const ::hellostreamingworld::HelloRequest* request, ::grpc::ServerWriter< ::hellostreamingworld::HelloReply>* writer) override { 222 | abort(); 223 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 224 | } 225 | // replace default version of method with split streamed 226 | virtual ::grpc::Status StreamedsayHello(::grpc::ServerContext* context, ::grpc::ServerSplitStreamer< ::hellostreamingworld::HelloRequest,::hellostreamingworld::HelloReply>* server_split_streamer) = 0; 227 | }; 228 | typedef WithSplitStreamingMethod_sayHello SplitStreamedService; 229 | typedef WithSplitStreamingMethod_sayHello StreamedService; 230 | }; 231 | 232 | } // namespace hellostreamingworld 233 | 234 | 235 | #endif // GRPC_hellostreamingworld_2eproto__INCLUDED 236 | -------------------------------------------------------------------------------- /hellostreamingworld.pb.cc: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: hellostreamingworld.proto 3 | 4 | #include "hellostreamingworld.pb.h" 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | // This is a temporary google only hack 17 | #ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS 18 | #include "third_party/protobuf/version.h" 19 | #endif 20 | // @@protoc_insertion_point(includes) 21 | 22 | namespace hellostreamingworld { 23 | class HelloRequestDefaultTypeInternal { 24 | public: 25 | ::google::protobuf::internal::ExplicitlyConstructed 26 | _instance; 27 | } _HelloRequest_default_instance_; 28 | class HelloReplyDefaultTypeInternal { 29 | public: 30 | ::google::protobuf::internal::ExplicitlyConstructed 31 | _instance; 32 | } _HelloReply_default_instance_; 33 | } // namespace hellostreamingworld 34 | namespace protobuf_hellostreamingworld_2eproto { 35 | static void InitDefaultsHelloRequest() { 36 | GOOGLE_PROTOBUF_VERIFY_VERSION; 37 | 38 | { 39 | void* ptr = &::hellostreamingworld::_HelloRequest_default_instance_; 40 | new (ptr) ::hellostreamingworld::HelloRequest(); 41 | ::google::protobuf::internal::OnShutdownDestroyMessage(ptr); 42 | } 43 | ::hellostreamingworld::HelloRequest::InitAsDefaultInstance(); 44 | } 45 | 46 | ::google::protobuf::internal::SCCInfo<0> scc_info_HelloRequest = 47 | {{ATOMIC_VAR_INIT(::google::protobuf::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsHelloRequest}, {}}; 48 | 49 | static void InitDefaultsHelloReply() { 50 | GOOGLE_PROTOBUF_VERIFY_VERSION; 51 | 52 | { 53 | void* ptr = &::hellostreamingworld::_HelloReply_default_instance_; 54 | new (ptr) ::hellostreamingworld::HelloReply(); 55 | ::google::protobuf::internal::OnShutdownDestroyMessage(ptr); 56 | } 57 | ::hellostreamingworld::HelloReply::InitAsDefaultInstance(); 58 | } 59 | 60 | ::google::protobuf::internal::SCCInfo<0> scc_info_HelloReply = 61 | {{ATOMIC_VAR_INIT(::google::protobuf::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsHelloReply}, {}}; 62 | 63 | void InitDefaults() { 64 | ::google::protobuf::internal::InitSCC(&scc_info_HelloRequest.base); 65 | ::google::protobuf::internal::InitSCC(&scc_info_HelloReply.base); 66 | } 67 | 68 | ::google::protobuf::Metadata file_level_metadata[2]; 69 | 70 | const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { 71 | ~0u, // no _has_bits_ 72 | GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::hellostreamingworld::HelloRequest, _internal_metadata_), 73 | ~0u, // no _extensions_ 74 | ~0u, // no _oneof_case_ 75 | ~0u, // no _weak_field_map_ 76 | GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::hellostreamingworld::HelloRequest, name_), 77 | GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::hellostreamingworld::HelloRequest, num_greetings_), 78 | ~0u, // no _has_bits_ 79 | GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::hellostreamingworld::HelloReply, _internal_metadata_), 80 | ~0u, // no _extensions_ 81 | ~0u, // no _oneof_case_ 82 | ~0u, // no _weak_field_map_ 83 | GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::hellostreamingworld::HelloReply, message_), 84 | }; 85 | static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { 86 | { 0, -1, sizeof(::hellostreamingworld::HelloRequest)}, 87 | { 7, -1, sizeof(::hellostreamingworld::HelloReply)}, 88 | }; 89 | 90 | static ::google::protobuf::Message const * const file_default_instances[] = { 91 | reinterpret_cast(&::hellostreamingworld::_HelloRequest_default_instance_), 92 | reinterpret_cast(&::hellostreamingworld::_HelloReply_default_instance_), 93 | }; 94 | 95 | void protobuf_AssignDescriptors() { 96 | AddDescriptors(); 97 | AssignDescriptors( 98 | "hellostreamingworld.proto", schemas, file_default_instances, TableStruct::offsets, 99 | file_level_metadata, NULL, NULL); 100 | } 101 | 102 | void protobuf_AssignDescriptorsOnce() { 103 | static ::google::protobuf::internal::once_flag once; 104 | ::google::protobuf::internal::call_once(once, protobuf_AssignDescriptors); 105 | } 106 | 107 | void protobuf_RegisterTypes(const ::std::string&) GOOGLE_PROTOBUF_ATTRIBUTE_COLD; 108 | void protobuf_RegisterTypes(const ::std::string&) { 109 | protobuf_AssignDescriptorsOnce(); 110 | ::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 2); 111 | } 112 | 113 | void AddDescriptorsImpl() { 114 | InitDefaults(); 115 | static const char descriptor[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { 116 | "\n\031hellostreamingworld.proto\022\023hellostream" 117 | "ingworld\"3\n\014HelloRequest\022\014\n\004name\030\001 \001(\t\022\025" 118 | "\n\rnum_greetings\030\002 \001(\t\"\035\n\nHelloReply\022\017\n\007m" 119 | "essage\030\001 \001(\t2b\n\014MultiGreeter\022R\n\010sayHello" 120 | "\022!.hellostreamingworld.HelloRequest\032\037.he" 121 | "llostreamingworld.HelloReply\"\0000\001B\017\n\007ex.g" 122 | "rpc\242\002\003HSWb\006proto3" 123 | }; 124 | ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( 125 | descriptor, 257); 126 | ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( 127 | "hellostreamingworld.proto", &protobuf_RegisterTypes); 128 | } 129 | 130 | void AddDescriptors() { 131 | static ::google::protobuf::internal::once_flag once; 132 | ::google::protobuf::internal::call_once(once, AddDescriptorsImpl); 133 | } 134 | // Force AddDescriptors() to be called at dynamic initialization time. 135 | struct StaticDescriptorInitializer { 136 | StaticDescriptorInitializer() { 137 | AddDescriptors(); 138 | } 139 | } static_descriptor_initializer; 140 | } // namespace protobuf_hellostreamingworld_2eproto 141 | namespace hellostreamingworld { 142 | 143 | // =================================================================== 144 | 145 | void HelloRequest::InitAsDefaultInstance() { 146 | } 147 | #if !defined(_MSC_VER) || _MSC_VER >= 1900 148 | const int HelloRequest::kNameFieldNumber; 149 | const int HelloRequest::kNumGreetingsFieldNumber; 150 | #endif // !defined(_MSC_VER) || _MSC_VER >= 1900 151 | 152 | HelloRequest::HelloRequest() 153 | : ::google::protobuf::Message(), _internal_metadata_(NULL) { 154 | ::google::protobuf::internal::InitSCC( 155 | &protobuf_hellostreamingworld_2eproto::scc_info_HelloRequest.base); 156 | SharedCtor(); 157 | // @@protoc_insertion_point(constructor:hellostreamingworld.HelloRequest) 158 | } 159 | HelloRequest::HelloRequest(const HelloRequest& from) 160 | : ::google::protobuf::Message(), 161 | _internal_metadata_(NULL) { 162 | _internal_metadata_.MergeFrom(from._internal_metadata_); 163 | name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 164 | if (from.name().size() > 0) { 165 | name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_); 166 | } 167 | num_greetings_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 168 | if (from.num_greetings().size() > 0) { 169 | num_greetings_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.num_greetings_); 170 | } 171 | // @@protoc_insertion_point(copy_constructor:hellostreamingworld.HelloRequest) 172 | } 173 | 174 | void HelloRequest::SharedCtor() { 175 | name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 176 | num_greetings_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 177 | } 178 | 179 | HelloRequest::~HelloRequest() { 180 | // @@protoc_insertion_point(destructor:hellostreamingworld.HelloRequest) 181 | SharedDtor(); 182 | } 183 | 184 | void HelloRequest::SharedDtor() { 185 | name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 186 | num_greetings_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 187 | } 188 | 189 | void HelloRequest::SetCachedSize(int size) const { 190 | _cached_size_.Set(size); 191 | } 192 | const ::google::protobuf::Descriptor* HelloRequest::descriptor() { 193 | ::protobuf_hellostreamingworld_2eproto::protobuf_AssignDescriptorsOnce(); 194 | return ::protobuf_hellostreamingworld_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; 195 | } 196 | 197 | const HelloRequest& HelloRequest::default_instance() { 198 | ::google::protobuf::internal::InitSCC(&protobuf_hellostreamingworld_2eproto::scc_info_HelloRequest.base); 199 | return *internal_default_instance(); 200 | } 201 | 202 | 203 | void HelloRequest::Clear() { 204 | // @@protoc_insertion_point(message_clear_start:hellostreamingworld.HelloRequest) 205 | ::google::protobuf::uint32 cached_has_bits = 0; 206 | // Prevent compiler warnings about cached_has_bits being unused 207 | (void) cached_has_bits; 208 | 209 | name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 210 | num_greetings_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 211 | _internal_metadata_.Clear(); 212 | } 213 | 214 | bool HelloRequest::MergePartialFromCodedStream( 215 | ::google::protobuf::io::CodedInputStream* input) { 216 | #define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure 217 | ::google::protobuf::uint32 tag; 218 | // @@protoc_insertion_point(parse_start:hellostreamingworld.HelloRequest) 219 | for (;;) { 220 | ::std::pair<::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u); 221 | tag = p.first; 222 | if (!p.second) goto handle_unusual; 223 | switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { 224 | // string name = 1; 225 | case 1: { 226 | if (static_cast< ::google::protobuf::uint8>(tag) == 227 | static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { 228 | DO_(::google::protobuf::internal::WireFormatLite::ReadString( 229 | input, this->mutable_name())); 230 | DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( 231 | this->name().data(), static_cast(this->name().length()), 232 | ::google::protobuf::internal::WireFormatLite::PARSE, 233 | "hellostreamingworld.HelloRequest.name")); 234 | } else { 235 | goto handle_unusual; 236 | } 237 | break; 238 | } 239 | 240 | // string num_greetings = 2; 241 | case 2: { 242 | if (static_cast< ::google::protobuf::uint8>(tag) == 243 | static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { 244 | DO_(::google::protobuf::internal::WireFormatLite::ReadString( 245 | input, this->mutable_num_greetings())); 246 | DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( 247 | this->num_greetings().data(), static_cast(this->num_greetings().length()), 248 | ::google::protobuf::internal::WireFormatLite::PARSE, 249 | "hellostreamingworld.HelloRequest.num_greetings")); 250 | } else { 251 | goto handle_unusual; 252 | } 253 | break; 254 | } 255 | 256 | default: { 257 | handle_unusual: 258 | if (tag == 0) { 259 | goto success; 260 | } 261 | DO_(::google::protobuf::internal::WireFormat::SkipField( 262 | input, tag, _internal_metadata_.mutable_unknown_fields())); 263 | break; 264 | } 265 | } 266 | } 267 | success: 268 | // @@protoc_insertion_point(parse_success:hellostreamingworld.HelloRequest) 269 | return true; 270 | failure: 271 | // @@protoc_insertion_point(parse_failure:hellostreamingworld.HelloRequest) 272 | return false; 273 | #undef DO_ 274 | } 275 | 276 | void HelloRequest::SerializeWithCachedSizes( 277 | ::google::protobuf::io::CodedOutputStream* output) const { 278 | // @@protoc_insertion_point(serialize_start:hellostreamingworld.HelloRequest) 279 | ::google::protobuf::uint32 cached_has_bits = 0; 280 | (void) cached_has_bits; 281 | 282 | // string name = 1; 283 | if (this->name().size() > 0) { 284 | ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( 285 | this->name().data(), static_cast(this->name().length()), 286 | ::google::protobuf::internal::WireFormatLite::SERIALIZE, 287 | "hellostreamingworld.HelloRequest.name"); 288 | ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased( 289 | 1, this->name(), output); 290 | } 291 | 292 | // string num_greetings = 2; 293 | if (this->num_greetings().size() > 0) { 294 | ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( 295 | this->num_greetings().data(), static_cast(this->num_greetings().length()), 296 | ::google::protobuf::internal::WireFormatLite::SERIALIZE, 297 | "hellostreamingworld.HelloRequest.num_greetings"); 298 | ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased( 299 | 2, this->num_greetings(), output); 300 | } 301 | 302 | if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { 303 | ::google::protobuf::internal::WireFormat::SerializeUnknownFields( 304 | (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); 305 | } 306 | // @@protoc_insertion_point(serialize_end:hellostreamingworld.HelloRequest) 307 | } 308 | 309 | ::google::protobuf::uint8* HelloRequest::InternalSerializeWithCachedSizesToArray( 310 | bool deterministic, ::google::protobuf::uint8* target) const { 311 | (void)deterministic; // Unused 312 | // @@protoc_insertion_point(serialize_to_array_start:hellostreamingworld.HelloRequest) 313 | ::google::protobuf::uint32 cached_has_bits = 0; 314 | (void) cached_has_bits; 315 | 316 | // string name = 1; 317 | if (this->name().size() > 0) { 318 | ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( 319 | this->name().data(), static_cast(this->name().length()), 320 | ::google::protobuf::internal::WireFormatLite::SERIALIZE, 321 | "hellostreamingworld.HelloRequest.name"); 322 | target = 323 | ::google::protobuf::internal::WireFormatLite::WriteStringToArray( 324 | 1, this->name(), target); 325 | } 326 | 327 | // string num_greetings = 2; 328 | if (this->num_greetings().size() > 0) { 329 | ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( 330 | this->num_greetings().data(), static_cast(this->num_greetings().length()), 331 | ::google::protobuf::internal::WireFormatLite::SERIALIZE, 332 | "hellostreamingworld.HelloRequest.num_greetings"); 333 | target = 334 | ::google::protobuf::internal::WireFormatLite::WriteStringToArray( 335 | 2, this->num_greetings(), target); 336 | } 337 | 338 | if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { 339 | target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( 340 | (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); 341 | } 342 | // @@protoc_insertion_point(serialize_to_array_end:hellostreamingworld.HelloRequest) 343 | return target; 344 | } 345 | 346 | size_t HelloRequest::ByteSizeLong() const { 347 | // @@protoc_insertion_point(message_byte_size_start:hellostreamingworld.HelloRequest) 348 | size_t total_size = 0; 349 | 350 | if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { 351 | total_size += 352 | ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( 353 | (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); 354 | } 355 | // string name = 1; 356 | if (this->name().size() > 0) { 357 | total_size += 1 + 358 | ::google::protobuf::internal::WireFormatLite::StringSize( 359 | this->name()); 360 | } 361 | 362 | // string num_greetings = 2; 363 | if (this->num_greetings().size() > 0) { 364 | total_size += 1 + 365 | ::google::protobuf::internal::WireFormatLite::StringSize( 366 | this->num_greetings()); 367 | } 368 | 369 | int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); 370 | SetCachedSize(cached_size); 371 | return total_size; 372 | } 373 | 374 | void HelloRequest::MergeFrom(const ::google::protobuf::Message& from) { 375 | // @@protoc_insertion_point(generalized_merge_from_start:hellostreamingworld.HelloRequest) 376 | GOOGLE_DCHECK_NE(&from, this); 377 | const HelloRequest* source = 378 | ::google::protobuf::internal::DynamicCastToGenerated( 379 | &from); 380 | if (source == NULL) { 381 | // @@protoc_insertion_point(generalized_merge_from_cast_fail:hellostreamingworld.HelloRequest) 382 | ::google::protobuf::internal::ReflectionOps::Merge(from, this); 383 | } else { 384 | // @@protoc_insertion_point(generalized_merge_from_cast_success:hellostreamingworld.HelloRequest) 385 | MergeFrom(*source); 386 | } 387 | } 388 | 389 | void HelloRequest::MergeFrom(const HelloRequest& from) { 390 | // @@protoc_insertion_point(class_specific_merge_from_start:hellostreamingworld.HelloRequest) 391 | GOOGLE_DCHECK_NE(&from, this); 392 | _internal_metadata_.MergeFrom(from._internal_metadata_); 393 | ::google::protobuf::uint32 cached_has_bits = 0; 394 | (void) cached_has_bits; 395 | 396 | if (from.name().size() > 0) { 397 | 398 | name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_); 399 | } 400 | if (from.num_greetings().size() > 0) { 401 | 402 | num_greetings_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.num_greetings_); 403 | } 404 | } 405 | 406 | void HelloRequest::CopyFrom(const ::google::protobuf::Message& from) { 407 | // @@protoc_insertion_point(generalized_copy_from_start:hellostreamingworld.HelloRequest) 408 | if (&from == this) return; 409 | Clear(); 410 | MergeFrom(from); 411 | } 412 | 413 | void HelloRequest::CopyFrom(const HelloRequest& from) { 414 | // @@protoc_insertion_point(class_specific_copy_from_start:hellostreamingworld.HelloRequest) 415 | if (&from == this) return; 416 | Clear(); 417 | MergeFrom(from); 418 | } 419 | 420 | bool HelloRequest::IsInitialized() const { 421 | return true; 422 | } 423 | 424 | void HelloRequest::Swap(HelloRequest* other) { 425 | if (other == this) return; 426 | InternalSwap(other); 427 | } 428 | void HelloRequest::InternalSwap(HelloRequest* other) { 429 | using std::swap; 430 | name_.Swap(&other->name_, &::google::protobuf::internal::GetEmptyStringAlreadyInited(), 431 | GetArenaNoVirtual()); 432 | num_greetings_.Swap(&other->num_greetings_, &::google::protobuf::internal::GetEmptyStringAlreadyInited(), 433 | GetArenaNoVirtual()); 434 | _internal_metadata_.Swap(&other->_internal_metadata_); 435 | } 436 | 437 | ::google::protobuf::Metadata HelloRequest::GetMetadata() const { 438 | protobuf_hellostreamingworld_2eproto::protobuf_AssignDescriptorsOnce(); 439 | return ::protobuf_hellostreamingworld_2eproto::file_level_metadata[kIndexInFileMessages]; 440 | } 441 | 442 | 443 | // =================================================================== 444 | 445 | void HelloReply::InitAsDefaultInstance() { 446 | } 447 | #if !defined(_MSC_VER) || _MSC_VER >= 1900 448 | const int HelloReply::kMessageFieldNumber; 449 | #endif // !defined(_MSC_VER) || _MSC_VER >= 1900 450 | 451 | HelloReply::HelloReply() 452 | : ::google::protobuf::Message(), _internal_metadata_(NULL) { 453 | ::google::protobuf::internal::InitSCC( 454 | &protobuf_hellostreamingworld_2eproto::scc_info_HelloReply.base); 455 | SharedCtor(); 456 | // @@protoc_insertion_point(constructor:hellostreamingworld.HelloReply) 457 | } 458 | HelloReply::HelloReply(const HelloReply& from) 459 | : ::google::protobuf::Message(), 460 | _internal_metadata_(NULL) { 461 | _internal_metadata_.MergeFrom(from._internal_metadata_); 462 | message_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 463 | if (from.message().size() > 0) { 464 | message_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.message_); 465 | } 466 | // @@protoc_insertion_point(copy_constructor:hellostreamingworld.HelloReply) 467 | } 468 | 469 | void HelloReply::SharedCtor() { 470 | message_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 471 | } 472 | 473 | HelloReply::~HelloReply() { 474 | // @@protoc_insertion_point(destructor:hellostreamingworld.HelloReply) 475 | SharedDtor(); 476 | } 477 | 478 | void HelloReply::SharedDtor() { 479 | message_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 480 | } 481 | 482 | void HelloReply::SetCachedSize(int size) const { 483 | _cached_size_.Set(size); 484 | } 485 | const ::google::protobuf::Descriptor* HelloReply::descriptor() { 486 | ::protobuf_hellostreamingworld_2eproto::protobuf_AssignDescriptorsOnce(); 487 | return ::protobuf_hellostreamingworld_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; 488 | } 489 | 490 | const HelloReply& HelloReply::default_instance() { 491 | ::google::protobuf::internal::InitSCC(&protobuf_hellostreamingworld_2eproto::scc_info_HelloReply.base); 492 | return *internal_default_instance(); 493 | } 494 | 495 | 496 | void HelloReply::Clear() { 497 | // @@protoc_insertion_point(message_clear_start:hellostreamingworld.HelloReply) 498 | ::google::protobuf::uint32 cached_has_bits = 0; 499 | // Prevent compiler warnings about cached_has_bits being unused 500 | (void) cached_has_bits; 501 | 502 | message_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 503 | _internal_metadata_.Clear(); 504 | } 505 | 506 | bool HelloReply::MergePartialFromCodedStream( 507 | ::google::protobuf::io::CodedInputStream* input) { 508 | #define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure 509 | ::google::protobuf::uint32 tag; 510 | // @@protoc_insertion_point(parse_start:hellostreamingworld.HelloReply) 511 | for (;;) { 512 | ::std::pair<::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u); 513 | tag = p.first; 514 | if (!p.second) goto handle_unusual; 515 | switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { 516 | // string message = 1; 517 | case 1: { 518 | if (static_cast< ::google::protobuf::uint8>(tag) == 519 | static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { 520 | DO_(::google::protobuf::internal::WireFormatLite::ReadString( 521 | input, this->mutable_message())); 522 | DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( 523 | this->message().data(), static_cast(this->message().length()), 524 | ::google::protobuf::internal::WireFormatLite::PARSE, 525 | "hellostreamingworld.HelloReply.message")); 526 | } else { 527 | goto handle_unusual; 528 | } 529 | break; 530 | } 531 | 532 | default: { 533 | handle_unusual: 534 | if (tag == 0) { 535 | goto success; 536 | } 537 | DO_(::google::protobuf::internal::WireFormat::SkipField( 538 | input, tag, _internal_metadata_.mutable_unknown_fields())); 539 | break; 540 | } 541 | } 542 | } 543 | success: 544 | // @@protoc_insertion_point(parse_success:hellostreamingworld.HelloReply) 545 | return true; 546 | failure: 547 | // @@protoc_insertion_point(parse_failure:hellostreamingworld.HelloReply) 548 | return false; 549 | #undef DO_ 550 | } 551 | 552 | void HelloReply::SerializeWithCachedSizes( 553 | ::google::protobuf::io::CodedOutputStream* output) const { 554 | // @@protoc_insertion_point(serialize_start:hellostreamingworld.HelloReply) 555 | ::google::protobuf::uint32 cached_has_bits = 0; 556 | (void) cached_has_bits; 557 | 558 | // string message = 1; 559 | if (this->message().size() > 0) { 560 | ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( 561 | this->message().data(), static_cast(this->message().length()), 562 | ::google::protobuf::internal::WireFormatLite::SERIALIZE, 563 | "hellostreamingworld.HelloReply.message"); 564 | ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased( 565 | 1, this->message(), output); 566 | } 567 | 568 | if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { 569 | ::google::protobuf::internal::WireFormat::SerializeUnknownFields( 570 | (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); 571 | } 572 | // @@protoc_insertion_point(serialize_end:hellostreamingworld.HelloReply) 573 | } 574 | 575 | ::google::protobuf::uint8* HelloReply::InternalSerializeWithCachedSizesToArray( 576 | bool deterministic, ::google::protobuf::uint8* target) const { 577 | (void)deterministic; // Unused 578 | // @@protoc_insertion_point(serialize_to_array_start:hellostreamingworld.HelloReply) 579 | ::google::protobuf::uint32 cached_has_bits = 0; 580 | (void) cached_has_bits; 581 | 582 | // string message = 1; 583 | if (this->message().size() > 0) { 584 | ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( 585 | this->message().data(), static_cast(this->message().length()), 586 | ::google::protobuf::internal::WireFormatLite::SERIALIZE, 587 | "hellostreamingworld.HelloReply.message"); 588 | target = 589 | ::google::protobuf::internal::WireFormatLite::WriteStringToArray( 590 | 1, this->message(), target); 591 | } 592 | 593 | if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { 594 | target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( 595 | (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); 596 | } 597 | // @@protoc_insertion_point(serialize_to_array_end:hellostreamingworld.HelloReply) 598 | return target; 599 | } 600 | 601 | size_t HelloReply::ByteSizeLong() const { 602 | // @@protoc_insertion_point(message_byte_size_start:hellostreamingworld.HelloReply) 603 | size_t total_size = 0; 604 | 605 | if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { 606 | total_size += 607 | ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( 608 | (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); 609 | } 610 | // string message = 1; 611 | if (this->message().size() > 0) { 612 | total_size += 1 + 613 | ::google::protobuf::internal::WireFormatLite::StringSize( 614 | this->message()); 615 | } 616 | 617 | int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); 618 | SetCachedSize(cached_size); 619 | return total_size; 620 | } 621 | 622 | void HelloReply::MergeFrom(const ::google::protobuf::Message& from) { 623 | // @@protoc_insertion_point(generalized_merge_from_start:hellostreamingworld.HelloReply) 624 | GOOGLE_DCHECK_NE(&from, this); 625 | const HelloReply* source = 626 | ::google::protobuf::internal::DynamicCastToGenerated( 627 | &from); 628 | if (source == NULL) { 629 | // @@protoc_insertion_point(generalized_merge_from_cast_fail:hellostreamingworld.HelloReply) 630 | ::google::protobuf::internal::ReflectionOps::Merge(from, this); 631 | } else { 632 | // @@protoc_insertion_point(generalized_merge_from_cast_success:hellostreamingworld.HelloReply) 633 | MergeFrom(*source); 634 | } 635 | } 636 | 637 | void HelloReply::MergeFrom(const HelloReply& from) { 638 | // @@protoc_insertion_point(class_specific_merge_from_start:hellostreamingworld.HelloReply) 639 | GOOGLE_DCHECK_NE(&from, this); 640 | _internal_metadata_.MergeFrom(from._internal_metadata_); 641 | ::google::protobuf::uint32 cached_has_bits = 0; 642 | (void) cached_has_bits; 643 | 644 | if (from.message().size() > 0) { 645 | 646 | message_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.message_); 647 | } 648 | } 649 | 650 | void HelloReply::CopyFrom(const ::google::protobuf::Message& from) { 651 | // @@protoc_insertion_point(generalized_copy_from_start:hellostreamingworld.HelloReply) 652 | if (&from == this) return; 653 | Clear(); 654 | MergeFrom(from); 655 | } 656 | 657 | void HelloReply::CopyFrom(const HelloReply& from) { 658 | // @@protoc_insertion_point(class_specific_copy_from_start:hellostreamingworld.HelloReply) 659 | if (&from == this) return; 660 | Clear(); 661 | MergeFrom(from); 662 | } 663 | 664 | bool HelloReply::IsInitialized() const { 665 | return true; 666 | } 667 | 668 | void HelloReply::Swap(HelloReply* other) { 669 | if (other == this) return; 670 | InternalSwap(other); 671 | } 672 | void HelloReply::InternalSwap(HelloReply* other) { 673 | using std::swap; 674 | message_.Swap(&other->message_, &::google::protobuf::internal::GetEmptyStringAlreadyInited(), 675 | GetArenaNoVirtual()); 676 | _internal_metadata_.Swap(&other->_internal_metadata_); 677 | } 678 | 679 | ::google::protobuf::Metadata HelloReply::GetMetadata() const { 680 | protobuf_hellostreamingworld_2eproto::protobuf_AssignDescriptorsOnce(); 681 | return ::protobuf_hellostreamingworld_2eproto::file_level_metadata[kIndexInFileMessages]; 682 | } 683 | 684 | 685 | // @@protoc_insertion_point(namespace_scope) 686 | } // namespace hellostreamingworld 687 | namespace google { 688 | namespace protobuf { 689 | template<> GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE ::hellostreamingworld::HelloRequest* Arena::CreateMaybeMessage< ::hellostreamingworld::HelloRequest >(Arena* arena) { 690 | return Arena::CreateInternal< ::hellostreamingworld::HelloRequest >(arena); 691 | } 692 | template<> GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE ::hellostreamingworld::HelloReply* Arena::CreateMaybeMessage< ::hellostreamingworld::HelloReply >(Arena* arena) { 693 | return Arena::CreateInternal< ::hellostreamingworld::HelloReply >(arena); 694 | } 695 | } // namespace protobuf 696 | } // namespace google 697 | 698 | // @@protoc_insertion_point(global_scope) 699 | -------------------------------------------------------------------------------- /hellostreamingworld.pb.h: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: hellostreamingworld.proto 3 | 4 | #ifndef PROTOBUF_INCLUDED_hellostreamingworld_2eproto 5 | #define PROTOBUF_INCLUDED_hellostreamingworld_2eproto 6 | 7 | #include 8 | 9 | #include 10 | 11 | #if GOOGLE_PROTOBUF_VERSION < 3006001 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 3006001 < 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 29 | #include 30 | #include // IWYU pragma: export 31 | #include // IWYU pragma: export 32 | #include 33 | // @@protoc_insertion_point(includes) 34 | #define PROTOBUF_INTERNAL_EXPORT_protobuf_hellostreamingworld_2eproto 35 | 36 | namespace protobuf_hellostreamingworld_2eproto { 37 | // Internal implementation detail -- do not use these members. 38 | struct TableStruct { 39 | static const ::google::protobuf::internal::ParseTableField entries[]; 40 | static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; 41 | static const ::google::protobuf::internal::ParseTable schema[2]; 42 | static const ::google::protobuf::internal::FieldMetadata field_metadata[]; 43 | static const ::google::protobuf::internal::SerializationTable serialization_table[]; 44 | static const ::google::protobuf::uint32 offsets[]; 45 | }; 46 | void AddDescriptors(); 47 | } // namespace protobuf_hellostreamingworld_2eproto 48 | namespace hellostreamingworld { 49 | class HelloReply; 50 | class HelloReplyDefaultTypeInternal; 51 | extern HelloReplyDefaultTypeInternal _HelloReply_default_instance_; 52 | class HelloRequest; 53 | class HelloRequestDefaultTypeInternal; 54 | extern HelloRequestDefaultTypeInternal _HelloRequest_default_instance_; 55 | } // namespace hellostreamingworld 56 | namespace google { 57 | namespace protobuf { 58 | template<> ::hellostreamingworld::HelloReply* Arena::CreateMaybeMessage<::hellostreamingworld::HelloReply>(Arena*); 59 | template<> ::hellostreamingworld::HelloRequest* Arena::CreateMaybeMessage<::hellostreamingworld::HelloRequest>(Arena*); 60 | } // namespace protobuf 61 | } // namespace google 62 | namespace hellostreamingworld { 63 | 64 | // =================================================================== 65 | 66 | class HelloRequest : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:hellostreamingworld.HelloRequest) */ { 67 | public: 68 | HelloRequest(); 69 | virtual ~HelloRequest(); 70 | 71 | HelloRequest(const HelloRequest& from); 72 | 73 | inline HelloRequest& operator=(const HelloRequest& from) { 74 | CopyFrom(from); 75 | return *this; 76 | } 77 | #if LANG_CXX11 78 | HelloRequest(HelloRequest&& from) noexcept 79 | : HelloRequest() { 80 | *this = ::std::move(from); 81 | } 82 | 83 | inline HelloRequest& operator=(HelloRequest&& from) noexcept { 84 | if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { 85 | if (this != &from) InternalSwap(&from); 86 | } else { 87 | CopyFrom(from); 88 | } 89 | return *this; 90 | } 91 | #endif 92 | static const ::google::protobuf::Descriptor* descriptor(); 93 | static const HelloRequest& default_instance(); 94 | 95 | static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY 96 | static inline const HelloRequest* internal_default_instance() { 97 | return reinterpret_cast( 98 | &_HelloRequest_default_instance_); 99 | } 100 | static constexpr int kIndexInFileMessages = 101 | 0; 102 | 103 | void Swap(HelloRequest* other); 104 | friend void swap(HelloRequest& a, HelloRequest& b) { 105 | a.Swap(&b); 106 | } 107 | 108 | // implements Message ---------------------------------------------- 109 | 110 | inline HelloRequest* New() const final { 111 | return CreateMaybeMessage(NULL); 112 | } 113 | 114 | HelloRequest* New(::google::protobuf::Arena* arena) const final { 115 | return CreateMaybeMessage(arena); 116 | } 117 | void CopyFrom(const ::google::protobuf::Message& from) final; 118 | void MergeFrom(const ::google::protobuf::Message& from) final; 119 | void CopyFrom(const HelloRequest& from); 120 | void MergeFrom(const HelloRequest& from); 121 | void Clear() final; 122 | bool IsInitialized() const final; 123 | 124 | size_t ByteSizeLong() const final; 125 | bool MergePartialFromCodedStream( 126 | ::google::protobuf::io::CodedInputStream* input) final; 127 | void SerializeWithCachedSizes( 128 | ::google::protobuf::io::CodedOutputStream* output) const final; 129 | ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( 130 | bool deterministic, ::google::protobuf::uint8* target) const final; 131 | int GetCachedSize() const final { return _cached_size_.Get(); } 132 | 133 | private: 134 | void SharedCtor(); 135 | void SharedDtor(); 136 | void SetCachedSize(int size) const final; 137 | void InternalSwap(HelloRequest* other); 138 | private: 139 | inline ::google::protobuf::Arena* GetArenaNoVirtual() const { 140 | return NULL; 141 | } 142 | inline void* MaybeArenaPtr() const { 143 | return NULL; 144 | } 145 | public: 146 | 147 | ::google::protobuf::Metadata GetMetadata() const final; 148 | 149 | // nested types ---------------------------------------------------- 150 | 151 | // accessors ------------------------------------------------------- 152 | 153 | // string name = 1; 154 | void clear_name(); 155 | static const int kNameFieldNumber = 1; 156 | const ::std::string& name() const; 157 | void set_name(const ::std::string& value); 158 | #if LANG_CXX11 159 | void set_name(::std::string&& value); 160 | #endif 161 | void set_name(const char* value); 162 | void set_name(const char* value, size_t size); 163 | ::std::string* mutable_name(); 164 | ::std::string* release_name(); 165 | void set_allocated_name(::std::string* name); 166 | 167 | // string num_greetings = 2; 168 | void clear_num_greetings(); 169 | static const int kNumGreetingsFieldNumber = 2; 170 | const ::std::string& num_greetings() const; 171 | void set_num_greetings(const ::std::string& value); 172 | #if LANG_CXX11 173 | void set_num_greetings(::std::string&& value); 174 | #endif 175 | void set_num_greetings(const char* value); 176 | void set_num_greetings(const char* value, size_t size); 177 | ::std::string* mutable_num_greetings(); 178 | ::std::string* release_num_greetings(); 179 | void set_allocated_num_greetings(::std::string* num_greetings); 180 | 181 | // @@protoc_insertion_point(class_scope:hellostreamingworld.HelloRequest) 182 | private: 183 | 184 | ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; 185 | ::google::protobuf::internal::ArenaStringPtr name_; 186 | ::google::protobuf::internal::ArenaStringPtr num_greetings_; 187 | mutable ::google::protobuf::internal::CachedSize _cached_size_; 188 | friend struct ::protobuf_hellostreamingworld_2eproto::TableStruct; 189 | }; 190 | // ------------------------------------------------------------------- 191 | 192 | class HelloReply : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:hellostreamingworld.HelloReply) */ { 193 | public: 194 | HelloReply(); 195 | virtual ~HelloReply(); 196 | 197 | HelloReply(const HelloReply& from); 198 | 199 | inline HelloReply& operator=(const HelloReply& from) { 200 | CopyFrom(from); 201 | return *this; 202 | } 203 | #if LANG_CXX11 204 | HelloReply(HelloReply&& from) noexcept 205 | : HelloReply() { 206 | *this = ::std::move(from); 207 | } 208 | 209 | inline HelloReply& operator=(HelloReply&& from) noexcept { 210 | if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { 211 | if (this != &from) InternalSwap(&from); 212 | } else { 213 | CopyFrom(from); 214 | } 215 | return *this; 216 | } 217 | #endif 218 | static const ::google::protobuf::Descriptor* descriptor(); 219 | static const HelloReply& default_instance(); 220 | 221 | static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY 222 | static inline const HelloReply* internal_default_instance() { 223 | return reinterpret_cast( 224 | &_HelloReply_default_instance_); 225 | } 226 | static constexpr int kIndexInFileMessages = 227 | 1; 228 | 229 | void Swap(HelloReply* other); 230 | friend void swap(HelloReply& a, HelloReply& b) { 231 | a.Swap(&b); 232 | } 233 | 234 | // implements Message ---------------------------------------------- 235 | 236 | inline HelloReply* New() const final { 237 | return CreateMaybeMessage(NULL); 238 | } 239 | 240 | HelloReply* New(::google::protobuf::Arena* arena) const final { 241 | return CreateMaybeMessage(arena); 242 | } 243 | void CopyFrom(const ::google::protobuf::Message& from) final; 244 | void MergeFrom(const ::google::protobuf::Message& from) final; 245 | void CopyFrom(const HelloReply& from); 246 | void MergeFrom(const HelloReply& from); 247 | void Clear() final; 248 | bool IsInitialized() const final; 249 | 250 | size_t ByteSizeLong() const final; 251 | bool MergePartialFromCodedStream( 252 | ::google::protobuf::io::CodedInputStream* input) final; 253 | void SerializeWithCachedSizes( 254 | ::google::protobuf::io::CodedOutputStream* output) const final; 255 | ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( 256 | bool deterministic, ::google::protobuf::uint8* target) const final; 257 | int GetCachedSize() const final { return _cached_size_.Get(); } 258 | 259 | private: 260 | void SharedCtor(); 261 | void SharedDtor(); 262 | void SetCachedSize(int size) const final; 263 | void InternalSwap(HelloReply* other); 264 | private: 265 | inline ::google::protobuf::Arena* GetArenaNoVirtual() const { 266 | return NULL; 267 | } 268 | inline void* MaybeArenaPtr() const { 269 | return NULL; 270 | } 271 | public: 272 | 273 | ::google::protobuf::Metadata GetMetadata() const final; 274 | 275 | // nested types ---------------------------------------------------- 276 | 277 | // accessors ------------------------------------------------------- 278 | 279 | // string message = 1; 280 | void clear_message(); 281 | static const int kMessageFieldNumber = 1; 282 | const ::std::string& message() const; 283 | void set_message(const ::std::string& value); 284 | #if LANG_CXX11 285 | void set_message(::std::string&& value); 286 | #endif 287 | void set_message(const char* value); 288 | void set_message(const char* value, size_t size); 289 | ::std::string* mutable_message(); 290 | ::std::string* release_message(); 291 | void set_allocated_message(::std::string* message); 292 | 293 | // @@protoc_insertion_point(class_scope:hellostreamingworld.HelloReply) 294 | private: 295 | 296 | ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; 297 | ::google::protobuf::internal::ArenaStringPtr message_; 298 | mutable ::google::protobuf::internal::CachedSize _cached_size_; 299 | friend struct ::protobuf_hellostreamingworld_2eproto::TableStruct; 300 | }; 301 | // =================================================================== 302 | 303 | 304 | // =================================================================== 305 | 306 | #ifdef __GNUC__ 307 | #pragma GCC diagnostic push 308 | #pragma GCC diagnostic ignored "-Wstrict-aliasing" 309 | #endif // __GNUC__ 310 | // HelloRequest 311 | 312 | // string name = 1; 313 | inline void HelloRequest::clear_name() { 314 | name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 315 | } 316 | inline const ::std::string& HelloRequest::name() const { 317 | // @@protoc_insertion_point(field_get:hellostreamingworld.HelloRequest.name) 318 | return name_.GetNoArena(); 319 | } 320 | inline void HelloRequest::set_name(const ::std::string& value) { 321 | 322 | name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); 323 | // @@protoc_insertion_point(field_set:hellostreamingworld.HelloRequest.name) 324 | } 325 | #if LANG_CXX11 326 | inline void HelloRequest::set_name(::std::string&& value) { 327 | 328 | name_.SetNoArena( 329 | &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); 330 | // @@protoc_insertion_point(field_set_rvalue:hellostreamingworld.HelloRequest.name) 331 | } 332 | #endif 333 | inline void HelloRequest::set_name(const char* value) { 334 | GOOGLE_DCHECK(value != NULL); 335 | 336 | name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); 337 | // @@protoc_insertion_point(field_set_char:hellostreamingworld.HelloRequest.name) 338 | } 339 | inline void HelloRequest::set_name(const char* value, size_t size) { 340 | 341 | name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), 342 | ::std::string(reinterpret_cast(value), size)); 343 | // @@protoc_insertion_point(field_set_pointer:hellostreamingworld.HelloRequest.name) 344 | } 345 | inline ::std::string* HelloRequest::mutable_name() { 346 | 347 | // @@protoc_insertion_point(field_mutable:hellostreamingworld.HelloRequest.name) 348 | return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 349 | } 350 | inline ::std::string* HelloRequest::release_name() { 351 | // @@protoc_insertion_point(field_release:hellostreamingworld.HelloRequest.name) 352 | 353 | return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 354 | } 355 | inline void HelloRequest::set_allocated_name(::std::string* name) { 356 | if (name != NULL) { 357 | 358 | } else { 359 | 360 | } 361 | name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); 362 | // @@protoc_insertion_point(field_set_allocated:hellostreamingworld.HelloRequest.name) 363 | } 364 | 365 | // string num_greetings = 2; 366 | inline void HelloRequest::clear_num_greetings() { 367 | num_greetings_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 368 | } 369 | inline const ::std::string& HelloRequest::num_greetings() const { 370 | // @@protoc_insertion_point(field_get:hellostreamingworld.HelloRequest.num_greetings) 371 | return num_greetings_.GetNoArena(); 372 | } 373 | inline void HelloRequest::set_num_greetings(const ::std::string& value) { 374 | 375 | num_greetings_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); 376 | // @@protoc_insertion_point(field_set:hellostreamingworld.HelloRequest.num_greetings) 377 | } 378 | #if LANG_CXX11 379 | inline void HelloRequest::set_num_greetings(::std::string&& value) { 380 | 381 | num_greetings_.SetNoArena( 382 | &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); 383 | // @@protoc_insertion_point(field_set_rvalue:hellostreamingworld.HelloRequest.num_greetings) 384 | } 385 | #endif 386 | inline void HelloRequest::set_num_greetings(const char* value) { 387 | GOOGLE_DCHECK(value != NULL); 388 | 389 | num_greetings_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); 390 | // @@protoc_insertion_point(field_set_char:hellostreamingworld.HelloRequest.num_greetings) 391 | } 392 | inline void HelloRequest::set_num_greetings(const char* value, size_t size) { 393 | 394 | num_greetings_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), 395 | ::std::string(reinterpret_cast(value), size)); 396 | // @@protoc_insertion_point(field_set_pointer:hellostreamingworld.HelloRequest.num_greetings) 397 | } 398 | inline ::std::string* HelloRequest::mutable_num_greetings() { 399 | 400 | // @@protoc_insertion_point(field_mutable:hellostreamingworld.HelloRequest.num_greetings) 401 | return num_greetings_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 402 | } 403 | inline ::std::string* HelloRequest::release_num_greetings() { 404 | // @@protoc_insertion_point(field_release:hellostreamingworld.HelloRequest.num_greetings) 405 | 406 | return num_greetings_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 407 | } 408 | inline void HelloRequest::set_allocated_num_greetings(::std::string* num_greetings) { 409 | if (num_greetings != NULL) { 410 | 411 | } else { 412 | 413 | } 414 | num_greetings_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), num_greetings); 415 | // @@protoc_insertion_point(field_set_allocated:hellostreamingworld.HelloRequest.num_greetings) 416 | } 417 | 418 | // ------------------------------------------------------------------- 419 | 420 | // HelloReply 421 | 422 | // string message = 1; 423 | inline void HelloReply::clear_message() { 424 | message_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 425 | } 426 | inline const ::std::string& HelloReply::message() const { 427 | // @@protoc_insertion_point(field_get:hellostreamingworld.HelloReply.message) 428 | return message_.GetNoArena(); 429 | } 430 | inline void HelloReply::set_message(const ::std::string& value) { 431 | 432 | message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); 433 | // @@protoc_insertion_point(field_set:hellostreamingworld.HelloReply.message) 434 | } 435 | #if LANG_CXX11 436 | inline void HelloReply::set_message(::std::string&& value) { 437 | 438 | message_.SetNoArena( 439 | &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); 440 | // @@protoc_insertion_point(field_set_rvalue:hellostreamingworld.HelloReply.message) 441 | } 442 | #endif 443 | inline void HelloReply::set_message(const char* value) { 444 | GOOGLE_DCHECK(value != NULL); 445 | 446 | message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); 447 | // @@protoc_insertion_point(field_set_char:hellostreamingworld.HelloReply.message) 448 | } 449 | inline void HelloReply::set_message(const char* value, size_t size) { 450 | 451 | message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), 452 | ::std::string(reinterpret_cast(value), size)); 453 | // @@protoc_insertion_point(field_set_pointer:hellostreamingworld.HelloReply.message) 454 | } 455 | inline ::std::string* HelloReply::mutable_message() { 456 | 457 | // @@protoc_insertion_point(field_mutable:hellostreamingworld.HelloReply.message) 458 | return message_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 459 | } 460 | inline ::std::string* HelloReply::release_message() { 461 | // @@protoc_insertion_point(field_release:hellostreamingworld.HelloReply.message) 462 | 463 | return message_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 464 | } 465 | inline void HelloReply::set_allocated_message(::std::string* message) { 466 | if (message != NULL) { 467 | 468 | } else { 469 | 470 | } 471 | message_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), message); 472 | // @@protoc_insertion_point(field_set_allocated:hellostreamingworld.HelloReply.message) 473 | } 474 | 475 | #ifdef __GNUC__ 476 | #pragma GCC diagnostic pop 477 | #endif // __GNUC__ 478 | // ------------------------------------------------------------------- 479 | 480 | 481 | // @@protoc_insertion_point(namespace_scope) 482 | 483 | } // namespace hellostreamingworld 484 | 485 | // @@protoc_insertion_point(global_scope) 486 | 487 | #endif // PROTOBUF_INCLUDED_hellostreamingworld_2eproto 488 | --------------------------------------------------------------------------------