zmqpp  4.1.2
C++ bindings for 0mq (libzmq)
Public Types | Public Member Functions | Public Attributes | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
zmqpp::message Class Reference

a zmq message with optional multipart support More...

#include <message.hpp>

Collaboration diagram for zmqpp::message:
Collaboration graph
[legend]

Public Types

typedef std::function< void(void *)> release_function
 callback to release user allocated data. More...
 

Public Member Functions

 message ()
 
 ~message ()
 
template<typename T , typename ... Args>
 message (T const &part, Args &&...args)
 
size_t parts () const
 
size_t size (size_t const part) const
 
std::string get (size_t const part) const
 
void get (int8_t &integer, size_t const part) const
 
void get (int16_t &integer, size_t const part) const
 
void get (int32_t &integer, size_t const part) const
 
void get (int64_t &integer, size_t const part) const
 
void get (signal &sig, size_t const part) const
 
void get (uint8_t &unsigned_integer, size_t const part) const
 
void get (uint16_t &unsigned_integer, size_t const part) const
 
void get (uint32_t &unsigned_integer, size_t const part) const
 
void get (uint64_t &unsigned_integer, size_t const part) const
 
void get (float &floating_point, size_t const part) const
 
void get (double &double_precision, size_t const part) const
 
void get (bool &boolean, size_t const part) const
 
void get (std::string &string, size_t const part) const
 
template<typename Type >
Type get (size_t const part) const
 
template<int part = 0, typename T , typename ... Args>
void extract (T &nextpart, Args &...args) const
 
template<int part = 0, typename T >
void extract (T &nextpart) const
 
template<typename Type >
void get (Type *&value, size_t const part) const
 
template<typename Type >
void get (Type **value, size_t const part) const
 
void move (void *part, size_t const size, release_function const &release)
 
template<typename Object >
void move (Object *part)
 
template<typename Type , typename ... Args>
void add (Type const &part, Args &&...args)
 
template<typename Type >
void add (Type const part)
 
template<typename Type >
void add_raw (Type *part, size_t const data_size)
 
