CppServer  1.0.0.0
C++ Server Library
Public Member Functions | Friends | List of all members
CppServer::Nanomsg::Message Class Reference

Nanomsg message. More...

#include <message.h>

Public Member Functions

 Message ()
 Create an empty message. More...
 
 Message (size_t size, int type=0)
 Allocate memory for a new message. More...
 
 Message (const void *data, size_t size, int type=0)
 Create a new message based on the given buffer. More...
 
 Message (const Message &message)
 
 Message (Message &&) noexcept=default
 
 ~Message ()
 
Messageoperator= (const Message &message)
 
Messageoperator= (Message &&) noexcept=default
 
 operator bool () const
 Check if the message is valid. More...
 
uint8_t * buffer () noexcept
 Get the message buffer. More...
 
const uint8_t * buffer () const noexcept
 Get the constant message buffer. More...
 
size_t size () const noexcept
 Get the message size. More...
 
int type () const noexcept
 Get the message type. More...
 
void Clear ()
 Clear the message buffer. More...
 
void Reallocate (size_t size)
 Reallocate the message size. More...
 
std::string string () const
 Convert the current message to a string. More...
 
void swap (Message &message) noexcept
 Swap two instances. More...
 

Friends

class Socket
 
std::ostream & operator<< (std::ostream &os, const Message &instance)
 Output instance into the given output stream. More...
 
void swap (Message &message1, Message &message2) noexcept
 

Detailed Description

Nanomsg message.

Nanomsg message wraps message buffer and used to send or receive data using Nanomsg library API.

Thread-safe.

Examples:
nanomsg_bus.cpp, nanomsg_pair_client.cpp, nanomsg_pair_server.cpp, nanomsg_push_server.cpp, nanomsg_request_client.cpp, nanomsg_request_server.cpp, nanomsg_subscribe_client.cpp, nanomsg_survey_client.cpp, and nanomsg_survey_server.cpp.

Definition at line 29 of file message.h.

Constructor & Destructor Documentation

◆ Message() [1/5]

CppServer::Nanomsg::Message::Message ( )

Create an empty message.

Definition at line 19 of file message.cpp.

◆ Message() [2/5]

CppServer::Nanomsg::Message::Message ( size_t  size,
int  type = 0 
)
explicit

Allocate memory for a new message.

Allocate type parameter specifies type of allocation mechanism to use. Zero is the default one, however, individual transport mechanisms may define their own allocation mechanisms, such as allocating in shared memory or allocating a memory block pinned down to a physical memory address. Such allocation, when used with the transport that defines them, should be more efficient than the default allocation mechanism.

Parameters
size- Message size
type- Allocate type (default is 0)

Definition at line 23 of file message.cpp.

◆ Message() [3/5]

CppServer::Nanomsg::Message::Message ( const void *  data,
size_t  size,
int  type = 0 
)
explicit

Create a new message based on the given buffer.

Parameters
data- Message data
size- Message size
type- Allocate type (default is 0)

Definition at line 32 of file message.cpp.

◆ Message() [4/5]

CppServer::Nanomsg::Message::Message ( const Message message)

Definition at line 37 of file message.cpp.

◆ Message() [5/5]

CppServer::Nanomsg::Message::Message ( Message &&  )
defaultnoexcept

◆ ~Message()

CppServer::Nanomsg::Message::~Message ( )

Definition at line 41 of file message.cpp.

Member Function Documentation

◆ buffer() [1/2]

uint8_t* CppServer::Nanomsg::Message::buffer ( )
inlinenoexcept

Get the message buffer.

Definition at line 67 of file message.h.

◆ buffer() [2/2]

const uint8_t* CppServer::Nanomsg::Message::buffer ( ) const
inlinenoexcept

Get the constant message buffer.

Definition at line 69 of file message.h.

◆ Clear()

void CppServer::Nanomsg::Message::Clear ( )

Clear the message buffer.

Definition at line 60 of file message.cpp.

◆ operator bool()

CppServer::Nanomsg::Message::operator bool ( ) const
inlineexplicit

Check if the message is valid.

Definition at line 64 of file message.h.

◆ operator=() [1/2]

Message & CppServer::Nanomsg::Message::operator= ( const Message message)

Definition at line 53 of file message.cpp.

◆ operator=() [2/2]

Message& CppServer::Nanomsg::Message::operator= ( Message &&  )
defaultnoexcept

◆ Reallocate()

void CppServer::Nanomsg::Message::Reallocate ( size_t  size)

Reallocate the message size.

Parameters
size- New message size

Definition at line 71 of file message.cpp.

◆ size()

size_t CppServer::Nanomsg::Message::size ( ) const
inlinenoexcept

Get the message size.

Definition at line 71 of file message.h.

◆ string()

std::string CppServer::Nanomsg::Message::string ( ) const
inline

Convert the current message to a string.

Examples:
nanomsg_pair_server.cpp, nanomsg_request_server.cpp, and nanomsg_survey_client.cpp.

Definition at line 85 of file message.h.

◆ swap()

void CppServer::Nanomsg::Message::swap ( Message message)
inlinenoexcept

Swap two instances.

Definition at line 12 of file message.inl.

◆ type()

int CppServer::Nanomsg::Message::type ( ) const
inlinenoexcept

Get the message type.

Definition at line 73 of file message.h.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const Message instance 
)
friend

Output instance into the given output stream.

Definition at line 88 of file message.h.

◆ Socket

friend class Socket
friend

Definition at line 31 of file message.h.

◆ swap

void swap ( Message message1,
Message message2 
)
friend

Definition at line 20 of file message.inl.


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