61 lines
1.2 KiB
C++
61 lines
1.2 KiB
C++
#include "Message.h"
|
|
|
|
namespace Nng {
|
|
|
|
Message::Message(std::size_t size) {
|
|
nng_msg_alloc(&m_message, size);
|
|
}
|
|
|
|
Message::Message(const Message &rhs) {
|
|
nng_msg_dup(&m_message, rhs.m_message);
|
|
}
|
|
|
|
Message &Message::operator=(const Message &rhs) {
|
|
if (this != &rhs) {
|
|
if (m_message != nullptr) nng_msg_free(m_message);
|
|
nng_msg_dup(&m_message, rhs.m_message);
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
Message &Message::operator=(Message &&rhs) noexcept {
|
|
if (this != &rhs) {
|
|
if (m_message != nullptr) nng_msg_free(m_message);
|
|
m_message = rhs.m_message;
|
|
rhs.m_message = nullptr;
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
Message::~Message() {
|
|
if (m_message != nullptr) nng_msg_free(m_message);
|
|
}
|
|
|
|
void Message::realloc(std::size_t size) const {
|
|
nng_msg_realloc(m_message, size);
|
|
}
|
|
|
|
Message::Header Message::header() const {
|
|
return Header(m_message);
|
|
}
|
|
|
|
Message::Body Message::body() const {
|
|
return Body(m_message);
|
|
}
|
|
|
|
Message::Header::Header(nng_msg *message) : m_message(message) {
|
|
}
|
|
|
|
std::size_t Message::Body::capacity() const {
|
|
return nng_msg_capacity(m_message);
|
|
}
|
|
|
|
void Message::Body::clear() const noexcept {
|
|
nng_msg_clear(m_message);
|
|
}
|
|
|
|
Message::Body::Body(nng_msg *message) : m_message(message) {
|
|
}
|
|
|
|
} // namespace Nng
|