-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support arena rpc pb message factory
- Loading branch information
1 parent
48996cf
commit 4fad729
Showing
6 changed files
with
222 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1027,20 +1027,31 @@ Server默认使用`DefaultRpcPBMessageFactory`。它是一个简单的工厂类 | |
class RpcPBMessages { | ||
public: | ||
virtual ~RpcPBMessages() = default; | ||
// Get protobuf request message. | ||
virtual google::protobuf::Message* Request() = 0; | ||
// Get protobuf response message. | ||
virtual google::protobuf::Message* Response() = 0; | ||
}; | ||
// Factory to manage `RpcPBMessages'. | ||
class RpcPBMessageFactory { | ||
public: | ||
virtual ~RpcPBMessageFactory() = default; | ||
// Get `RpcPBMessages' according to `service' and `method'. | ||
// Common practice to create protobuf message: | ||
// service.GetRequestPrototype(&method).New() -> request; | ||
// service.GetRequestPrototype(&method).New() -> response. | ||
virtual RpcPBMessages* Get(const ::google::protobuf::Service& service, | ||
const ::google::protobuf::MethodDescriptor& method) = 0; | ||
virtual void Return(RpcPBMessages* protobuf_message) = 0; | ||
// Return `RpcPBMessages' to factory. | ||
virtual void Return(RpcPBMessages* messages) = 0; | ||
}; | ||
``` | ||
|
||
### Protobuf arena | ||
|
||
|
||
# FAQ | ||
|
||
### Q: Fail to write into fd=1865 [email protected]:54742@8230: Got EOF是什么意思 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1008,6 +1008,41 @@ public: | |
... | ||
``` | ||
## RPC Protobuf message factory | ||
`DefaultRpcPBMessageFactory' is used at server-side by default. It is a simple factory class that uses `new' to create request/response messages and `delete' to destroy request/response messages. | ||
Users can implement `RpcPBMessages' (encapsulation of request/response message) and `RpcPBMessageFactory' (factory class) to customize the creation and destruction mechanism of protobuf message, and then set to `ServerOptions.rpc_pb_message_factory'. | ||
The interface is as follows: | ||
```c++ | ||
// Inherit this class to customize rpc protobuf messages, | ||
// include request and response. | ||
class RpcPBMessages { | ||
public: | ||
virtual ~RpcPBMessages() = default; | ||
// Get protobuf request message. | ||
virtual google::protobuf::Message* Request() = 0; | ||
// Get protobuf response message. | ||
virtual google::protobuf::Message* Response() = 0; | ||
}; | ||
// Factory to manage `RpcPBMessages'. | ||
class RpcPBMessageFactory { | ||
public: | ||
virtual ~RpcPBMessageFactory() = default; | ||
// Get `RpcPBMessages' according to `service' and `method'. | ||
// Common practice to create protobuf message: | ||
// service.GetRequestPrototype(&method).New() -> request; | ||
// service.GetRequestPrototype(&method).New() -> response. | ||
virtual RpcPBMessages* Get(const ::google::protobuf::Service& service, | ||
const ::google::protobuf::MethodDescriptor& method) = 0; | ||
// Return `RpcPBMessages' to factory. | ||
virtual void Return(RpcPBMessages* protobuf_message) = 0; | ||
}; | ||
``` | ||
|
||
# FAQ | ||
|
||
### Q: Fail to write into fd=1865 [email protected]:54742@8230: Got EOF | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
syntax="proto3"; | ||
|
||
package v3; | ||
|
||
option cc_generic_services = true; | ||
// https://github.com/protocolbuffers/protobuf/releases/tag/v3.14.0 | ||
// Since Protocol Buffers v3.14.0, Arenas are now unconditionally enabled. | ||
// cc_enable_arenas no longer has any effect. | ||
option cc_enable_arenas = true; | ||
|
||
message EchoRequest { | ||
string message = 1; | ||
}; | ||
|
||
message EchoResponse { | ||
string message = 1; | ||
}; | ||
|
||
service EchoService { | ||
rpc Echo(EchoRequest) returns (EchoResponse); | ||
}; |