#include <rpcService.hpp>
Public Member Functions | |
| RpcService (std::string_view name) | |
| template<anch::codec::ProtobufMessage Req, anch::codec::ProtobufMessage Res, typename F> | |
| RpcService & | unary (std::string_view method, F &&handler) |
| std::string | call (std::string_view method, std::string_view request, anch::rest::RpcFormat format, anch::rest::RpcContext &context) const |
| bool | has (std::string_view method) const |
| std::vector< std::string > | getMethods () const |
| const std::string & | getName () const noexcept |
| std::size_t | getMaxMessageSize () const noexcept |
| void | setMaxMessageSize (std::size_t size) noexcept |
RPC service: unary methods of a Protocol Buffers service, served by installRpc (Connect and gRPC-Web in Api , HTTP/1.1) and by GrpcServer (gRPC, HTTP/2) with the same handlers.
Handler errors: RpcError is sent with its code and message, HttpException with the code of its status ( 400 is INVALID_ARGUMENT , 404 is NOT_FOUND , ...), other exceptions are INTERNAL without message.
Methods have to be declared before calls; calls can then be made from several threads.
|
explicit |
RpcService constructor
| name | the service full name ( package.Service ) |
| std::invalid_argument | when name is empty or contains / |
| std::string anch::rest::RpcService::call | ( | std::string_view | method, |
| std::string_view | request, | ||
| anch::rest::RpcFormat | format, | ||
| anch::rest::RpcContext & | context ) const |
Call method
| method | the method name |
| request | the request message |
| format | the messages encoding |
| context | the call context |
| RpcError | on error ( UNIMPLEMENTED for unknown method, INVALID_ARGUMENT for invalid request, RESOURCE_EXHAUSTED for request larger than maximum message size, handler errors) |
|
noexcept |
Get maximum request message size (default: 4 MiB, as gRPC)
| std::vector< std::string > anch::rest::RpcService::getMethods | ( | ) | const |
Get methods names
|
noexcept |
Get service full name
| bool anch::rest::RpcService::has | ( | std::string_view | method | ) | const |
Check if service has a method
| method | the method name |
true when method is declared
|
noexcept |
Set maximum request message size
| size | the size in bytes |
| RpcService & anch::rest::RpcService::unary | ( | std::string_view | method, |
| F && | handler ) |
Declare unary method
| Req | the request message type |
| Res | the response message type |
| method | the method name ( GetPet ) |
| handler | the handler: Res(const Req&, RpcContext&) or Res(const Req&) |
this | std::invalid_argument | when method name is invalid or already declared |