├── .gitignore
├── RpcServer
├── RpcServer.sln
└── RpcServer
│ ├── RPCServerService.cpp
│ ├── RPCServerService.h
│ ├── ReadMe.txt
│ ├── RpcMain.cpp
│ ├── RpcServer.vcxproj
│ ├── RpcServer.vcxproj.filters
│ ├── TcpConnect.cpp
│ ├── TcpConnect.h
│ ├── echo.pb.cc
│ ├── echo.pb.h
│ ├── stdafx.cpp
│ ├── stdafx.h
│ └── targetver.h
├── echo.proto
└── readme.md
/.gitignore:
--------------------------------------------------------------------------------
1 | #################
2 | ## Eclipse
3 | #################
4 |
5 | *.pydevproject
6 | .project
7 | .metadata
8 | bin/
9 | tmp/
10 | *.tmp
11 | *.bak
12 | *.swp
13 | *~.nib
14 | local.properties
15 | .classpath
16 | .settings/
17 | .loadpath
18 | RpcClient/Debug
19 | RpcClient/ipch
20 | RpcClient/RpcClient/Debug
21 | RpcClient/RpcClient/protobuf-lite
22 | RpcServer/Debug
23 | RpcServer/ipch
24 | RpcServer/RpcServer/Debug
25 | RpcServer/RpcServer/protobuf-lite
26 | # External tool builders
27 | .externalToolBuilders/
28 |
29 | # Locally stored "Eclipse launch configurations"
30 | *.launch
31 |
32 | # CDT-specific
33 | .cproject
34 |
35 | # PDT-specific
36 | .buildpath
37 |
38 |
39 | #################
40 | ## Visual Studio
41 | #################
42 |
43 | ## Ignore Visual Studio temporary files, build results, and
44 | ## files generated by popular Visual Studio add-ons.
45 |
46 | # User-specific files
47 | *.suo
48 | *.user
49 | *.sln.docstates
50 |
51 | # Build results
52 |
53 | [Dd]ebug/
54 | [Rr]elease/
55 | x64/
56 | build/
57 | [Bb]in/
58 | [Oo]bj/
59 |
60 | # MSTest test Results
61 | [Tt]est[Rr]esult*/
62 | [Bb]uild[Ll]og.*
63 |
64 | *_i.c
65 | *_p.c
66 | *.ilk
67 | *.meta
68 | *.obj
69 | *.pch
70 | *.pdb
71 | *.pgc
72 | *.pgd
73 | *.rsp
74 | *.sbr
75 | *.tlb
76 | *.tli
77 | *.tlh
78 | *.tmp
79 | *.tmp_proj
80 | *.log
81 | *.vspscc
82 | *.vssscc
83 | .builds
84 | *.pidb
85 | *.log
86 | *.scc
87 |
88 | # Visual C++ cache files
89 | ipch/
90 | *.aps
91 | *.ncb
92 | *.opensdf
93 | *.sdf
94 | *.cachefile
95 |
96 | # Visual Studio profiler
97 | *.psess
98 | *.vsp
99 | *.vspx
100 |
101 | # Guidance Automation Toolkit
102 | *.gpState
103 |
104 | # ReSharper is a .NET coding add-in
105 | _ReSharper*/
106 | *.[Rr]e[Ss]harper
107 |
108 | # TeamCity is a build add-in
109 | _TeamCity*
110 |
111 | # DotCover is a Code Coverage Tool
112 | *.dotCover
113 |
114 | # NCrunch
115 | *.ncrunch*
116 | .*crunch*.local.xml
117 |
118 | # Installshield output folder
119 | [Ee]xpress/
120 |
121 | # DocProject is a documentation generator add-in
122 | DocProject/buildhelp/
123 | DocProject/Help/*.HxT
124 | DocProject/Help/*.HxC
125 | DocProject/Help/*.hhc
126 | DocProject/Help/*.hhk
127 | DocProject/Help/*.hhp
128 | DocProject/Help/Html2
129 | DocProject/Help/html
130 |
131 | # Click-Once directory
132 | publish/
133 |
134 | # Publish Web Output
135 | *.Publish.xml
136 | *.pubxml
137 | *.publishproj
138 |
139 | # NuGet Packages Directory
140 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line
141 | #packages/
142 |
143 | # Windows Azure Build Output
144 | csx
145 | *.build.csdef
146 |
147 | # Windows Store app package directory
148 | AppPackages/
149 |
150 | # Others
151 | sql/
152 | *.Cache
153 | ClientBin/
154 | [Ss]tyle[Cc]op.*
155 | ~$*
156 | *~
157 | *.dbmdl
158 | *.[Pp]ublish.xml
159 | *.pfx
160 | *.publishsettings
161 |
162 | # RIA/Silverlight projects
163 | Generated_Code/
164 |
165 | # Backup & report files from converting an old project file to a newer
166 | # Visual Studio version. Backup files are not needed, because we have git ;-)
167 | _UpgradeReport_Files/
168 | Backup*/
169 | UpgradeLog*.XML
170 | UpgradeLog*.htm
171 |
172 | # SQL Server files
173 | App_Data/*.mdf
174 | App_Data/*.ldf
175 |
176 | #############
177 | ## Windows detritus
178 | #############
179 |
180 | # Windows image file caches
181 | Thumbs.db
182 | ehthumbs.db
183 |
184 | # Folder config file
185 | Desktop.ini
186 |
187 | # Recycle Bin used on file shares
188 | $RECYCLE.BIN/
189 |
190 | # Mac crap
191 | .DS_Store
192 |
193 |
194 | #############
195 | ## Python
196 | #############
197 |
198 | *.py[cod]
199 |
200 | # Packages
201 | *.egg
202 | *.egg-info
203 | dist/
204 | build/
205 | eggs/
206 | parts/
207 | var/
208 | sdist/
209 | develop-eggs/
210 | .installed.cfg
211 |
212 | # Installer logs
213 | pip-log.txt
214 |
215 | # Unit test / coverage reports
216 | .coverage
217 | .tox
218 |
219 | #Translations
220 | *.mo
221 |
222 | #Mr Developer
223 | .mr.developer.cfg
224 |
--------------------------------------------------------------------------------
/RpcServer/RpcServer.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2012
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RpcServer", "RpcServer\RpcServer.vcxproj", "{21392AA9-FF2A-4923-B67A-9542B6D6B7D4}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Win32 = Debug|Win32
9 | Release|Win32 = Release|Win32
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {21392AA9-FF2A-4923-B67A-9542B6D6B7D4}.Debug|Win32.ActiveCfg = Debug|Win32
13 | {21392AA9-FF2A-4923-B67A-9542B6D6B7D4}.Debug|Win32.Build.0 = Debug|Win32
14 | {21392AA9-FF2A-4923-B67A-9542B6D6B7D4}.Release|Win32.ActiveCfg = Release|Win32
15 | {21392AA9-FF2A-4923-B67A-9542B6D6B7D4}.Release|Win32.Build.0 = Release|Win32
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | EndGlobal
21 |
--------------------------------------------------------------------------------
/RpcServer/RpcServer/RPCServerService.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shinepengwei/miniRPC/a3cb09c3522b114476b9b1c3e2ab2eda52e8a12e/RpcServer/RpcServer/RPCServerService.cpp
--------------------------------------------------------------------------------
/RpcServer/RpcServer/RPCServerService.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shinepengwei/miniRPC/a3cb09c3522b114476b9b1c3e2ab2eda52e8a12e/RpcServer/RpcServer/RPCServerService.h
--------------------------------------------------------------------------------
/RpcServer/RpcServer/ReadMe.txt:
--------------------------------------------------------------------------------
1 | ========================================================================
2 | 控制台应用程序:RpcServer 项目概述
3 | ========================================================================
4 |
5 | 应用程序向导已为您创建了此 RpcServer 应用程序。
6 |
7 | 本文件概要介绍组成 RpcServer 应用程序的每个文件的内容。
8 |
9 |
10 | RpcServer.vcxproj
11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。
12 |
13 | RpcServer.vcxproj.filters
14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。
15 |
16 | RpcServer.cpp
17 | 这是主应用程序源文件。
18 |
19 | /////////////////////////////////////////////////////////////////////////////
20 | 其他标准文件:
21 |
22 | StdAfx.h, StdAfx.cpp
23 | 这些文件用于生成名为 RpcServer.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。
24 |
25 | /////////////////////////////////////////////////////////////////////////////
26 | 其他注释:
27 |
28 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。
29 |
30 | /////////////////////////////////////////////////////////////////////////////
31 |
--------------------------------------------------------------------------------
/RpcServer/RpcServer/RpcMain.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shinepengwei/miniRPC/a3cb09c3522b114476b9b1c3e2ab2eda52e8a12e/RpcServer/RpcServer/RpcMain.cpp
--------------------------------------------------------------------------------
/RpcServer/RpcServer/RpcServer.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | {21392AA9-FF2A-4923-B67A-9542B6D6B7D4}
15 | Win32Proj
16 | RpcServer
17 |
18 |
19 |
20 | Application
21 | true
22 | v110
23 | Unicode
24 |
25 |
26 | Application
27 | false
28 | v110
29 | true
30 | Unicode
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 | true
44 | E:\test\RpcServer\RpcServer\protobuf-lite;$(IncludePath)
45 |
46 |
47 | false
48 |
49 |
50 |
51 | NotUsing
52 | Level3
53 | Disabled
54 | WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)
55 | true
56 | E:\MyProj\miniRPC\RpcServer\RpcServer\protobuf-lite;C:\boost_1_58_0;%(AdditionalIncludeDirectories)
57 |
58 |
59 | Console
60 | true
61 | C:\boost_1_58_0\stage\lib;%(AdditionalLibraryDirectories)
62 |
63 |
64 |
65 |
66 | Level3
67 | Use
68 | MaxSpeed
69 | true
70 | true
71 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
72 | true
73 |
74 |
75 | Console
76 | true
77 | true
78 | true
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 | Create
186 | Create
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
--------------------------------------------------------------------------------
/RpcServer/RpcServer/RpcServer.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 | {756dbc6f-fdb9-4acd-baef-c9cd17d8c53a}
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | 头文件
26 |
27 |
28 | 头文件
29 |
30 |
31 | proto
32 |
33 |
34 | proto
35 |
36 |
37 | proto
38 |
39 |
40 | proto
41 |
42 |
43 | proto
44 |
45 |
46 | proto
47 |
48 |
49 | proto
50 |
51 |
52 | proto
53 |
54 |
55 | proto
56 |
57 |
58 | proto
59 |
60 |
61 | proto
62 |
63 |
64 | proto
65 |
66 |
67 | proto
68 |
69 |
70 | proto
71 |
72 |
73 | proto
74 |
75 |
76 | proto
77 |
78 |
79 | proto
80 |
81 |
82 | proto
83 |
84 |
85 | proto
86 |
87 |
88 | proto
89 |
90 |
91 | proto
92 |
93 |
94 | proto
95 |
96 |
97 | proto
98 |
99 |
100 | proto
101 |
102 |
103 | proto
104 |
105 |
106 | proto
107 |
108 |
109 | proto
110 |
111 |
112 | proto
113 |
114 |
115 | proto
116 |
117 |
118 | proto
119 |
120 |
121 | proto
122 |
123 |
124 | proto
125 |
126 |
127 | proto
128 |
129 |
130 | proto
131 |
132 |
133 | proto
134 |
135 |
136 | proto
137 |
138 |
139 | proto
140 |
141 |
142 | proto
143 |
144 |
145 | proto
146 |
147 |
148 | proto
149 |
150 |
151 | proto
152 |
153 |
154 | proto
155 |
156 |
157 | proto
158 |
159 |
160 | proto
161 |
162 |
163 | proto
164 |
165 |
166 | proto
167 |
168 |
169 | proto
170 |
171 |
172 | proto
173 |
174 |
175 | proto
176 |
177 |
178 | proto
179 |
180 |
181 | proto
182 |
183 |
184 | proto
185 |
186 |
187 | proto
188 |
189 |
190 | proto
191 |
192 |
193 | proto
194 |
195 |
196 | 头文件
197 |
198 |
199 | proto
200 |
201 |
202 | 头文件
203 |
204 |
205 | 头文件
206 |
207 |
208 |
209 |
210 | 源文件
211 |
212 |
213 | proto
214 |
215 |
216 | proto
217 |
218 |
219 | proto
220 |
221 |
222 | proto
223 |
224 |
225 | proto
226 |
227 |
228 | proto
229 |
230 |
231 | proto
232 |
233 |
234 | proto
235 |
236 |
237 | proto
238 |
239 |
240 | proto
241 |
242 |
243 | proto
244 |
245 |
246 | proto
247 |
248 |
249 | proto
250 |
251 |
252 | proto
253 |
254 |
255 | proto
256 |
257 |
258 | proto
259 |
260 |
261 | proto
262 |
263 |
264 | proto
265 |
266 |
267 | proto
268 |
269 |
270 | proto
271 |
272 |
273 | proto
274 |
275 |
276 | proto
277 |
278 |
279 | proto
280 |
281 |
282 | proto
283 |
284 |
285 | proto
286 |
287 |
288 | proto
289 |
290 |
291 | proto
292 |
293 |
294 | proto
295 |
296 |
297 | proto
298 |
299 |
300 | proto
301 |
302 |
303 | proto
304 |
305 |
306 | proto
307 |
308 |
309 | 源文件
310 |
311 |
312 | proto
313 |
314 |
315 | 源文件
316 |
317 |
318 | 源文件
319 |
320 |
321 | 源文件
322 |
323 |
324 |
325 |
326 | proto
327 |
328 |
329 |
--------------------------------------------------------------------------------
/RpcServer/RpcServer/TcpConnect.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shinepengwei/miniRPC/a3cb09c3522b114476b9b1c3e2ab2eda52e8a12e/RpcServer/RpcServer/TcpConnect.cpp
--------------------------------------------------------------------------------
/RpcServer/RpcServer/TcpConnect.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shinepengwei/miniRPC/a3cb09c3522b114476b9b1c3e2ab2eda52e8a12e/RpcServer/RpcServer/TcpConnect.h
--------------------------------------------------------------------------------
/RpcServer/RpcServer/echo.pb.cc:
--------------------------------------------------------------------------------
1 | // Generated by the protocol buffer compiler. DO NOT EDIT!
2 | // source: echo.proto
3 |
4 | #define INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION
5 | #include "echo.pb.h"
6 |
7 | #include
8 |
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | // @@protoc_insertion_point(includes)
18 |
19 | namespace echo {
20 |
21 | namespace {
22 |
23 | const ::google::protobuf::Descriptor* EchoRequest_descriptor_ = NULL;
24 | const ::google::protobuf::internal::GeneratedMessageReflection*
25 | EchoRequest_reflection_ = NULL;
26 | const ::google::protobuf::Descriptor* EchoResponse_descriptor_ = NULL;
27 | const ::google::protobuf::internal::GeneratedMessageReflection*
28 | EchoResponse_reflection_ = NULL;
29 | const ::google::protobuf::ServiceDescriptor* EchoService_descriptor_ = NULL;
30 |
31 | } // namespace
32 |
33 |
34 | void protobuf_AssignDesc_echo_2eproto() {
35 | protobuf_AddDesc_echo_2eproto();
36 | const ::google::protobuf::FileDescriptor* file =
37 | ::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(
38 | "echo.proto");
39 | GOOGLE_CHECK(file != NULL);
40 | EchoRequest_descriptor_ = file->message_type(0);
41 | static const int EchoRequest_offsets_[1] = {
42 | GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EchoRequest, message_),
43 | };
44 | EchoRequest_reflection_ =
45 | new ::google::protobuf::internal::GeneratedMessageReflection(
46 | EchoRequest_descriptor_,
47 | EchoRequest::default_instance_,
48 | EchoRequest_offsets_,
49 | GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EchoRequest, _has_bits_[0]),
50 | GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EchoRequest, _unknown_fields_),
51 | -1,
52 | ::google::protobuf::DescriptorPool::generated_pool(),
53 | ::google::protobuf::MessageFactory::generated_factory(),
54 | sizeof(EchoRequest));
55 | EchoResponse_descriptor_ = file->message_type(1);
56 | static const int EchoResponse_offsets_[1] = {
57 | GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EchoResponse, response_),
58 | };
59 | EchoResponse_reflection_ =
60 | new ::google::protobuf::internal::GeneratedMessageReflection(
61 | EchoResponse_descriptor_,
62 | EchoResponse::default_instance_,
63 | EchoResponse_offsets_,
64 | GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EchoResponse, _has_bits_[0]),
65 | GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EchoResponse, _unknown_fields_),
66 | -1,
67 | ::google::protobuf::DescriptorPool::generated_pool(),
68 | ::google::protobuf::MessageFactory::generated_factory(),
69 | sizeof(EchoResponse));
70 | EchoService_descriptor_ = file->service(0);
71 | }
72 |
73 | namespace {
74 |
75 | GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);
76 | inline void protobuf_AssignDescriptorsOnce() {
77 | ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,
78 | &protobuf_AssignDesc_echo_2eproto);
79 | }
80 |
81 | void protobuf_RegisterTypes(const ::std::string&) {
82 | protobuf_AssignDescriptorsOnce();
83 | ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
84 | EchoRequest_descriptor_, &EchoRequest::default_instance());
85 | ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
86 | EchoResponse_descriptor_, &EchoResponse::default_instance());
87 | }
88 |
89 | } // namespace
90 |
91 | void protobuf_ShutdownFile_echo_2eproto() {
92 | delete EchoRequest::default_instance_;
93 | delete EchoRequest_reflection_;
94 | delete EchoResponse::default_instance_;
95 | delete EchoResponse_reflection_;
96 | }
97 |
98 | void protobuf_AddDesc_echo_2eproto() {
99 | static bool already_here = false;
100 | if (already_here) return;
101 | already_here = true;
102 | GOOGLE_PROTOBUF_VERIFY_VERSION;
103 |
104 | ::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
105 | "\n\necho.proto\022\004echo\"\036\n\013EchoRequest\022\017\n\007mes"
106 | "sage\030\001 \002(\t\" \n\014EchoResponse\022\020\n\010response\030\001"
107 | " \002(\t2<\n\013EchoService\022-\n\004Echo\022\021.echo.EchoR"
108 | "equest\032\022.echo.EchoResponseB\003\200\001\001", 151);
109 | ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
110 | "echo.proto", &protobuf_RegisterTypes);
111 | EchoRequest::default_instance_ = new EchoRequest();
112 | EchoResponse::default_instance_ = new EchoResponse();
113 | EchoRequest::default_instance_->InitAsDefaultInstance();
114 | EchoResponse::default_instance_->InitAsDefaultInstance();
115 | ::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_echo_2eproto);
116 | }
117 |
118 | // Force AddDescriptors() to be called at static initialization time.
119 | struct StaticDescriptorInitializer_echo_2eproto {
120 | StaticDescriptorInitializer_echo_2eproto() {
121 | protobuf_AddDesc_echo_2eproto();
122 | }
123 | } static_descriptor_initializer_echo_2eproto_;
124 |
125 | // ===================================================================
126 |
127 | #ifndef _MSC_VER
128 | const int EchoRequest::kMessageFieldNumber;
129 | #endif // !_MSC_VER
130 |
131 | EchoRequest::EchoRequest()
132 | : ::google::protobuf::Message() {
133 | SharedCtor();
134 | // @@protoc_insertion_point(constructor:echo.EchoRequest)
135 | }
136 |
137 | void EchoRequest::InitAsDefaultInstance() {
138 | }
139 |
140 | EchoRequest::EchoRequest(const EchoRequest& from)
141 | : ::google::protobuf::Message() {
142 | SharedCtor();
143 | MergeFrom(from);
144 | // @@protoc_insertion_point(copy_constructor:echo.EchoRequest)
145 | }
146 |
147 | void EchoRequest::SharedCtor() {
148 | ::google::protobuf::internal::GetEmptyString();
149 | _cached_size_ = 0;
150 | message_ = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
151 | ::memset(_has_bits_, 0, sizeof(_has_bits_));
152 | }
153 |
154 | EchoRequest::~EchoRequest() {
155 | // @@protoc_insertion_point(destructor:echo.EchoRequest)
156 | SharedDtor();
157 | }
158 |
159 | void EchoRequest::SharedDtor() {
160 | if (message_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
161 | delete message_;
162 | }
163 | if (this != default_instance_) {
164 | }
165 | }
166 |
167 | void EchoRequest::SetCachedSize(int size) const {
168 | GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
169 | _cached_size_ = size;
170 | GOOGLE_SAFE_CONCURRENT_WRITES_END();
171 | }
172 | const ::google::protobuf::Descriptor* EchoRequest::descriptor() {
173 | protobuf_AssignDescriptorsOnce();
174 | return EchoRequest_descriptor_;
175 | }
176 |
177 | const EchoRequest& EchoRequest::default_instance() {
178 | if (default_instance_ == NULL) protobuf_AddDesc_echo_2eproto();
179 | return *default_instance_;
180 | }
181 |
182 | EchoRequest* EchoRequest::default_instance_ = NULL;
183 |
184 | EchoRequest* EchoRequest::New() const {
185 | return new EchoRequest;
186 | }
187 |
188 | void EchoRequest::Clear() {
189 | if (has_message()) {
190 | if (message_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
191 | message_->clear();
192 | }
193 | }
194 | ::memset(_has_bits_, 0, sizeof(_has_bits_));
195 | mutable_unknown_fields()->Clear();
196 | }
197 |
198 | bool EchoRequest::MergePartialFromCodedStream(
199 | ::google::protobuf::io::CodedInputStream* input) {
200 | #define DO_(EXPRESSION) if (!(EXPRESSION)) goto failure
201 | ::google::protobuf::uint32 tag;
202 | // @@protoc_insertion_point(parse_start:echo.EchoRequest)
203 | for (;;) {
204 | ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
205 | tag = p.first;
206 | if (!p.second) goto handle_unusual;
207 | switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
208 | // required string message = 1;
209 | case 1: {
210 | if (tag == 10) {
211 | DO_(::google::protobuf::internal::WireFormatLite::ReadString(
212 | input, this->mutable_message()));
213 | ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
214 | this->message().data(), this->message().length(),
215 | ::google::protobuf::internal::WireFormat::PARSE,
216 | "message");
217 | } else {
218 | goto handle_unusual;
219 | }
220 | if (input->ExpectAtEnd()) goto success;
221 | break;
222 | }
223 |
224 | default: {
225 | handle_unusual:
226 | if (tag == 0 ||
227 | ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
228 | ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
229 | goto success;
230 | }
231 | DO_(::google::protobuf::internal::WireFormat::SkipField(
232 | input, tag, mutable_unknown_fields()));
233 | break;
234 | }
235 | }
236 | }
237 | success:
238 | // @@protoc_insertion_point(parse_success:echo.EchoRequest)
239 | return true;
240 | failure:
241 | // @@protoc_insertion_point(parse_failure:echo.EchoRequest)
242 | return false;
243 | #undef DO_
244 | }
245 |
246 | void EchoRequest::SerializeWithCachedSizes(
247 | ::google::protobuf::io::CodedOutputStream* output) const {
248 | // @@protoc_insertion_point(serialize_start:echo.EchoRequest)
249 | // required string message = 1;
250 | if (has_message()) {
251 | ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
252 | this->message().data(), this->message().length(),
253 | ::google::protobuf::internal::WireFormat::SERIALIZE,
254 | "message");
255 | ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(
256 | 1, this->message(), output);
257 | }
258 |
259 | if (!unknown_fields().empty()) {
260 | ::google::protobuf::internal::WireFormat::SerializeUnknownFields(
261 | unknown_fields(), output);
262 | }
263 | // @@protoc_insertion_point(serialize_end:echo.EchoRequest)
264 | }
265 |
266 | ::google::protobuf::uint8* EchoRequest::SerializeWithCachedSizesToArray(
267 | ::google::protobuf::uint8* target) const {
268 | // @@protoc_insertion_point(serialize_to_array_start:echo.EchoRequest)
269 | // required string message = 1;
270 | if (has_message()) {
271 | ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
272 | this->message().data(), this->message().length(),
273 | ::google::protobuf::internal::WireFormat::SERIALIZE,
274 | "message");
275 | target =
276 | ::google::protobuf::internal::WireFormatLite::WriteStringToArray(
277 | 1, this->message(), target);
278 | }
279 |
280 | if (!unknown_fields().empty()) {
281 | target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
282 | unknown_fields(), target);
283 | }
284 | // @@protoc_insertion_point(serialize_to_array_end:echo.EchoRequest)
285 | return target;
286 | }
287 |
288 | int EchoRequest::ByteSize() const {
289 | int total_size = 0;
290 |
291 | if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
292 | // required string message = 1;
293 | if (has_message()) {
294 | total_size += 1 +
295 | ::google::protobuf::internal::WireFormatLite::StringSize(
296 | this->message());
297 | }
298 |
299 | }
300 | if (!unknown_fields().empty()) {
301 | total_size +=
302 | ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
303 | unknown_fields());
304 | }
305 | GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
306 | _cached_size_ = total_size;
307 | GOOGLE_SAFE_CONCURRENT_WRITES_END();
308 | return total_size;
309 | }
310 |
311 | void EchoRequest::MergeFrom(const ::google::protobuf::Message& from) {
312 | GOOGLE_CHECK_NE(&from, this);
313 | const EchoRequest* source =
314 | ::google::protobuf::internal::dynamic_cast_if_available(
315 | &from);
316 | if (source == NULL) {
317 | ::google::protobuf::internal::ReflectionOps::Merge(from, this);
318 | } else {
319 | MergeFrom(*source);
320 | }
321 | }
322 |
323 | void EchoRequest::MergeFrom(const EchoRequest& from) {
324 | GOOGLE_CHECK_NE(&from, this);
325 | if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
326 | if (from.has_message()) {
327 | set_message(from.message());
328 | }
329 | }
330 | mutable_unknown_fields()->MergeFrom(from.unknown_fields());
331 | }
332 |
333 | void EchoRequest::CopyFrom(const ::google::protobuf::Message& from) {
334 | if (&from == this) return;
335 | Clear();
336 | MergeFrom(from);
337 | }
338 |
339 | void EchoRequest::CopyFrom(const EchoRequest& from) {
340 | if (&from == this) return;
341 | Clear();
342 | MergeFrom(from);
343 | }
344 |
345 | bool EchoRequest::IsInitialized() const {
346 | if ((_has_bits_[0] & 0x00000001) != 0x00000001) return false;
347 |
348 | return true;
349 | }
350 |
351 | void EchoRequest::Swap(EchoRequest* other) {
352 | if (other != this) {
353 | std::swap(message_, other->message_);
354 | std::swap(_has_bits_[0], other->_has_bits_[0]);
355 | _unknown_fields_.Swap(&other->_unknown_fields_);
356 | std::swap(_cached_size_, other->_cached_size_);
357 | }
358 | }
359 |
360 | ::google::protobuf::Metadata EchoRequest::GetMetadata() const {
361 | protobuf_AssignDescriptorsOnce();
362 | ::google::protobuf::Metadata metadata;
363 | metadata.descriptor = EchoRequest_descriptor_;
364 | metadata.reflection = EchoRequest_reflection_;
365 | return metadata;
366 | }
367 |
368 |
369 | // ===================================================================
370 |
371 | #ifndef _MSC_VER
372 | const int EchoResponse::kResponseFieldNumber;
373 | #endif // !_MSC_VER
374 |
375 | EchoResponse::EchoResponse()
376 | : ::google::protobuf::Message() {
377 | SharedCtor();
378 | // @@protoc_insertion_point(constructor:echo.EchoResponse)
379 | }
380 |
381 | void EchoResponse::InitAsDefaultInstance() {
382 | }
383 |
384 | EchoResponse::EchoResponse(const EchoResponse& from)
385 | : ::google::protobuf::Message() {
386 | SharedCtor();
387 | MergeFrom(from);
388 | // @@protoc_insertion_point(copy_constructor:echo.EchoResponse)
389 | }
390 |
391 | void EchoResponse::SharedCtor() {
392 | ::google::protobuf::internal::GetEmptyString();
393 | _cached_size_ = 0;
394 | response_ = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
395 | ::memset(_has_bits_, 0, sizeof(_has_bits_));
396 | }
397 |
398 | EchoResponse::~EchoResponse() {
399 | // @@protoc_insertion_point(destructor:echo.EchoResponse)
400 | SharedDtor();
401 | }
402 |
403 | void EchoResponse::SharedDtor() {
404 | if (response_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
405 | delete response_;
406 | }
407 | if (this != default_instance_) {
408 | }
409 | }
410 |
411 | void EchoResponse::SetCachedSize(int size) const {
412 | GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
413 | _cached_size_ = size;
414 | GOOGLE_SAFE_CONCURRENT_WRITES_END();
415 | }
416 | const ::google::protobuf::Descriptor* EchoResponse::descriptor() {
417 | protobuf_AssignDescriptorsOnce();
418 | return EchoResponse_descriptor_;
419 | }
420 |
421 | const EchoResponse& EchoResponse::default_instance() {
422 | if (default_instance_ == NULL) protobuf_AddDesc_echo_2eproto();
423 | return *default_instance_;
424 | }
425 |
426 | EchoResponse* EchoResponse::default_instance_ = NULL;
427 |
428 | EchoResponse* EchoResponse::New() const {
429 | return new EchoResponse;
430 | }
431 |
432 | void EchoResponse::Clear() {
433 | if (has_response()) {
434 | if (response_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
435 | response_->clear();
436 | }
437 | }
438 | ::memset(_has_bits_, 0, sizeof(_has_bits_));
439 | mutable_unknown_fields()->Clear();
440 | }
441 |
442 | bool EchoResponse::MergePartialFromCodedStream(
443 | ::google::protobuf::io::CodedInputStream* input) {
444 | #define DO_(EXPRESSION) if (!(EXPRESSION)) goto failure
445 | ::google::protobuf::uint32 tag;
446 | // @@protoc_insertion_point(parse_start:echo.EchoResponse)
447 | for (;;) {
448 | ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
449 | tag = p.first;
450 | if (!p.second) goto handle_unusual;
451 | switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
452 | // required string response = 1;
453 | case 1: {
454 | if (tag == 10) {
455 | DO_(::google::protobuf::internal::WireFormatLite::ReadString(
456 | input, this->mutable_response()));
457 | ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
458 | this->response().data(), this->response().length(),
459 | ::google::protobuf::internal::WireFormat::PARSE,
460 | "response");
461 | } else {
462 | goto handle_unusual;
463 | }
464 | if (input->ExpectAtEnd()) goto success;
465 | break;
466 | }
467 |
468 | default: {
469 | handle_unusual:
470 | if (tag == 0 ||
471 | ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
472 | ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
473 | goto success;
474 | }
475 | DO_(::google::protobuf::internal::WireFormat::SkipField(
476 | input, tag, mutable_unknown_fields()));
477 | break;
478 | }
479 | }
480 | }
481 | success:
482 | // @@protoc_insertion_point(parse_success:echo.EchoResponse)
483 | return true;
484 | failure:
485 | // @@protoc_insertion_point(parse_failure:echo.EchoResponse)
486 | return false;
487 | #undef DO_
488 | }
489 |
490 | void EchoResponse::SerializeWithCachedSizes(
491 | ::google::protobuf::io::CodedOutputStream* output) const {
492 | // @@protoc_insertion_point(serialize_start:echo.EchoResponse)
493 | // required string response = 1;
494 | if (has_response()) {
495 | ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
496 | this->response().data(), this->response().length(),
497 | ::google::protobuf::internal::WireFormat::SERIALIZE,
498 | "response");
499 | ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(
500 | 1, this->response(), output);
501 | }
502 |
503 | if (!unknown_fields().empty()) {
504 | ::google::protobuf::internal::WireFormat::SerializeUnknownFields(
505 | unknown_fields(), output);
506 | }
507 | // @@protoc_insertion_point(serialize_end:echo.EchoResponse)
508 | }
509 |
510 | ::google::protobuf::uint8* EchoResponse::SerializeWithCachedSizesToArray(
511 | ::google::protobuf::uint8* target) const {
512 | // @@protoc_insertion_point(serialize_to_array_start:echo.EchoResponse)
513 | // required string response = 1;
514 | if (has_response()) {
515 | ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
516 | this->response().data(), this->response().length(),
517 | ::google::protobuf::internal::WireFormat::SERIALIZE,
518 | "response");
519 | target =
520 | ::google::protobuf::internal::WireFormatLite::WriteStringToArray(
521 | 1, this->response(), target);
522 | }
523 |
524 | if (!unknown_fields().empty()) {
525 | target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
526 | unknown_fields(), target);
527 | }
528 | // @@protoc_insertion_point(serialize_to_array_end:echo.EchoResponse)
529 | return target;
530 | }
531 |
532 | int EchoResponse::ByteSize() const {
533 | int total_size = 0;
534 |
535 | if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
536 | // required string response = 1;
537 | if (has_response()) {
538 | total_size += 1 +
539 | ::google::protobuf::internal::WireFormatLite::StringSize(
540 | this->response());
541 | }
542 |
543 | }
544 | if (!unknown_fields().empty()) {
545 | total_size +=
546 | ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
547 | unknown_fields());
548 | }
549 | GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
550 | _cached_size_ = total_size;
551 | GOOGLE_SAFE_CONCURRENT_WRITES_END();
552 | return total_size;
553 | }
554 |
555 | void EchoResponse::MergeFrom(const ::google::protobuf::Message& from) {
556 | GOOGLE_CHECK_NE(&from, this);
557 | const EchoResponse* source =
558 | ::google::protobuf::internal::dynamic_cast_if_available(
559 | &from);
560 | if (source == NULL) {
561 | ::google::protobuf::internal::ReflectionOps::Merge(from, this);
562 | } else {
563 | MergeFrom(*source);
564 | }
565 | }
566 |
567 | void EchoResponse::MergeFrom(const EchoResponse& from) {
568 | GOOGLE_CHECK_NE(&from, this);
569 | if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
570 | if (from.has_response()) {
571 | set_response(from.response());
572 | }
573 | }
574 | mutable_unknown_fields()->MergeFrom(from.unknown_fields());
575 | }
576 |
577 | void EchoResponse::CopyFrom(const ::google::protobuf::Message& from) {
578 | if (&from == this) return;
579 | Clear();
580 | MergeFrom(from);
581 | }
582 |
583 | void EchoResponse::CopyFrom(const EchoResponse& from) {
584 | if (&from == this) return;
585 | Clear();
586 | MergeFrom(from);
587 | }
588 |
589 | bool EchoResponse::IsInitialized() const {
590 | if ((_has_bits_[0] & 0x00000001) != 0x00000001) return false;
591 |
592 | return true;
593 | }
594 |
595 | void EchoResponse::Swap(EchoResponse* other) {
596 | if (other != this) {
597 | std::swap(response_, other->response_);
598 | std::swap(_has_bits_[0], other->_has_bits_[0]);
599 | _unknown_fields_.Swap(&other->_unknown_fields_);
600 | std::swap(_cached_size_, other->_cached_size_);
601 | }
602 | }
603 |
604 | ::google::protobuf::Metadata EchoResponse::GetMetadata() const {
605 | protobuf_AssignDescriptorsOnce();
606 | ::google::protobuf::Metadata metadata;
607 | metadata.descriptor = EchoResponse_descriptor_;
608 | metadata.reflection = EchoResponse_reflection_;
609 | return metadata;
610 | }
611 |
612 |
613 | // ===================================================================
614 |
615 | EchoService::~EchoService() {}
616 |
617 | const ::google::protobuf::ServiceDescriptor* EchoService::descriptor() {
618 | protobuf_AssignDescriptorsOnce();
619 | return EchoService_descriptor_;
620 | }
621 |
622 | const ::google::protobuf::ServiceDescriptor* EchoService::GetDescriptor() {
623 | protobuf_AssignDescriptorsOnce();
624 | return EchoService_descriptor_;
625 | }
626 |
627 | void EchoService::Echo(::google::protobuf::RpcController* controller,
628 | const ::echo::EchoRequest*,
629 | ::echo::EchoResponse*,
630 | ::google::protobuf::Closure* done) {
631 | controller->SetFailed("Method Echo() not implemented.");
632 | done->Run();
633 | }
634 |
635 | void EchoService::CallMethod(const ::google::protobuf::MethodDescriptor* method,
636 | ::google::protobuf::RpcController* controller,
637 | const ::google::protobuf::Message* request,
638 | ::google::protobuf::Message* response,
639 | ::google::protobuf::Closure* done) {
640 | GOOGLE_DCHECK_EQ(method->service(), EchoService_descriptor_);
641 | switch(method->index()) {
642 | case 0:
643 | Echo(controller,
644 | ::google::protobuf::down_cast(request),
645 | ::google::protobuf::down_cast< ::echo::EchoResponse*>(response),
646 | done);
647 | break;
648 | default:
649 | GOOGLE_LOG(FATAL) << "Bad method index; this should never happen.";
650 | break;
651 | }
652 | }
653 |
654 | const ::google::protobuf::Message& EchoService::GetRequestPrototype(
655 | const ::google::protobuf::MethodDescriptor* method) const {
656 | GOOGLE_DCHECK_EQ(method->service(), descriptor());
657 | switch(method->index()) {
658 | case 0:
659 | return ::echo::EchoRequest::default_instance();
660 | default:
661 | GOOGLE_LOG(FATAL) << "Bad method index; this should never happen.";
662 | return *reinterpret_cast< ::google::protobuf::Message*>(NULL);
663 | }
664 | }
665 |
666 | const ::google::protobuf::Message& EchoService::GetResponsePrototype(
667 | const ::google::protobuf::MethodDescriptor* method) const {
668 | GOOGLE_DCHECK_EQ(method->service(), descriptor());
669 | switch(method->index()) {
670 | case 0:
671 | return ::echo::EchoResponse::default_instance();
672 | default:
673 | GOOGLE_LOG(FATAL) << "Bad method index; this should never happen.";
674 | return *reinterpret_cast< ::google::protobuf::Message*>(NULL);
675 | }
676 | }
677 |
678 | EchoService_Stub::EchoService_Stub(::google::protobuf::RpcChannel* channel)
679 | : channel_(channel), owns_channel_(false) {}
680 | EchoService_Stub::EchoService_Stub(
681 | ::google::protobuf::RpcChannel* channel,
682 | ::google::protobuf::Service::ChannelOwnership ownership)
683 | : channel_(channel),
684 | owns_channel_(ownership == ::google::protobuf::Service::STUB_OWNS_CHANNEL) {}
685 | EchoService_Stub::~EchoService_Stub() {
686 | if (owns_channel_) delete channel_;
687 | }
688 |
689 | void EchoService_Stub::Echo(::google::protobuf::RpcController* controller,
690 | const ::echo::EchoRequest* request,
691 | ::echo::EchoResponse* response,
692 | ::google::protobuf::Closure* done) {
693 | channel_->CallMethod(descriptor()->method(0),
694 | controller, request, response, done);
695 | }
696 |
697 | // @@protoc_insertion_point(namespace_scope)
698 |
699 | } // namespace echo
700 |
701 | // @@protoc_insertion_point(global_scope)
702 |
--------------------------------------------------------------------------------
/RpcServer/RpcServer/echo.pb.h:
--------------------------------------------------------------------------------
1 | // Generated by the protocol buffer compiler. DO NOT EDIT!
2 | // source: echo.proto
3 |
4 | #ifndef PROTOBUF_echo_2eproto__INCLUDED
5 | #define PROTOBUF_echo_2eproto__INCLUDED
6 |
7 | #include
8 |
9 | #include
10 |
11 | #if GOOGLE_PROTOBUF_VERSION < 2006000
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 2006001 < 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 | // @@protoc_insertion_point(includes)
29 |
30 | namespace echo {
31 |
32 | // Internal implementation detail -- do not call these.
33 | void protobuf_AddDesc_echo_2eproto();
34 | void protobuf_AssignDesc_echo_2eproto();
35 | void protobuf_ShutdownFile_echo_2eproto();
36 |
37 | class EchoRequest;
38 | class EchoResponse;
39 |
40 | // ===================================================================
41 |
42 | class EchoRequest : public ::google::protobuf::Message {
43 | public:
44 | EchoRequest();
45 | virtual ~EchoRequest();
46 |
47 | EchoRequest(const EchoRequest& from);
48 |
49 | inline EchoRequest& operator=(const EchoRequest& from) {
50 | CopyFrom(from);
51 | return *this;
52 | }
53 |
54 | inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
55 | return _unknown_fields_;
56 | }
57 |
58 | inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
59 | return &_unknown_fields_;
60 | }
61 |
62 | static const ::google::protobuf::Descriptor* descriptor();
63 | static const EchoRequest& default_instance();
64 |
65 | void Swap(EchoRequest* other);
66 |
67 | // implements Message ----------------------------------------------
68 |
69 | EchoRequest* New() const;
70 | void CopyFrom(const ::google::protobuf::Message& from);
71 | void MergeFrom(const ::google::protobuf::Message& from);
72 | void CopyFrom(const EchoRequest& from);
73 | void MergeFrom(const EchoRequest& from);
74 | void Clear();
75 | bool IsInitialized() const;
76 |
77 | int ByteSize() const;
78 | bool MergePartialFromCodedStream(
79 | ::google::protobuf::io::CodedInputStream* input);
80 | void SerializeWithCachedSizes(
81 | ::google::protobuf::io::CodedOutputStream* output) const;
82 | ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
83 | int GetCachedSize() const { return _cached_size_; }
84 | private:
85 | void SharedCtor();
86 | void SharedDtor();
87 | void SetCachedSize(int size) const;
88 | public:
89 | ::google::protobuf::Metadata GetMetadata() const;
90 |
91 | // nested types ----------------------------------------------------
92 |
93 | // accessors -------------------------------------------------------
94 |
95 | // required string message = 1;
96 | inline bool has_message() const;
97 | inline void clear_message();
98 | static const int kMessageFieldNumber = 1;
99 | inline const ::std::string& message() const;
100 | inline void set_message(const ::std::string& value);
101 | inline void set_message(const char* value);
102 | inline void set_message(const char* value, size_t size);
103 | inline ::std::string* mutable_message();
104 | inline ::std::string* release_message();
105 | inline void set_allocated_message(::std::string* message);
106 |
107 | // @@protoc_insertion_point(class_scope:echo.EchoRequest)
108 | private:
109 | inline void set_has_message();
110 | inline void clear_has_message();
111 |
112 | ::google::protobuf::UnknownFieldSet _unknown_fields_;
113 |
114 | ::google::protobuf::uint32 _has_bits_[1];
115 | mutable int _cached_size_;
116 | ::std::string* message_;
117 | friend void protobuf_AddDesc_echo_2eproto();
118 | friend void protobuf_AssignDesc_echo_2eproto();
119 | friend void protobuf_ShutdownFile_echo_2eproto();
120 |
121 | void InitAsDefaultInstance();
122 | static EchoRequest* default_instance_;
123 | };
124 | // -------------------------------------------------------------------
125 |
126 | class EchoResponse : public ::google::protobuf::Message {
127 | public:
128 | EchoResponse();
129 | virtual ~EchoResponse();
130 |
131 | EchoResponse(const EchoResponse& from);
132 |
133 | inline EchoResponse& operator=(const EchoResponse& from) {
134 | CopyFrom(from);
135 | return *this;
136 | }
137 |
138 | inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
139 | return _unknown_fields_;
140 | }
141 |
142 | inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
143 | return &_unknown_fields_;
144 | }
145 |
146 | static const ::google::protobuf::Descriptor* descriptor();
147 | static const EchoResponse& default_instance();
148 |
149 | void Swap(EchoResponse* other);
150 |
151 | // implements Message ----------------------------------------------
152 |
153 | EchoResponse* New() const;
154 | void CopyFrom(const ::google::protobuf::Message& from);
155 | void MergeFrom(const ::google::protobuf::Message& from);
156 | void CopyFrom(const EchoResponse& from);
157 | void MergeFrom(const EchoResponse& from);
158 | void Clear();
159 | bool IsInitialized() const;
160 |
161 | int ByteSize() const;
162 | bool MergePartialFromCodedStream(
163 | ::google::protobuf::io::CodedInputStream* input);
164 | void SerializeWithCachedSizes(
165 | ::google::protobuf::io::CodedOutputStream* output) const;
166 | ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
167 | int GetCachedSize() const { return _cached_size_; }
168 | private:
169 | void SharedCtor();
170 | void SharedDtor();
171 | void SetCachedSize(int size) const;
172 | public:
173 | ::google::protobuf::Metadata GetMetadata() const;
174 |
175 | // nested types ----------------------------------------------------
176 |
177 | // accessors -------------------------------------------------------
178 |
179 | // required string response = 1;
180 | inline bool has_response() const;
181 | inline void clear_response();
182 | static const int kResponseFieldNumber = 1;
183 | inline const ::std::string& response() const;
184 | inline void set_response(const ::std::string& value);
185 | inline void set_response(const char* value);
186 | inline void set_response(const char* value, size_t size);
187 | inline ::std::string* mutable_response();
188 | inline ::std::string* release_response();
189 | inline void set_allocated_response(::std::string* response);
190 |
191 | // @@protoc_insertion_point(class_scope:echo.EchoResponse)
192 | private:
193 | inline void set_has_response();
194 | inline void clear_has_response();
195 |
196 | ::google::protobuf::UnknownFieldSet _unknown_fields_;
197 |
198 | ::google::protobuf::uint32 _has_bits_[1];
199 | mutable int _cached_size_;
200 | ::std::string* response_;
201 | friend void protobuf_AddDesc_echo_2eproto();
202 | friend void protobuf_AssignDesc_echo_2eproto();
203 | friend void protobuf_ShutdownFile_echo_2eproto();
204 |
205 | void InitAsDefaultInstance();
206 | static EchoResponse* default_instance_;
207 | };
208 | // ===================================================================
209 |
210 | class EchoService_Stub;
211 |
212 | class EchoService : public ::google::protobuf::Service {
213 | protected:
214 | // This class should be treated as an abstract interface.
215 | inline EchoService() {};
216 | public:
217 | virtual ~EchoService();
218 |
219 | typedef EchoService_Stub Stub;
220 |
221 | static const ::google::protobuf::ServiceDescriptor* descriptor();
222 |
223 | virtual void Echo(::google::protobuf::RpcController* controller,
224 | const ::echo::EchoRequest* request,
225 | ::echo::EchoResponse* response,
226 | ::google::protobuf::Closure* done);
227 |
228 | // implements Service ----------------------------------------------
229 |
230 | const ::google::protobuf::ServiceDescriptor* GetDescriptor();
231 | void CallMethod(const ::google::protobuf::MethodDescriptor* method,
232 | ::google::protobuf::RpcController* controller,
233 | const ::google::protobuf::Message* request,
234 | ::google::protobuf::Message* response,
235 | ::google::protobuf::Closure* done);
236 | const ::google::protobuf::Message& GetRequestPrototype(
237 | const ::google::protobuf::MethodDescriptor* method) const;
238 | const ::google::protobuf::Message& GetResponsePrototype(
239 | const ::google::protobuf::MethodDescriptor* method) const;
240 |
241 | private:
242 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EchoService);
243 | };
244 |
245 | class EchoService_Stub : public EchoService {
246 | public:
247 | EchoService_Stub(::google::protobuf::RpcChannel* channel);
248 | EchoService_Stub(::google::protobuf::RpcChannel* channel,
249 | ::google::protobuf::Service::ChannelOwnership ownership);
250 | ~EchoService_Stub();
251 |
252 | inline ::google::protobuf::RpcChannel* channel() { return channel_; }
253 |
254 | // implements EchoService ------------------------------------------
255 |
256 | void Echo(::google::protobuf::RpcController* controller,
257 | const ::echo::EchoRequest* request,
258 | ::echo::EchoResponse* response,
259 | ::google::protobuf::Closure* done);
260 | private:
261 | ::google::protobuf::RpcChannel* channel_;
262 | bool owns_channel_;
263 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EchoService_Stub);
264 | };
265 |
266 |
267 | // ===================================================================
268 |
269 |
270 | // ===================================================================
271 |
272 | // EchoRequest
273 |
274 | // required string message = 1;
275 | inline bool EchoRequest::has_message() const {
276 | return (_has_bits_[0] & 0x00000001u) != 0;
277 | }
278 | inline void EchoRequest::set_has_message() {
279 | _has_bits_[0] |= 0x00000001u;
280 | }
281 | inline void EchoRequest::clear_has_message() {
282 | _has_bits_[0] &= ~0x00000001u;
283 | }
284 | inline void EchoRequest::clear_message() {
285 | if (message_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
286 | message_->clear();
287 | }
288 | clear_has_message();
289 | }
290 | inline const ::std::string& EchoRequest::message() const {
291 | // @@protoc_insertion_point(field_get:echo.EchoRequest.message)
292 | return *message_;
293 | }
294 | inline void EchoRequest::set_message(const ::std::string& value) {
295 | set_has_message();
296 | if (message_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
297 | message_ = new ::std::string;
298 | }
299 | message_->assign(value);
300 | // @@protoc_insertion_point(field_set:echo.EchoRequest.message)
301 | }
302 | inline void EchoRequest::set_message(const char* value) {
303 | set_has_message();
304 | if (message_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
305 | message_ = new ::std::string;
306 | }
307 | message_->assign(value);
308 | // @@protoc_insertion_point(field_set_char:echo.EchoRequest.message)
309 | }
310 | inline void EchoRequest::set_message(const char* value, size_t size) {
311 | set_has_message();
312 | if (message_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
313 | message_ = new ::std::string;
314 | }
315 | message_->assign(reinterpret_cast(value), size);
316 | // @@protoc_insertion_point(field_set_pointer:echo.EchoRequest.message)
317 | }
318 | inline ::std::string* EchoRequest::mutable_message() {
319 | set_has_message();
320 | if (message_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
321 | message_ = new ::std::string;
322 | }
323 | // @@protoc_insertion_point(field_mutable:echo.EchoRequest.message)
324 | return message_;
325 | }
326 | inline ::std::string* EchoRequest::release_message() {
327 | clear_has_message();
328 | if (message_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
329 | return NULL;
330 | } else {
331 | ::std::string* temp = message_;
332 | message_ = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
333 | return temp;
334 | }
335 | }
336 | inline void EchoRequest::set_allocated_message(::std::string* message) {
337 | if (message_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
338 | delete message_;
339 | }
340 | if (message) {
341 | set_has_message();
342 | message_ = message;
343 | } else {
344 | clear_has_message();
345 | message_ = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
346 | }
347 | // @@protoc_insertion_point(field_set_allocated:echo.EchoRequest.message)
348 | }
349 |
350 | // -------------------------------------------------------------------
351 |
352 | // EchoResponse
353 |
354 | // required string response = 1;
355 | inline bool EchoResponse::has_response() const {
356 | return (_has_bits_[0] & 0x00000001u) != 0;
357 | }
358 | inline void EchoResponse::set_has_response() {
359 | _has_bits_[0] |= 0x00000001u;
360 | }
361 | inline void EchoResponse::clear_has_response() {
362 | _has_bits_[0] &= ~0x00000001u;
363 | }
364 | inline void EchoResponse::clear_response() {
365 | if (response_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
366 | response_->clear();
367 | }
368 | clear_has_response();
369 | }
370 | inline const ::std::string& EchoResponse::response() const {
371 | // @@protoc_insertion_point(field_get:echo.EchoResponse.response)
372 | return *response_;
373 | }
374 | inline void EchoResponse::set_response(const ::std::string& value) {
375 | set_has_response();
376 | if (response_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
377 | response_ = new ::std::string;
378 | }
379 | response_->assign(value);
380 | // @@protoc_insertion_point(field_set:echo.EchoResponse.response)
381 | }
382 | inline void EchoResponse::set_response(const char* value) {
383 | set_has_response();
384 | if (response_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
385 | response_ = new ::std::string;
386 | }
387 | response_->assign(value);
388 | // @@protoc_insertion_point(field_set_char:echo.EchoResponse.response)
389 | }
390 | inline void EchoResponse::set_response(const char* value, size_t size) {
391 | set_has_response();
392 | if (response_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
393 | response_ = new ::std::string;
394 | }
395 | response_->assign(reinterpret_cast(value), size);
396 | // @@protoc_insertion_point(field_set_pointer:echo.EchoResponse.response)
397 | }
398 | inline ::std::string* EchoResponse::mutable_response() {
399 | set_has_response();
400 | if (response_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
401 | response_ = new ::std::string;
402 | }
403 | // @@protoc_insertion_point(field_mutable:echo.EchoResponse.response)
404 | return response_;
405 | }
406 | inline ::std::string* EchoResponse::release_response() {
407 | clear_has_response();
408 | if (response_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
409 | return NULL;
410 | } else {
411 | ::std::string* temp = response_;
412 | response_ = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
413 | return temp;
414 | }
415 | }
416 | inline void EchoResponse::set_allocated_response(::std::string* response) {
417 | if (response_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
418 | delete response_;
419 | }
420 | if (response) {
421 | set_has_response();
422 | response_ = response;
423 | } else {
424 | clear_has_response();
425 | response_ = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
426 | }
427 | // @@protoc_insertion_point(field_set_allocated:echo.EchoResponse.response)
428 | }
429 |
430 |
431 | // @@protoc_insertion_point(namespace_scope)
432 |
433 | } // namespace echo
434 |
435 | #ifndef SWIG
436 | namespace google {
437 | namespace protobuf {
438 |
439 |
440 | } // namespace google
441 | } // namespace protobuf
442 | #endif // SWIG
443 |
444 | // @@protoc_insertion_point(global_scope)
445 |
446 | #endif // PROTOBUF_echo_2eproto__INCLUDED
447 |
--------------------------------------------------------------------------------
/RpcServer/RpcServer/stdafx.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shinepengwei/miniRPC/a3cb09c3522b114476b9b1c3e2ab2eda52e8a12e/RpcServer/RpcServer/stdafx.cpp
--------------------------------------------------------------------------------
/RpcServer/RpcServer/stdafx.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shinepengwei/miniRPC/a3cb09c3522b114476b9b1c3e2ab2eda52e8a12e/RpcServer/RpcServer/stdafx.h
--------------------------------------------------------------------------------
/RpcServer/RpcServer/targetver.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shinepengwei/miniRPC/a3cb09c3522b114476b9b1c3e2ab2eda52e8a12e/RpcServer/RpcServer/targetver.h
--------------------------------------------------------------------------------
/echo.proto:
--------------------------------------------------------------------------------
1 | package echo;
2 |
3 | message EchoRequest
4 | {
5 | required string message = 1;
6 | required string serviceName = 2;
7 | required string funName = 3;
8 | };
9 |
10 | message EchoResponse
11 | {
12 | required string response = 1;
13 | };
14 |
15 | service EchoService
16 | {
17 | rpc Echo(EchoRequest) returns (EchoResponse);
18 | };
19 | option cc_generic_services = true;
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | 基于boost.asio网络模块和protobuf通信描述的RPC实现
2 | ==
3 |
4 | ##1 RPC实现框架
5 | 目前实现的RPC只能一端的RPC client调用另一端的RPC service,没有返回值。如果需要返回值,另一端调用这一端的RPC,以参数作为返回值。
6 |
7 | RPC分为client和service,client以protobuf的stub/channel形式实现,rpc server以service实现。
8 |
9 | 网络通信的服务端和客户端,都包括了RPC服务端和RPC客户端,RPC的客户端通过网络通信调用RPC服务端。
10 |
11 | 注意区分**网络通信的服务端/客户端**与**RPC服务端/客户端**,在本文中代表两种含义。
12 |
13 | ##2 模块构成:
14 | TcpConnection:
15 |
16 | - RpcChannel子类,提供CallMethod函数。该函数用于RPC客户端调用stub的service时使用,包括function和参数信息的序列化,以及调用数据传输。
17 | - 封装socket,以及和socket有关的数据传输函数。包括发送数据、接收数据回调。
18 | - 此外,他持有RPCServerService,RPC客户端接收数据后调用RPCServerService的rpc函数。
19 |
20 | TcpServer:
21 |
22 | - 网络通信服务端,处理网络连接请求。
23 | - 持有TcpConnection的vector,将所有的网络连接存放在里面。
24 | - 每次有网络连接请求时,已连接的网络连接存起来,创建一个新的网络连接等待请求。
25 |
26 |
27 | TcpClient:
28 |
29 | - 只有一个网络连接。
30 |
31 | Service分为两种:用于服务端的RPCServerService(包括EchoImplService和EchoBackImplService),以及用于客户端的echo::EchoService::Stub。
32 |
33 | RPCServerService:
34 |
35 | - EchoService的子类,用于实现echo的rpc被调用函数。
36 | - 存放在TcpConnection中,当接收到数据时,TcpConnection调用此service。`rpcServices[0]->CallMethod(rpcServices[0]->GetDescriptor()->method(fid),NULL,&request,NULL,NULL);`
37 |
38 | ## RPC调用过程
39 |
40 | ####服务端初始化过程:
41 |
42 | 1 使用io_service创建TcpServer:
43 | - 创建TcpConnection等待连接
44 | - 添加RPC serverService当接收到数据时,调用rpc函数。(RPC服务端)
45 |
46 | 2 创建一个新线程,io_service.run()
47 |
48 | ####客户端初始化过程:
49 |
50 | 1 使用io_service创建TcpClient:
51 | - 创建一个TcpConnection连接服务器。
52 | - 添加RPC serverService当接收到数据时,调用rpc函数。(RPC服务端)
53 |
54 | 2 创建一个新线程,io_service.run()
55 |
56 |
57 | ####客户端发起RPC调用步骤:
58 | 1.使用TcpClient的TcpConnection作为RpcChannel创建一个echo::EchoService::Stub。
59 | 2.设置request信息,调用Stub的Echo函数。`service->Echo(NULL, &request, NULL, NULL);`
60 | 3.调用RpcChannel(TcpConnection)的Callmethod函数。此函数中对函数信息和参数信息序列化,并发到服务端。
61 | 4.服务端接收到数据,TcpConnection持有一个RPCServerService,并调用RPCServerService的CallMethod函数。
62 | 5.RpcServerService的Echo函数被调用(protoBuf中callMethod根据function信息调用Echo函数)。
63 | 6.EchoBackImplService的Echo函数调用echo::EchoService::Stub的Echo函数,开始Web客户端的RPC调用。
64 |
65 | ####服务端发起RPC调用步骤:
66 | TcpServer有一个Echo函数,这个函数基于所有的TcpConnection创建一个EchoService::Stub,然后调用它的Echo函数。
67 |
68 |
69 | ##3 基于protobuf实现RPC流程
70 |
71 | 参考:
72 | http://blog.csdn.net/kevinlynx/article/details/39379957
73 |
74 | 其中有个问题:如何标示service和method。文中的方法太复杂。
75 |
76 | 我的方法是,使用serviceId和functionId,将其放在要传输的字符串首部,到了服务端进行解析即可。
77 |
78 | 目前,我只是用了functionId。放在网络传输字符串的第一个字节。
79 |
80 |
81 | ProtoBuf RPC总结:
82 |
83 | RPC客户端调用RPC服务端,重要的是实现一个RpcChannel以及它的一个CallMethod函数,此函数用于序列化函数和函数参数信息。
84 |
85 | RPC服务端重要的是实现EchoService的子类,也就是RPC被调用函数的具体实现。
86 |
87 | 实现了这两个东西,就是把序列化信息传来传去的过程。
88 |
89 | ##4 Boost.Asio相关问题
90 | http://www.codingart.info//rpc-boost-asio.html
91 |
92 |
93 |
--------------------------------------------------------------------------------