Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
kcenon::network::protocols::grpc::grpc_client Class Reference

gRPC client for making RPC calls More...

#include <client.h>

Collaboration diagram for kcenon::network::protocols::grpc::grpc_client:
Collaboration graph

Classes

class  bidi_stream
 Bidirectional streaming RPC handle. More...
 
class  client_stream_writer
 Writer for client streaming RPC. More...
 
class  impl
 
class  server_stream_reader
 Reader for server streaming RPC. More...
 

Public Member Functions

 grpc_client (const std::string &target, const grpc_channel_config &config={})
 Construct gRPC client.
 
 ~grpc_client ()
 Destructor.
 
 grpc_client (const grpc_client &)=delete
 
grpc_clientoperator= (const grpc_client &)=delete
 
 grpc_client (grpc_client &&) noexcept
 
grpc_clientoperator= (grpc_client &&) noexcept
 
auto connect () -> VoidResult
 Connect to the server.
 
auto disconnect () -> void
 Disconnect from the server.
 
auto is_connected () const -> bool
 Check if connected.
 
auto wait_for_connected (std::chrono::milliseconds timeout) -> bool
 Wait for connection to be ready.
 
auto target () const -> const std::string &
 Get the target address.
 
auto call_raw (const std::string &method, const std::vector< uint8_t > &request, const call_options &options={}) -> Result< grpc_message >
 Make a unary RPC call.
 
auto call_raw_async (const std::string &method, const std::vector< uint8_t > &request, std::function< void(Result< grpc_message >)> callback, const call_options &options={}) -> void
 Make an async unary RPC call.
 
auto server_stream_raw (const std::string &method, const std::vector< uint8_t > &request, const call_options &options={}) -> Result< std::unique_ptr< server_stream_reader > >
 Start a server streaming RPC call.
 
auto client_stream_raw (const std::string &method, const call_options &options={}) -> Result< std::unique_ptr< client_stream_writer > >
 Start a client streaming RPC call.
 
auto bidi_stream_raw (const std::string &method, const call_options &options={}) -> Result< std::unique_ptr< bidi_stream > >
 Start a bidirectional streaming RPC call.
 

Private Attributes

std::unique_ptr< implimpl_
 

Detailed Description

gRPC client for making RPC calls

This class provides a client interface for making gRPC calls over HTTP/2 transport. It supports unary and streaming RPC calls.

Note
This is a prototype implementation. For production use, consider wrapping the official gRPC library.

Definition at line 114 of file client.h.

Constructor & Destructor Documentation

◆ grpc_client() [1/3]

kcenon::network::protocols::grpc::grpc_client::grpc_client ( const std::string & target,
const grpc_channel_config & config = {} )
explicit

Construct gRPC client.

Parameters
targetTarget address (e.g., "localhost:50051")
configChannel configuration

Definition at line 1629 of file client.cpp.

1631 : impl_(std::make_unique<impl>(target, config))
1632{
1633}
auto target() const -> const std::string &
Get the target address.
Definition client.cpp:1660

References config.

◆ ~grpc_client()

kcenon::network::protocols::grpc::grpc_client::~grpc_client ( )
default

Destructor.

◆ grpc_client() [2/3]

kcenon::network::protocols::grpc::grpc_client::grpc_client ( const grpc_client & )
delete

◆ grpc_client() [3/3]

kcenon::network::protocols::grpc::grpc_client::grpc_client ( grpc_client && )
defaultnoexcept

Member Function Documentation

◆ bidi_stream_raw()

auto kcenon::network::protocols::grpc::grpc_client::bidi_stream_raw ( const std::string & method,
const call_options & options = {} ) -> Result<std::unique_ptr<bidi_stream>>

Start a bidirectional streaming RPC call.

Parameters
methodFull method name
optionsCall options
Returns
Bidirectional stream handle or error

Definition at line 1695 of file client.cpp.

1698{
1699 return impl_->bidi_stream_raw(method, options);
1700}
auto bidi_stream_raw(const std::string &method, const call_options &options) -> Result< std::unique_ptr< grpc_client::bidi_stream > >
Definition client.cpp:1533

◆ call_raw()

auto kcenon::network::protocols::grpc::grpc_client::call_raw ( const std::string & method,
const std::vector< uint8_t > & request,
const call_options & options = {} ) -> Result<grpc_message>

Make a unary RPC call.

Parameters
methodFull method name (e.g., "/package.Service/Method")
requestSerialized request message
optionsCall options
Returns
Result containing serialized response or error status

Example:

auto result = client.call_raw("/helloworld.Greeter/SayHello",
serialize(request));
if (result.is_ok()) {
auto response = deserialize<HelloReply>(result.value().data);
}

