10#ifndef MSGPACK_V1_SBUFFER_HPP
11#define MSGPACK_V1_SBUFFER_HPP
33 m_data = (
char*)::malloc(initsz);
35 throw std::bad_alloc();
45#if !defined(MSGPACK_USE_CPP03)
50 m_size(other.m_size), m_data(other.m_data), m_alloc(other.m_alloc)
52 other.m_size = other.m_alloc = 0;
60 m_size = other.m_size;
61 m_alloc = other.m_alloc;
62 m_data = other.m_data;
64 other.m_size = other.m_alloc = 0;
71 void write(
const char* buf,
size_t len)
77 if(m_alloc - m_size < len) {
80 std::memcpy(m_data + m_size, buf, len);
114 void expand_buffer(
size_t len)
116 size_t nsize = (m_alloc > 0) ?
119 while(nsize < m_size + len) {
120 size_t tmp_nsize = nsize * 2;
121 if (tmp_nsize <= nsize) {
122 nsize = m_size + len;
128 void* tmp = ::realloc(m_data, nsize);
130 throw std::bad_alloc();
133 m_data =
static_cast<char*
>(tmp);
137#if defined(MSGPACK_USE_CPP03)
#define MSGPACK_ASSERT
Definition assert.hpp:22
Definition sbuffer.hpp:26
sbuffer(sbuffer &&other)
Definition sbuffer.hpp:49
sbuffer(const sbuffer &)=delete
const char * data() const
Definition sbuffer.hpp:89
char * data()
Definition sbuffer.hpp:84
sbuffer & operator=(const sbuffer &)=delete
char * release()
Definition sbuffer.hpp:99
sbuffer(size_t initsz=MSGPACK_SBUFFER_INIT_SIZE)
Definition sbuffer.hpp:28
~sbuffer()
Definition sbuffer.hpp:40
void clear()
Definition sbuffer.hpp:108
sbuffer & operator=(sbuffer &&other)
Definition sbuffer.hpp:56
size_t size() const
Definition sbuffer.hpp:94
void write(const char *buf, size_t len)
Definition sbuffer.hpp:71
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