int msgpack_vrefbuffer_append_copy(msgpack_vrefbuffer* vbuf, const char* buf, unsigned int len) { msgpack_vrefbuffer_chunk* chunk; char* m; msgpack_vrefbuffer_inner_buffer* const ib = &vbuf->inner_buffer; if(ib->free < len) { size_t sz = vbuf->chunk_size; if(sz < len) { sz = len; } chunk = (msgpack_vrefbuffer_chunk*)malloc( sizeof(msgpack_vrefbuffer_chunk) + sz); if(chunk == NULL) { return -1; } chunk->next = ib->head; ib->head = chunk; ib->free = sz; ib->ptr = ((char*)chunk) + sizeof(msgpack_vrefbuffer_chunk); } m = ib->ptr; memcpy(m, buf, len); ib->free -= len; ib->ptr += len; if(vbuf->tail != vbuf->array && m == (const char*)((vbuf->tail-1)->iov_base) + (vbuf->tail-1)->iov_len) { (vbuf->tail-1)->iov_len += len; return 0; } else { return msgpack_vrefbuffer_append_ref(vbuf, m, len); } }
void append_ref(const char* buf, size_t len) { if(msgpack_vrefbuffer_append_ref(this, buf, len) < 0) { throw std::bad_alloc(); } }