mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-05-19 04:47:37 +02:00
Merge branch 'cpp_master' of https://github.com/ygj6/msgpack-c into cpp_master
This commit is contained in:
commit
0168468ac8
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace msgpack {
|
namespace msgpack {
|
||||||
|
|
||||||
@ -68,11 +69,14 @@ public:
|
|||||||
|
|
||||||
void write(const char* buf, size_t len)
|
void write(const char* buf, size_t len)
|
||||||
{
|
{
|
||||||
|
assert(buf || len == 0);
|
||||||
if(m_alloc - m_size < len) {
|
if(m_alloc - m_size < len) {
|
||||||
expand_buffer(len);
|
expand_buffer(len);
|
||||||
}
|
}
|
||||||
std::memcpy(m_data + m_size, buf, len);
|
if(buf) {
|
||||||
m_size += len;
|
std::memcpy(m_data + m_size, buf, len);
|
||||||
|
m_size += len;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char* data()
|
char* data()
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
#ifndef MSGPACK_V2_CREATE_OBJECT_VISITOR_HPP
|
#ifndef MSGPACK_V2_CREATE_OBJECT_VISITOR_HPP
|
||||||
#define MSGPACK_V2_CREATE_OBJECT_VISITOR_HPP
|
#define MSGPACK_V2_CREATE_OBJECT_VISITOR_HPP
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
#include "msgpack/unpack_decl.hpp"
|
#include "msgpack/unpack_decl.hpp"
|
||||||
#include "msgpack/unpack_exception.hpp"
|
#include "msgpack/unpack_exception.hpp"
|
||||||
#include "msgpack/v2/create_object_visitor_decl.hpp"
|
#include "msgpack/v2/create_object_visitor_decl.hpp"
|
||||||
@ -106,6 +108,7 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool visit_str(const char* v, uint32_t size) {
|
bool visit_str(const char* v, uint32_t size) {
|
||||||
|
assert(v || size == 0);
|
||||||
if (size > m_limit.str()) throw msgpack::str_size_overflow("str size overflow");
|
if (size > m_limit.str()) throw msgpack::str_size_overflow("str size overflow");
|
||||||
msgpack::object* obj = m_stack.back();
|
msgpack::object* obj = m_stack.back();
|
||||||
obj->type = msgpack::type::STR;
|
obj->type = msgpack::type::STR;
|
||||||
@ -115,8 +118,10 @@ public:
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
char* tmp = static_cast<char*>(zone().allocate_align(size, MSGPACK_ZONE_ALIGNOF(char)));
|
char* tmp = static_cast<char*>(zone().allocate_align(size, MSGPACK_ZONE_ALIGNOF(char)));
|
||||||
std::memcpy(tmp, v, size);
|
if (v) {
|
||||||
obj->via.str.ptr = tmp;
|
std::memcpy(tmp, v, size);
|
||||||
|
obj->via.str.ptr = tmp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
obj->via.str.size = size;
|
obj->via.str.size = size;
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user