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_client & operator= (const grpc_client &)=delete
 
 grpc_client (grpc_client &&) noexcept
 
grpc_client & operator= (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::shared_ptr< impl > impl_
 

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 1648 of file client.cpp.

1650 : impl_(std::make_shared<impl>(target, config))
1651{
1652}
auto target() const -> const std::string &
Get the target address.
Definition client.cpp:1679

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 1714 of file client.cpp.

1717{
1718 return impl_->bidi_stream_raw(method, options);
1719}

◆ 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 1684 of file client.cpp.

1687{
1688 return impl_->call_raw(method, request, options);
1689}

◆ 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 1691 of file client.cpp.

1695{
1696 impl_->call_raw_async(method, request, std::move(callback), options);
1697}

◆ 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 1707 of file client.cpp.

1710{
1711 return impl_->client_stream_raw(method, options);
1712}

◆ connect()

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

Connect to the server.

Returns
Success or error

Definition at line 1659 of file client.cpp.

1660{
1661 return impl_->connect();
1662}

◆ disconnect()

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

Disconnect from the server.

Definition at line 1664 of file client.cpp.

1665{
1666 impl_->disconnect();
1667}

◆ is_connected()

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

Check if connected.

Returns
True if connected

Definition at line 1669 of file client.cpp.

1670{
1671 return impl_->is_connected();
1672}

References impl_.

◆ 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 1699 of file client.cpp.

1703{
1704 return impl_->server_stream_raw(method, request, options);
1705}

◆ target()

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

Get the target address.

Returns
Target address string

Definition at line 1679 of file client.cpp.

1680{
1681 return impl_->target();
1682}

References impl_.

◆ 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 1674 of file client.cpp.

1675{
1676 return impl_->wait_for_connected(timeout);
1677}

Member Data Documentation

◆ impl_

std::shared_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: