10#ifndef MSGPACK_V1_SBUFFER_HPP
11#define MSGPACK_V1_SBUFFER_HPP
32 m_data = (
char*)::malloc(initsz);
34 throw std::bad_alloc();
44#if !defined(MSGPACK_USE_CPP03)
49 m_size(other.m_size), m_data(other.m_data), m_alloc(other.m_alloc)
51 other.m_size = other.m_alloc = 0;
59 m_size = other.m_size;
60 m_alloc = other.m_alloc;
61 m_data = other.m_data;
63 other.m_size = other.m_alloc = 0;
70 void write(
const char* buf,
size_t len)
76 if(m_alloc - m_size < len) {
79 std::memcpy(m_data + m_size, buf, len);
113 void expand_buffer(
size_t len)
115 size_t nsize = (m_alloc > 0) ?
118 while(nsize < m_size + len) {
119 size_t tmp_nsize = nsize * 2;
120 if (tmp_nsize <= nsize) {
121 nsize = m_size + len;
127 void* tmp = ::realloc(m_data, nsize);
129 throw std::bad_alloc();
132 m_data =
static_cast<char*
>(tmp);
136#if defined(MSGPACK_USE_CPP03)
#define MSGPACK_ASSERT
Definition: assert.hpp:22
Definition: sbuffer.hpp:25
sbuffer(sbuffer &&other)
Definition: sbuffer.hpp:48
sbuffer(const sbuffer &)=delete
const char * data() const
Definition: sbuffer.hpp:88
char * data()
Definition: sbuffer.hpp:83
sbuffer & operator=(const sbuffer &)=delete
char * release()
Definition: sbuffer.hpp:98
sbuffer(size_t initsz=MSGPACK_SBUFFER_INIT_SIZE)
Definition: sbuffer.hpp:27
~sbuffer()
Definition: sbuffer.hpp:39
void clear()
Definition: sbuffer.hpp:107
sbuffer & operator=(sbuffer &&other)
Definition: sbuffer.hpp:55
size_t size() const
Definition: sbuffer.hpp:93
void write(const char *buf, size_t len)
Definition: sbuffer.hpp:70
Definition: adaptor_base.hpp:15
#define MSGPACK_NULLPTR
Definition: cpp_config_decl.hpp:85
#define MSGPACK_SBUFFER_INIT_SIZE
Definition: sbuffer_decl.hpp:16
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:66