11 #include "errors/fatal.h" 12 #include "string/format.h" 25 assert((
size > 0) &&
"Message size should be greater than zero!");
26 _buffer = (uint8_t*)nn_allocmsg(
size,
type);
27 if (_buffer ==
nullptr)
28 throwex CppCommon::SystemException(
"Failed to allocate a memory buffer of {} bytes for the nanomsg message! Nanomsg error: {}"_format(
size, nn_strerror(nn_errno())));
34 std::memcpy(_buffer, data,
size);
47 catch (CppCommon::SystemException& ex)
49 fatality(CppCommon::SystemException(ex.string()));
56 *
this = std::move(temp);
62 if (_buffer !=
nullptr)
64 int result = nn_freemsg(_buffer);
66 throwex CppCommon::SystemException(
"Failed to free memory of the nanomsg message!");
73 assert((
size > 0) &&
"Message size should be greater than zero!");
74 if (_buffer !=
nullptr)
76 _buffer = (uint8_t*)nn_reallocmsg(_buffer,
size);
77 if (_buffer ==
nullptr)
78 throwex CppCommon::SystemException(
"Failed to reallocate a memory buffer of {} bytes for the nanomsg message! Nanomsg error: {}"_format(
size, nn_strerror(nn_errno())));
82 _buffer = (uint8_t*)nn_allocmsg(
size, _type);
83 if (_buffer ==
nullptr)
84 throwex CppCommon::SystemException(
"Failed to allocate a memory buffer of {} bytes for the nanomsg message! Nanomsg error: {}"_format(
size, nn_strerror(nn_errno())));
void Reallocate(size_t size)
Reallocate the message size.
int type() const noexcept
Get the message type.
size_t size() const noexcept
Get the message size.
Nanomsg message definition.
C++ Server project definitions.
Message()
Create an empty message.
void Clear()
Clear the message buffer.
Message & operator=(const Message &message)