template<typename Type >
 ZMQPP_DEPRECATED ("Use add_nocopy() or add_nocopy_const() instead.") void add_const(Type *part
 
template<typename Type >
void add_nocopy (Type *part, size_t const data_size, zmq_free_fn *ffn=nullptr, void *hint=nullptr)
 Add a no-copy frame. More...
 
template<typename Type >
void add_nocopy_const (const Type *part, size_t const data_size, zmq_free_fn *ffn=nullptr, void *hint=nullptr)
 Add a no-copy frame where pointed-to data are const. More...
 
void reset_read_cursor ()
 
template<typename Type >
messageoperator>> (Type &value)
 
messageoperator<< (int8_t const integer)
 
messageoperator<< (int16_t const integer)
 
messageoperator<< (int32_t const integer)
 
messageoperator<< (int64_t const integer)
 
messageoperator<< (signal const sig)
 
messageoperator<< (uint8_t const unsigned_integer)
 
messageoperator<< (uint16_t const unsigned_integer)
 
messageoperator<< (uint32_t const unsigned_integer)
 
messageoperator<< (uint64_t const unsigned_integer)
 
messageoperator<< (float const floating_point)
 
messageoperator<< (double const double_precision)
 
messageoperator<< (bool const boolean)
 
messageoperator<< (char const *c_string)
 
messageoperator<< (std::string const &string)
 
void push_front (void const *part, size_t const size)
 
void push_front (int8_t const integer)
 
void push_front (int16_t const integer)
 
void push_front (int32_t const integer)
 
void push_front (int64_t const integer)
 
void push_front (signal const sig)
 
void push_front (uint8_t const unsigned_integer)
 
void push_front (uint16_t const unsigned_integer)
 
void push_front (uint32_t const unsigned_integer)
 
void push_front (uint64_t const unsigned_integer)
 
void push_front (float const floating_point)
 
void push_front (double const double_precision)
 
void push_front (bool const boolean)
 
void push_front (char const *c_string)
 
void push_front (std::string const &string)
 
void pop_front ()
 
void push_back (void const *part, size_t const data_size)
 
template<typename Type >
void push_back (Type const part)
 
void pop_back ()
 
void remove (size_t const part)
 
 message (message &&source) NOEXCEPT
 
messageoperator= (message &&source) NOEXCEPT
 
message copy () const
 
void copy (message const &source)
 
void sent (size_t const part)
 
void const * raw_data (size_t const part=0) const
 
zmq_msg_t & raw_msg (size_t const part=0)
 
zmq_msg_t & raw_new_msg ()
 
zmq_msg_t & raw_new_msg (size_t const reserve_data_size)
 
bool is_signal () const
 Check if the message is a signal. More...
 
size_t read_cursor () const NOEXCEPT
 Gets the read cursor. More...
 
size_t remaining () const NOEXCEPT
 Gets the remaining number of parts in the message. More...
 
size_t next () NOEXCEPT
 Moves the read cursor to the next element. More...
 

Public Attributes

size_t const data_size
 

Private Types

typedef std::vector< frameparts_type
 

Private Member Functions

 message (message const &) NOEXCEPT ZMQPP_EXPLICITLY_DELETED
 
messageoperator= (message const &) NOEXCEPT ZMQPP_EXPLICITLY_DELETED
 

Static Private Member Functions

static void release_callback (void *data, void *hint)
 
template<typename Object >
static void deleter_callback (void *data)
 

Private Attributes

parts_type _parts
 
size_t _read_cursor
 

Detailed Description

a zmq message with optional multipart support

A zmq message is made up of one or more parts which are sent together to the target endpoints. zmq guarantees either the whole message or none of the message will be delivered.

Member Typedef Documentation

◆ parts_type

typedef std::vector<frame> zmqpp::message::parts_type
private

◆ release_function

typedef std::function<void (void*)> zmqpp::message::release_function

callback to release user allocated data.

The release function will be called on any void* moved part. It must be thread safe to the extent that the callback may occur on one of the context threads.

The function called will be passed a single variable which is the pointer to the memory allocated.

Constructor & Destructor Documentation

◆ message() [1/4]

zmqpp::message::message ( )

◆ ~message()

zmqpp::message::~message ( )

◆ message() [2/4]

template<typename T , typename ... Args>
zmqpp::message::message ( T const &  part,
Args &&...  args 
)
inline

◆ message() [3/4]

zmqpp::message::message ( message &&  source)

◆ message() [4/4]

zmqpp::message::message ( message const &  )
private

Member Function Documentation

◆ add() [1/2]

template<typename Type , typename ... Args>
void zmqpp::message::add ( Type const &  part,
Args &&...  args 
)
inline

◆ add() [2/2]

template<typename Type >
void zmqpp::message::add ( Type const  part)
inline

◆ add_nocopy()

template<typename Type >
void zmqpp::message::add_nocopy ( Type *  part,
size_t const  data_size,
zmq_free_fn *  ffn = nullptr,
void *  hint = nullptr 
)
inline

Add a no-copy frame.

This means that neither zmqpp nor libzmq will make a copy of the data. The pointed-to data must remain valid for the lifetime of the underlying zmq_msg_t. Note that you cannot always know about this lifetime, so be careful.

Parameters
partThe pointed-to data that will be send in the message.
data_sizeThe number of byte pointed-to by "part".
ffnThe free function called by libzmq when it doesn't need your buffer anymore. It defaults to nullptr, meaning your data will not be freed.
hintA hint to help your free function do its job.
Note
This is similar to what move() does. While move() provide a safe (wrt to type) deleter (at the cost of 1 memory allocation) add_nocopy let you pass the low-level callback that libzmq will invoke.
The free function must be thread-safe as it can be invoke from any libzmq's context threads.
See also
add_nocopy_const
move

◆ add_nocopy_const()

template<typename Type >
void zmqpp::message::add_nocopy_const ( const Type *  part,
size_t const  data_size,
zmq_free_fn *  ffn = nullptr,
void *  hint = nullptr 
)
inline

Add a no-copy frame where pointed-to data are const.

This means that neither zmqpp nor libzmq will make a copy of the data. The pointed-to data must remain valid for the lifetime of the underlying zmq_msg_t. Note that you cannot always know about this lifetime, so be careful.

Warning
About constness: The library will cast away constness from your pointer. However, it promises that both libzmq and zmqpp will not alter the pointed-to data. YOU must however be careful: zmqpp or libzmq will happily return a non-const pointer to your data. It's your responsibility to not modify it.
Parameters
partThe pointed-to data that will be send in the message.
data_sizeThe number of byte pointed-to by "part".
ffnThe free function called by libzmq when it doesn't need your buffer anymore. It defaults to nullptr, meaning your data will not be freed.
hintA hint to help your free function do its job.
Note
The free function must be thread-safe as it can be invoke from any libzmq's context threads.
See also
add_nocopy

◆ add_raw()

template<typename Type >
void zmqpp::message::add_raw ( Type *  part,
size_t const  data_size 
)
inline

◆ copy() [1/2]

message zmqpp::message::copy ( ) const

◆ copy() [2/2]

void zmqpp::message::copy ( message const &  source)

◆ deleter_callback()

template<typename Object >
static void zmqpp::message::deleter_callback ( void *  data)
inlinestaticprivate

◆ extract() [1/2]

template<int part = 0, typename T , typename ... Args>
void zmqpp::message::extract ( T &  nextpart,
Args &...  args 
) const
inline

◆ extract() [2/2]

template<int part = 0, typename T >
void zmqpp::message::extract ( T &  nextpart) const
inline

◆ get() [1/17]

std::string zmqpp::message::get ( size_t const  part) const

◆ get() [2/17]

void zmqpp::message::get ( int8_t &  integer,
size_t const  part 
) const

◆ get() [3/17]

void zmqpp::message::get ( int16_t &  integer,
size_t const  part 
) const

◆ get() [4/17]

void zmqpp::message::get ( int32_t &  integer,
size_t const  part 
) const

◆ get() [5/17]

void zmqpp::message::get ( int64_t &  integer,
size_t const  part 
) const

◆ get() [6/17]

void zmqpp::message::get ( signal sig,
size_t const  part 
) const

◆ get() [7/17]

void zmqpp::message::get ( uint8_t &  unsigned_integer,
size_t const  part 
) const

◆ get() [8/17]

void zmqpp::message::get ( uint16_t &  unsigned_integer,
size_t const  part 
) const

◆ get() [9/17]

void zmqpp::message::get ( uint32_t &  unsigned_integer,
size_t const  part 
) const

◆ get() [10/17]

void zmqpp::message::get ( uint64_t &  unsigned_integer,
size_t const  part 
) const

◆ get() [11/17]

void zmqpp::message::get ( float &  floating_point,
size_t const  part 
) const

◆ get() [12/17]

void zmqpp::message::get ( double &  double_precision,
size_t const  part 
) const

◆ get() [13/17]

void zmqpp::message::get ( bool &  boolean,
size_t const  part 
) const

◆ get() [14/17]

void zmqpp::message::get ( std::string &  string,
size_t const  part 
) const

◆ get() [15/17]

template<typename Type >
Type zmqpp::message::get ( size_t const  part) const
inline

◆ get() [16/17]

template<typename Type >
void zmqpp::message::get ( Type *&  value,
size_t const  part 
) const
inline

◆ get() [17/17]

template<typename Type >
void zmqpp::message::get ( Type **  value,
size_t const  part 
) const
inline

◆ is_signal()

bool zmqpp::message::is_signal ( ) const

Check if the message is a signal.

If the message has 1 part, has the correct size and if the 7 first bytes match the signal header we consider the message a signal.

Returns
true if the message is a signal, false otherwise

◆ move() [1/2]

void zmqpp::message::move ( void *  part,
size_t const  size,
release_function const &  release 
)

◆ move() [2/2]

template<typename Object >
void zmqpp::message::move ( Object *  part)
inline

◆ next()

size_t zmqpp::message::next ( )
inline

Moves the read cursor to the next element.

Returns
the new read_cursor

◆ operator<<() [1/14]

message & zmqpp::message::operator<< ( int8_t const  integer)

◆ operator<<() [2/14]

message & zmqpp::message::operator<< ( int16_t const  integer)

◆ operator<<() [3/14]

message & zmqpp::message::operator<< ( int32_t const  integer)

◆ operator<<() [4/14]

message & zmqpp::message::operator<< ( int64_t const  integer)

◆ operator<<() [5/14]

message & zmqpp::message::operator<< ( signal const  sig)

◆ operator<<() [6/14]

message & zmqpp::message::operator<< ( uint8_t const  unsigned_integer)

◆ operator<<() [7/14]

message & zmqpp::message::operator<< ( uint16_t const  unsigned_integer)

◆ operator<<() [8/14]

message & zmqpp::message::operator<< ( uint32_t const  unsigned_integer)

◆ operator<<() [9/14]

message & zmqpp::message::operator<< ( uint64_t const  unsigned_integer)

◆ operator<<() [10/14]

message & zmqpp::message::operator<< ( float const  floating_point)

◆ operator<<() [11/14]

message & zmqpp::message::operator<< ( double const  double_precision)

◆ operator<<() [12/14]

message & zmqpp::message::operator<< ( bool const  boolean)

◆ operator<<() [13/14]

message & zmqpp::message::operator<< ( char const *  c_string)

◆ operator<<() [14/14]

message & zmqpp::message::operator<< ( std::string const &  string)

◆ operator=() [1/2]

message & zmqpp::message::operator= ( message &&  source)

◆ operator=() [2/2]

message& zmqpp::message::operator= ( message const &  )
private

◆ operator>>()

template<typename Type >
message& zmqpp::message::operator>> ( Type &  value)
inline

◆ parts()

size_t zmqpp::message::parts ( ) const

◆ pop_back()

void zmqpp::message::pop_back ( )

◆ pop_front()

void zmqpp::message::pop_front ( )

◆ push_back() [1/2]

void zmqpp::message::push_back ( void const *  part,
size_t const  data_size 
)
inline

◆ push_back() [2/2]

template<typename Type >
void zmqpp::message::push_back ( Type const  part)
inline

◆ push_front() [1/15]

void zmqpp::message::push_front ( void const *  part,
size_t const  size 
)

◆ push_front() [2/15]

void zmqpp::message::push_front ( int8_t const  integer)

◆ push_front() [3/15]

void zmqpp::message::push_front ( int16_t const  integer)

◆ push_front() [4/15]

void zmqpp::message::push_front ( int32_t const  integer)

◆ push_front() [5/15]

void zmqpp::message::push_front ( int64_t const  integer)

◆ push_front() [6/15]

void zmqpp::message::push_front ( signal const  sig)

◆ push_front() [7/15]

void zmqpp::message::push_front ( uint8_t const  unsigned_integer)

◆ push_front() [8/15]

void zmqpp::message::push_front ( uint16_t const  unsigned_integer)

◆ push_front() [9/15]

void zmqpp::message::push_front ( uint32_t const  unsigned_integer)

◆ push_front() [10/15]

void zmqpp::message::push_front ( uint64_t const  unsigned_integer)

◆ push_front() [11/15]

void zmqpp::message::push_front ( float const  floating_point)

◆ push_front() [12/15]

void zmqpp::message::push_front ( double const  double_precision)

◆ push_front() [13/15]

void zmqpp::message::push_front ( bool const  boolean)

◆ push_front() [14/15]

void zmqpp::message::push_front ( char const *  c_string)

◆ push_front() [15/15]

void zmqpp::message::push_front ( std::string const &  string)

◆ raw_data()

void const * zmqpp::message::raw_data ( size_t const  part = 0) const

◆ raw_msg()

zmq_msg_t & zmqpp::message::raw_msg ( size_t const  part = 0)

◆ raw_new_msg() [1/2]

zmq_msg_t & zmqpp::message::raw_new_msg ( )

◆ raw_new_msg() [2/2]

zmq_msg_t & zmqpp::message::raw_new_msg ( size_t const  reserve_data_size)

◆ read_cursor()

size_t zmqpp::message::read_cursor ( ) const
inline

Gets the read cursor.

For using get_raw() with stream-style reading.

◆ release_callback()

void zmqpp::message::release_callback ( void *  data,
void *  hint 
)
staticprivate

◆ remaining()

size_t zmqpp::message::remaining ( ) const
inline

Gets the remaining number of parts in the message.

◆ remove()

void zmqpp::message::remove ( size_t const  part)

◆ reset_read_cursor()

void zmqpp::message::reset_read_cursor ( )

◆ sent()

void zmqpp::message::sent ( size_t const  part)

◆ size()

size_t zmqpp::message::size ( size_t const  part) const

◆ ZMQPP_DEPRECATED()

template<typename Type >
zmqpp::message::ZMQPP_DEPRECATED ( "Use add_nocopy() or add_nocopy_const() instead."  )

Member Data Documentation

◆ _parts

parts_type zmqpp::message::_parts
private

◆ _read_cursor

size_t zmqpp::message::_read_cursor
private

◆ data_size

size_t const zmqpp::message::data_size
Initial value:
{
_parts.push_back( frame( part, data_size, nullptr, nullptr ) )

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