C++ Actor Framework 0.19
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
caf::net::message_flow_bridge< Trait > Class Template Reference

Translates between a message-oriented transport and data flows. More...

#include <message_flow_bridge.hpp>

Inheritance diagram for caf::net::message_flow_bridge< Trait >:
caf::net::lp::upper_layer caf::net::generic_upper_layer

Public Types

using input_type = typename Trait::input_type
 The input type for the application.
 
using output_type = typename Trait::output_type
 The output type for of application.
 
using pull_resource_t = async::consumer_resource< output_type >
 The resource type we pull from. We consume the output of the application.
 
using pull_buffer_t = async::spsc_buffer< output_type >
 The buffer type from the pull_resource_t.
 
using push_resource_t = async::producer_resource< input_type >
 Type for the producer adapter. We produce the input of the application.
 
using push_buffer_t = async::spsc_buffer< input_type >
 The buffer type from the push_resource_t.
 

Public Member Functions

 message_flow_bridge (pull_resource_t in_res, push_resource_t out_res, Trait trait)
 
 message_flow_bridge (Trait trait)
 
error start (net::socket_manager *mgr, lp::lower_layer *down)
 
bool write (const input_type &item)
 
void prepare_send () override
 Gives the upper layer an opportunity to add additional data to the output buffer.
 
bool done_sending () override
 Queries whether all pending data has been sent.
 
void abort (const error &reason) override
 Called by the lower layer for cleaning up any state in case of an error or when disposed.
 
ptrdiff_t consume (byte_span buf)
 Consumes bytes from the lower layer.
 
- Public Member Functions inherited from caf::net::lp::upper_layer
virtual error start (lower_layer *down)=0
 Initializes the upper layer.
 
virtual ptrdiff_t consume (byte_span payload)=0
 Consumes bytes from the lower layer.
 
virtual void prepare_send ()=0
 Gives the upper layer an opportunity to add additional data to the output buffer.
 
virtual bool done_sending ()=0
 Queries whether all pending data has been sent.
 
virtual void abort (const error &reason)=0
 Called by the lower layer for cleaning up any state in case of an error or when disposed.
 

Detailed Description

template<class Trait>
class caf::net::message_flow_bridge< Trait >

Translates between a message-oriented transport and data flows.

The Trait provides a customization point that converts between native and wire format.

class my_trait {
using input_type = ...;
using output_type = ...;
bool convert(const_byte_span bytes, input_type& value);
bool convert(const output_type& value, byte_buffer& bytes);
};
typename Trait::output_type output_type
The output type for of application.
Definition message_flow_bridge.hpp:42
typename Trait::input_type input_type
The input type for the application.
Definition message_flow_bridge.hpp:39
std::vector< std::byte > byte_buffer
A buffer for storing binary data.
Definition byte_buffer.hpp:13

Member Function Documentation

◆ abort()

template<class Trait >
void caf::net::message_flow_bridge< Trait >::abort ( const error reason)
overridevirtual

Called by the lower layer for cleaning up any state in case of an error or when disposed.

Implements caf::net::generic_upper_layer.

◆ consume()

template<class Trait >
ptrdiff_t caf::net::message_flow_bridge< Trait >::consume ( byte_span  payload)
virtual

Consumes bytes from the lower layer.

Parameters
payloadPayload of the received message.
Returns
The number of consumed bytes or a negative value to signal an error.
Note
Discarded data is lost permanently.

Implements caf::net::lp::upper_layer.

◆ done_sending()

template<class Trait >
bool caf::net::message_flow_bridge< Trait >::done_sending ( )
overridevirtual

Queries whether all pending data has been sent.

The lower calls this function to decide whether it has to wait for write events on the socket.

Implements caf::net::generic_upper_layer.

◆ prepare_send()

template<class Trait >
void caf::net::message_flow_bridge< Trait >::prepare_send ( )
overridevirtual

Gives the upper layer an opportunity to add additional data to the output buffer.

Implements caf::net::generic_upper_layer.


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