10 #ifndef MSGPACK_SBUFFER_HPP 11 #define MSGPACK_SBUFFER_HPP 17 #ifndef MSGPACK_SBUFFER_INIT_SIZE 18 #define MSGPACK_SBUFFER_INIT_SIZE 8192 34 m_data = (
char*)::malloc(initsz);
36 throw std::bad_alloc();
46 #if !defined(MSGPACK_USE_CPP03) 51 m_size(other.m_size), m_data(other.m_data), m_alloc(other.m_alloc)
53 other.m_size = other.m_alloc = 0;
54 other.m_data =
nullptr;
61 m_size = other.m_size;
62 m_alloc = other.m_alloc;
63 m_data = other.m_data;
65 other.m_size = other.m_alloc = 0;
66 other.m_data =
nullptr;
70 #endif // !defined(MSGPACK_USE_CPP03) 72 void write(
const char* buf,
size_t len)
74 if(m_alloc - m_size < len) {
77 std::memcpy(m_data + m_size, buf, len);
111 void expand_buffer(
size_t len)
113 size_t nsize = (m_alloc > 0) ?
116 while(nsize < m_size + len) {
117 size_t tmp_nsize = nsize * 2;
118 if (tmp_nsize <= nsize) {
119 nsize = m_size + len;
125 void* tmp = ::realloc(m_data, nsize);
127 throw std::bad_alloc();
130 m_data =
static_cast<char*
>(tmp);
134 #if defined(MSGPACK_USE_CPP03) 138 #endif // defined(MSGPACK_USE_CPP03) #define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:58
sbuffer & operator=(sbuffer &&other)
Definition: sbuffer.hpp:57
#define MSGPACK_SBUFFER_INIT_SIZE
Definition: sbuffer.hpp:18
Definition: sbuffer.hpp:27
~sbuffer()
Definition: sbuffer.hpp:41
Definition: adaptor_base.hpp:15
char * data()
Definition: sbuffer.hpp:81
sbuffer & operator=(const sbuffer &)=delete
void write(const char *buf, size_t len)
Definition: sbuffer.hpp:72
const char * data() const
Definition: sbuffer.hpp:86
size_t size() const
Definition: sbuffer.hpp:91
char * release()
Definition: sbuffer.hpp:96
sbuffer(size_t initsz=MSGPACK_SBUFFER_INIT_SIZE)
Definition: sbuffer.hpp:29
void clear()
Definition: sbuffer.hpp:105
sbuffer(sbuffer &&other)
Definition: sbuffer.hpp:50