Added EXT support.

Removed obsolete unpack functions.
Updated examples that no longer use obsolete functions.
Added reference checking function to unpacked. ( unpacked::referenced() )
Added std:: namespace.
Added reference or copy choice function and default behavior:
  When you use unpacker, default behavior is:
    STR, BIN, EXT types are always held by reference.
  When you don't use unpacker, default behavior is:
    STR, BIN, EXT types are always held by copy.
    The memory is allocated from zone.
  You can customize the behavior passing your custom judging function to unpack() or unpacker's constructor.
This commit is contained in:
Takatoshi Kondo
2014-08-06 16:18:37 +09:00
parent ce21ab0ebf
commit 1f5d6b9cac
12 changed files with 519 additions and 400 deletions

View File

@@ -43,7 +43,8 @@ namespace type {
STR = MSGPACK_OBJECT_STR,
BIN = MSGPACK_OBJECT_BIN,
ARRAY = MSGPACK_OBJECT_ARRAY,
MAP = MSGPACK_OBJECT_MAP
MAP = MSGPACK_OBJECT_MAP,
EXT = MSGPACK_OBJECT_EXT
};
}
@@ -71,6 +72,13 @@ struct object_bin {
const char* ptr;
};
struct object_ext {
int8_t type() const { return ptr[0]; }
const char* data() const { return &ptr[1]; }
uint32_t size;
const char* ptr;
};
struct object {
union union_type {
bool boolean;
@@ -81,6 +89,7 @@ struct object {
object_map map;
object_str str;
object_bin bin;
object_ext ext;
};
type::object_type type;
@@ -242,6 +251,10 @@ inline bool operator==(const object& x, const object& y)
return x.via.bin.size == y.via.bin.size &&
memcmp(x.via.bin.ptr, y.via.bin.ptr, x.via.bin.size) == 0;
case type::EXT:
return x.via.bin.size == y.via.bin.size &&
memcmp(x.via.bin.ptr, y.via.bin.ptr, x.via.bin.size) == 0;
case type::ARRAY:
if(x.via.array.size != y.via.array.size) {
return false;
@@ -444,6 +457,11 @@ packer<Stream>& operator<< (packer<Stream>& o, const object& v)
o.pack_bin_body(v.via.bin.ptr, v.via.bin.size);
return o;
case type::EXT:
o.pack_ext(v.via.ext.size, v.via.ext.type());
o.pack_ext_body(v.via.ext.data(), v.via.ext.size);
return o;
case type::ARRAY:
o.pack_array(v.via.array.size);
for(object* p(v.via.array.ptr),