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;
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;
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)
Definition sbuffer.hpp:24
sbuffer(sbuffer &&other)
Definition sbuffer.hpp:47
sbuffer(const sbuffer &)=delete
const char * data() const
Definition sbuffer.hpp:83
char * data()
Definition sbuffer.hpp:78
sbuffer & operator=(const sbuffer &)=delete
char * release()
Definition sbuffer.hpp:93
sbuffer(size_t initsz=MSGPACK_SBUFFER_INIT_SIZE)
Definition sbuffer.hpp:26
~sbuffer()
Definition sbuffer.hpp:38
void clear()
Definition sbuffer.hpp:102
sbuffer & operator=(sbuffer &&other)
Definition sbuffer.hpp:54
size_t size() const
Definition sbuffer.hpp:88
void write(const char *buf, size_t len)
Definition sbuffer.hpp:69
Definition adaptor_base.hpp:15
#define MSGPACK_NULLPTR
Definition cpp_config_decl.hpp:35
#define MSGPACK_SBUFFER_INIT_SIZE
Definition sbuffer_decl.hpp:16
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition versioning.hpp:58