10 #ifndef MSGPACK_V1_SBUFFER_HPP 11 #define MSGPACK_V1_SBUFFER_HPP 31 m_data = (
char*)::malloc(initsz);
33 throw std::bad_alloc();
43 #if !defined(MSGPACK_USE_CPP03) 48 m_size(other.m_size), m_data(other.m_data), m_alloc(other.m_alloc)
50 other.m_size = other.m_alloc = 0;
51 other.m_data =
nullptr;
58 m_size = other.m_size;
59 m_alloc = other.m_alloc;
60 m_data = other.m_data;
62 other.m_size = other.m_alloc = 0;
63 other.m_data =
nullptr;
67 #endif // !defined(MSGPACK_USE_CPP03) 69 void write(
const char* buf,
size_t len)
71 if(m_alloc - m_size < len) {
74 std::memcpy(m_data + m_size, buf, len);
108 void expand_buffer(
size_t len)
110 size_t nsize = (m_alloc > 0) ?
113 while(nsize < m_size + len) {
114 size_t tmp_nsize = nsize * 2;
115 if (tmp_nsize <= nsize) {
116 nsize = m_size + len;
122 void* tmp = ::realloc(m_data, nsize);
124 throw std::bad_alloc();
127 m_data =
static_cast<char*
>(tmp);
131 #if defined(MSGPACK_USE_CPP03) 135 #endif // defined(MSGPACK_USE_CPP03) 149 #endif // MSGPACK_V1_SBUFFER_HPP sbuffer & operator=(sbuffer &&other)
Definition: sbuffer.hpp:54
#define MSGPACK_SBUFFER_INIT_SIZE
Definition: sbuffer_decl.hpp:16
Definition: sbuffer.hpp:24
~sbuffer()
Definition: sbuffer.hpp:38
Definition: adaptor_base.hpp:15
char * data()
Definition: sbuffer.hpp:78
sbuffer & operator=(const sbuffer &)=delete
void write(const char *buf, size_t len)
Definition: sbuffer.hpp:69
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:58
char * release()
Definition: sbuffer.hpp:93
sbuffer(size_t initsz=MSGPACK_SBUFFER_INIT_SIZE)
Definition: sbuffer.hpp:26
void clear()
Definition: sbuffer.hpp:102
const char * data() const
Definition: sbuffer.hpp:83
size_t size() const
Definition: sbuffer.hpp:88
sbuffer(sbuffer &&other)
Definition: sbuffer.hpp:47