#ifndef __BUFFER_H__ #define __BUFFER_H__ #include #include namespace Nng { namespace Asio { class Socket; }; class Buffer { friend class Socket; friend class Asio::Socket; public: Buffer() = default; Buffer(std::size_t size); Buffer(const Buffer &rhs); ~Buffer(); Buffer(Buffer &&rhs) noexcept { m_buffer = rhs.m_buffer; m_size = rhs.m_size; rhs.m_buffer = nullptr; rhs.m_size = 0; } Buffer &operator=(const Buffer &rhs); Buffer &operator=(Buffer &&rhs) noexcept; explicit operator bool() const noexcept { return (m_buffer != nullptr) && (m_size > 0); } template T *data() const noexcept { return reinterpret_cast(m_buffer); } std::string_view data() const noexcept; std::size_t size() const noexcept { return m_size; } protected: template Buffer(T *data, std::size_t size) : m_buffer(data), m_size(size) { } void *release(); private: void *m_buffer = nullptr; std::size_t m_size = 0; }; } // namespace Nng #endif // __BUFFER_H__