Definition at line 1665 of file client.cpp.

1668{
1669 return impl_->call_raw(method, request, options);
1670}
auto call_raw(const std::string &method, const std::vector< uint8_t > &request, const call_options &options) -> Result< grpc_message >
Definition client.cpp:1146

◆ call_raw_async()

auto kcenon::network::protocols::grpc::grpc_client::call_raw_async ( const std::string & method,
const std::vector< uint8_t > & request,
std::function< void(Result< grpc_message >)> callback,
const call_options & options = {} ) -> void

Make an async unary RPC call.

Parameters
methodFull method name
requestSerialized request message
callbackCallback with result
optionsCall options

Definition at line 1672 of file client.cpp.

1676{
1677 impl_->call_raw_async(method, request, std::move(callback), options);
1678}
auto call_raw_async(const std::string &method, const std::vector< uint8_t > &request, std::function< void(Result< grpc_message >)> callback, const call_options &options) -> void
Definition client.cpp:1336

◆ client_stream_raw()

auto kcenon::network::protocols::grpc::grpc_client::client_stream_raw ( const std::string & method,
const call_options & options = {} ) -> Result<std::unique_ptr<client_stream_writer>>

Start a client streaming RPC call.

Parameters
methodFull method name
optionsCall options
Returns
Stream writer or error

Definition at line 1688 of file client.cpp.

1691{
1692 return impl_->client_stream_raw(method, options);
1693}
auto client_stream_raw(const std::string &method, const call_options &options) -> Result< std::unique_ptr< grpc_client::client_stream_writer > >
Definition client.cpp:1446

◆ connect()

auto kcenon::network::protocols::grpc::grpc_client::connect ( ) -> VoidResult

Connect to the server.

Returns
Success or error

Definition at line 1640 of file client.cpp.

1641{
1642 return impl_->connect();
1643}

◆ disconnect()

auto kcenon::network::protocols::grpc::grpc_client::disconnect ( ) -> void

Disconnect from the server.

Definition at line 1645 of file client.cpp.

◆ is_connected()

auto kcenon::network::protocols::grpc::grpc_client::is_connected ( ) const -> bool

Check if connected.

Returns
True if connected

Definition at line 1650 of file client.cpp.

1651{
1652 return impl_->is_connected();
1653}

References impl_, and kcenon::network::protocols::grpc::grpc_client::impl::is_connected().

Here is the call graph for this function:

◆ operator=() [1/2]

grpc_client & kcenon::network::protocols::grpc::grpc_client::operator= ( const grpc_client & )
delete

◆ operator=() [2/2]

grpc_client & kcenon::network::protocols::grpc::grpc_client::operator= ( grpc_client && )
defaultnoexcept

◆ server_stream_raw()

auto kcenon::network::protocols::grpc::grpc_client::server_stream_raw ( const std::string & method,
const std::vector< uint8_t > & request,
const call_options & options = {} ) -> Result<std::unique_ptr<server_stream_reader>>

Start a server streaming RPC call.

Parameters
methodFull method name
requestSerialized request message
optionsCall options
Returns
Stream reader or error

Definition at line 1680 of file client.cpp.

1684{
1685 return impl_->server_stream_raw(method, request, options);
1686}
auto server_stream_raw(const std::string &method, const std::vector< uint8_t > &request, const call_options &options) -> Result< std::unique_ptr< grpc_client::server_stream_reader > >
Definition client.cpp:1352

◆ target()

auto kcenon::network::protocols::grpc::grpc_client::target ( ) const -> const std::string&

Get the target address.

Returns
Target address string

Definition at line 1660 of file client.cpp.

1661{
1662 return impl_->target();
1663}
auto target() const -> const std::string &
Definition client.cpp:1141

References impl_, and kcenon::network::protocols::grpc::grpc_client::impl::target().

Here is the call graph for this function:

◆ wait_for_connected()

auto kcenon::network::protocols::grpc::grpc_client::wait_for_connected ( std::chrono::milliseconds timeout) -> bool

Wait for connection to be ready.

Parameters
timeoutMaximum time to wait
Returns
True if connected within timeout

Definition at line 1655 of file client.cpp.

1656{
1657 return impl_->wait_for_connected(timeout);
1658}
auto wait_for_connected(std::chrono::milliseconds timeout) -> bool
Definition client.cpp:1125

Member Data Documentation

◆ impl_

std::unique_ptr<impl> kcenon::network::protocols::grpc::grpc_client::impl_
private

Definition at line 326 of file client.h.

Referenced by is_connected(), and target().


The documentation for this class was generated from the following files: