mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-05-17 20:21:37 +02:00
Fixed -Wextra warnings on gcc.
This commit is contained in:
parent
d15e49cb73
commit
5896ff3746
@ -68,6 +68,7 @@ LIST (APPEND msgpack_HEADERS
|
|||||||
include/msgpack/pack_template.h
|
include/msgpack/pack_template.h
|
||||||
include/msgpack/unpack_define.h
|
include/msgpack/unpack_define.h
|
||||||
include/msgpack/unpack_template.h
|
include/msgpack/unpack_template.h
|
||||||
|
include/msgpack/util.h
|
||||||
include/msgpack/sysdep.h
|
include/msgpack/sysdep.h
|
||||||
include/msgpack/sbuffer.h
|
include/msgpack/sbuffer.h
|
||||||
include/msgpack/version.h
|
include/msgpack/version.h
|
||||||
|
@ -82,7 +82,7 @@ struct define<> {
|
|||||||
{
|
{
|
||||||
if(o.type != type::ARRAY) { throw type_error(); }
|
if(o.type != type::ARRAY) { throw type_error(); }
|
||||||
}
|
}
|
||||||
void msgpack_object(msgpack::object* o, msgpack::zone& z) const
|
void msgpack_object(msgpack::object* o, msgpack::zone&) const
|
||||||
{
|
{
|
||||||
o->type = type::ARRAY;
|
o->type = type::ARRAY;
|
||||||
o->via.array.ptr = nullptr;
|
o->via.array.ptr = nullptr;
|
||||||
|
@ -135,7 +135,7 @@ tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> make_tuple(typename tuple_type<A0>::tr
|
|||||||
|
|
||||||
inline object const& operator>> (
|
inline object const& operator>> (
|
||||||
object const& o,
|
object const& o,
|
||||||
type::tuple<>& v) {
|
type::tuple<>&) {
|
||||||
if(o.type != type::ARRAY) { throw type_error(); }
|
if(o.type != type::ARRAY) { throw type_error(); }
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
@ -155,7 +155,7 @@ object const& operator>> (
|
|||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
const packer<Stream>& operator<< (
|
const packer<Stream>& operator<< (
|
||||||
packer<Stream>& o,
|
packer<Stream>& o,
|
||||||
const type::tuple<>& v) {
|
const type::tuple<>&) {
|
||||||
o.pack_array(0);
|
o.pack_array(0);
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
@ -173,7 +173,7 @@ const packer<Stream>& operator<< (
|
|||||||
|
|
||||||
inline void operator<< (
|
inline void operator<< (
|
||||||
object::with_zone& o,
|
object::with_zone& o,
|
||||||
const type::tuple<>& v) {
|
const type::tuple<>&) {
|
||||||
o.type = type::ARRAY;
|
o.type = type::ARRAY;
|
||||||
o.via.array.ptr = nullptr;
|
o.via.array.ptr = nullptr;
|
||||||
o.via.array.size = 0;
|
o.via.array.size = 0;
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "msgpack/util.h"
|
||||||
#include "msgpack/object.h"
|
#include "msgpack/object.h"
|
||||||
#include "msgpack/zone.h"
|
#include "msgpack/zone.h"
|
||||||
#include "msgpack/pack.h"
|
#include "msgpack/pack.h"
|
||||||
|
@ -82,7 +82,7 @@ struct define<> {
|
|||||||
{
|
{
|
||||||
if(o.type != type::ARRAY) { throw type_error(); }
|
if(o.type != type::ARRAY) { throw type_error(); }
|
||||||
}
|
}
|
||||||
void msgpack_object(msgpack::object* o, msgpack::zone& z) const
|
void msgpack_object(msgpack::object* o, msgpack::zone&) const
|
||||||
{
|
{
|
||||||
o->type = type::ARRAY;
|
o->type = type::ARRAY;
|
||||||
o->via.array.ptr = nullptr;
|
o->via.array.ptr = nullptr;
|
||||||
|
@ -10582,7 +10582,7 @@ tuple<A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16,
|
|||||||
|
|
||||||
inline object const& operator>> (
|
inline object const& operator>> (
|
||||||
object const& o,
|
object const& o,
|
||||||
type::tuple<>& v) {
|
type::tuple<>&) {
|
||||||
if(o.type != type::ARRAY) { throw type_error(); }
|
if(o.type != type::ARRAY) { throw type_error(); }
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
@ -11439,7 +11439,7 @@ object const& operator>> (
|
|||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
const packer<Stream>& operator<< (
|
const packer<Stream>& operator<< (
|
||||||
packer<Stream>& o,
|
packer<Stream>& o,
|
||||||
const type::tuple<>& v) {
|
const type::tuple<>&) {
|
||||||
o.pack_array(0);
|
o.pack_array(0);
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
@ -12263,7 +12263,7 @@ const packer<Stream>& operator<< (
|
|||||||
|
|
||||||
inline void operator<< (
|
inline void operator<< (
|
||||||
object::with_zone& o,
|
object::with_zone& o,
|
||||||
const type::tuple<>& v) {
|
const type::tuple<>&) {
|
||||||
o.type = type::ARRAY;
|
o.type = type::ARRAY;
|
||||||
o.via.array.ptr = nullptr;
|
o.via.array.ptr = nullptr;
|
||||||
o.via.array.size = 0;
|
o.via.array.size = 0;
|
||||||
|
@ -145,7 +145,7 @@ struct define<> {
|
|||||||
{
|
{
|
||||||
if(o.type != type::ARRAY) { throw type_error(); }
|
if(o.type != type::ARRAY) { throw type_error(); }
|
||||||
}
|
}
|
||||||
void msgpack_object(msgpack::object* o, msgpack::zone& z) const
|
void msgpack_object(msgpack::object* o, msgpack::zone&) const
|
||||||
{
|
{
|
||||||
o->type = type::ARRAY;
|
o->type = type::ARRAY;
|
||||||
o->via.array.ptr = NULL;
|
o->via.array.ptr = NULL;
|
||||||
|
@ -115,16 +115,52 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_uint64& v)
|
|||||||
|
|
||||||
|
|
||||||
inline void operator<< (object& o, type::fix_int8 v)
|
inline void operator<< (object& o, type::fix_int8 v)
|
||||||
{ v.get() < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v.get() : o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
{
|
||||||
|
if (v.get() < 0) {
|
||||||
|
o.type = type::NEGATIVE_INTEGER;
|
||||||
|
o.via.i64 = v.get();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
o.type = type::POSITIVE_INTEGER;
|
||||||
|
o.via.u64 = v.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline void operator<< (object& o, type::fix_int16 v)
|
inline void operator<< (object& o, type::fix_int16 v)
|
||||||
{ v.get() < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v.get() : o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
{
|
||||||
|
if(v.get() < 0) {
|
||||||
|
o.type = type::NEGATIVE_INTEGER;
|
||||||
|
o.via.i64 = v.get();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
o.type = type::POSITIVE_INTEGER;
|
||||||
|
o.via.u64 = v.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline void operator<< (object& o, type::fix_int32 v)
|
inline void operator<< (object& o, type::fix_int32 v)
|
||||||
{ v.get() < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v.get() : o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
{
|
||||||
|
if (v.get() < 0) {
|
||||||
|
o.type = type::NEGATIVE_INTEGER;
|
||||||
|
o.via.i64 = v.get();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
o.type = type::POSITIVE_INTEGER;
|
||||||
|
o.via.u64 = v.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline void operator<< (object& o, type::fix_int64 v)
|
inline void operator<< (object& o, type::fix_int64 v)
|
||||||
{ v.get() < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v.get() : o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
{
|
||||||
|
if (v.get() < 0) {
|
||||||
|
o.type = type::NEGATIVE_INTEGER;
|
||||||
|
o.via.i64 = v.get();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
o.type = type::POSITIVE_INTEGER;
|
||||||
|
o.via.u64 = v.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void operator<< (object& o, type::fix_uint8 v)
|
inline void operator<< (object& o, type::fix_uint8 v)
|
||||||
|
@ -98,8 +98,14 @@ namespace detail {
|
|||||||
template <>
|
template <>
|
||||||
struct object_char_sign<true> {
|
struct object_char_sign<true> {
|
||||||
static inline void make(object& o, char v) {
|
static inline void make(object& o, char v) {
|
||||||
v < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v
|
if (v < 0) {
|
||||||
: o.type = type::POSITIVE_INTEGER, o.via.u64 = v;
|
o.type = type::NEGATIVE_INTEGER;
|
||||||
|
o.via.i64 = v;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
o.type = type::POSITIVE_INTEGER;
|
||||||
|
o.via.u64 = v;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -205,20 +211,64 @@ inline void operator<< (object& o, char v)
|
|||||||
|
|
||||||
|
|
||||||
inline void operator<< (object& o, signed char v)
|
inline void operator<< (object& o, signed char v)
|
||||||
{ v < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v : o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
|
{
|
||||||
|
if (v < 0) {
|
||||||
|
o.type = type::NEGATIVE_INTEGER;
|
||||||
|
o.via.i64 = v;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
o.type = type::POSITIVE_INTEGER;
|
||||||
|
o.via.u64 = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline void operator<< (object& o, signed short v)
|
inline void operator<< (object& o, signed short v)
|
||||||
{ v < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v : o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
|
{
|
||||||
|
if (v < 0) {
|
||||||
|
o.type = type::NEGATIVE_INTEGER;
|
||||||
|
o.via.i64 = v;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
o.type = type::POSITIVE_INTEGER;
|
||||||
|
o.via.u64 = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline void operator<< (object& o, signed int v)
|
inline void operator<< (object& o, signed int v)
|
||||||
{ v < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v : o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
|
{
|
||||||
|
if (v < 0) {
|
||||||
|
o.type = type::NEGATIVE_INTEGER;
|
||||||
|
o.via.i64 = v;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
o.type = type::POSITIVE_INTEGER;
|
||||||
|
o.via.u64 = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline void operator<< (object& o, signed long v)
|
inline void operator<< (object& o, signed long v)
|
||||||
{ v < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v : o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
|
{
|
||||||
|
if (v < 0) {
|
||||||
|
o.type = type::NEGATIVE_INTEGER;
|
||||||
|
o.via.i64 = v;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
o.type = type::POSITIVE_INTEGER;
|
||||||
|
o.via.u64 = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline void operator<< (object& o, signed long long v)
|
inline void operator<< (object& o, signed long long v)
|
||||||
{ v < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v : o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
|
{
|
||||||
|
if (v < 0) {
|
||||||
|
o.type = type::NEGATIVE_INTEGER;
|
||||||
|
o.via.i64 = v;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
o.type = type::POSITIVE_INTEGER;
|
||||||
|
o.via.u64 = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline void operator<< (object& o, unsigned char v)
|
inline void operator<< (object& o, unsigned char v)
|
||||||
{ o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
|
{ o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||||
|
@ -29,20 +29,20 @@ struct nil { };
|
|||||||
} // namespace type
|
} // namespace type
|
||||||
|
|
||||||
|
|
||||||
inline object const& operator>> (object const& o, type::nil& v)
|
inline object const& operator>> (object const& o, type::nil&)
|
||||||
{
|
{
|
||||||
if(o.type != type::NIL) { throw type_error(); }
|
if(o.type != type::NIL) { throw type_error(); }
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
inline packer<Stream>& operator<< (packer<Stream>& o, const type::nil& v)
|
inline packer<Stream>& operator<< (packer<Stream>& o, const type::nil&)
|
||||||
{
|
{
|
||||||
o.pack_nil();
|
o.pack_nil();
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void operator<< (object& o, type::nil v)
|
inline void operator<< (object& o, type::nil)
|
||||||
{
|
{
|
||||||
o.type = type::NIL;
|
o.type = type::NIL;
|
||||||
}
|
}
|
||||||
|
@ -207,11 +207,11 @@ public:
|
|||||||
{
|
{
|
||||||
::free(p);
|
::free(p);
|
||||||
}
|
}
|
||||||
static void* operator new(std::size_t size, void* mem) throw()
|
static void* operator new(std::size_t /*size*/, void* mem) throw()
|
||||||
{
|
{
|
||||||
return mem;
|
return mem;
|
||||||
}
|
}
|
||||||
static void operator delete(void *p, void* mem) throw()
|
static void operator delete(void * /*p*/, void* /*mem*/) throw()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ inline void unpack_map_item(object& c, object const& k, object const& v)
|
|||||||
++c.via.map.size;
|
++c.via.map.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void unpack_str(unpack_user& u, const char* b, const char* p, uint64_t l, object& o)
|
inline void unpack_str(unpack_user& u, const char* p, uint64_t l, object& o)
|
||||||
{
|
{
|
||||||
o.type = type::STR;
|
o.type = type::STR;
|
||||||
if (u.reference_func() && u.reference_func()(o.type, l, u.user_data())) {
|
if (u.reference_func() && u.reference_func()(o.type, l, u.user_data())) {
|
||||||
@ -164,7 +164,7 @@ inline void unpack_str(unpack_user& u, const char* b, const char* p, uint64_t l,
|
|||||||
o.via.str.size = l;
|
o.via.str.size = l;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void unpack_bin(unpack_user& u, const char* b, const char* p, uint64_t l, object& o)
|
inline void unpack_bin(unpack_user& u, const char* p, uint64_t l, object& o)
|
||||||
{
|
{
|
||||||
o.type = type::BIN;
|
o.type = type::BIN;
|
||||||
if (u.reference_func() && u.reference_func()(o.type, l, u.user_data())) {
|
if (u.reference_func() && u.reference_func()(o.type, l, u.user_data())) {
|
||||||
@ -370,7 +370,7 @@ public:
|
|||||||
} else if(0xa0 <= selector && selector <= 0xbf) { // FixStr
|
} else if(0xa0 <= selector && selector <= 0xbf) { // FixStr
|
||||||
m_trail = static_cast<uint32_t>(*m_current) & 0x1f;
|
m_trail = static_cast<uint32_t>(*m_current) & 0x1f;
|
||||||
if(m_trail == 0) {
|
if(m_trail == 0) {
|
||||||
unpack_str(m_user, data, n, m_trail, obj);
|
unpack_str(m_user, n, m_trail, obj);
|
||||||
int ret = push_proc(obj, off);
|
int ret = push_proc(obj, off);
|
||||||
if (ret != 0) return ret;
|
if (ret != 0) return ret;
|
||||||
}
|
}
|
||||||
@ -523,7 +523,7 @@ public:
|
|||||||
load<uint8_t>(tmp, n);
|
load<uint8_t>(tmp, n);
|
||||||
m_trail = tmp;
|
m_trail = tmp;
|
||||||
if(m_trail == 0) {
|
if(m_trail == 0) {
|
||||||
unpack_str(m_user, data, n, m_trail, obj);
|
unpack_str(m_user, n, m_trail, obj);
|
||||||
int ret = push_proc(obj, off);
|
int ret = push_proc(obj, off);
|
||||||
if (ret != 0) return ret;
|
if (ret != 0) return ret;
|
||||||
}
|
}
|
||||||
@ -537,7 +537,7 @@ public:
|
|||||||
load<uint8_t>(tmp, n);
|
load<uint8_t>(tmp, n);
|
||||||
m_trail = tmp;
|
m_trail = tmp;
|
||||||
if(m_trail == 0) {
|
if(m_trail == 0) {
|
||||||
unpack_bin(m_user, data, n, m_trail, obj);
|
unpack_bin(m_user, n, m_trail, obj);
|
||||||
int ret = push_proc(obj, off);
|
int ret = push_proc(obj, off);
|
||||||
if (ret != 0) return ret;
|
if (ret != 0) return ret;
|
||||||
}
|
}
|
||||||
@ -565,7 +565,7 @@ public:
|
|||||||
load<uint16_t>(tmp, n);
|
load<uint16_t>(tmp, n);
|
||||||
m_trail = tmp;
|
m_trail = tmp;
|
||||||
if(m_trail == 0) {
|
if(m_trail == 0) {
|
||||||
unpack_str(m_user, data, n, m_trail, obj);
|
unpack_str(m_user, n, m_trail, obj);
|
||||||
int ret = push_proc(obj, off);
|
int ret = push_proc(obj, off);
|
||||||
if (ret != 0) return ret;
|
if (ret != 0) return ret;
|
||||||
}
|
}
|
||||||
@ -579,7 +579,7 @@ public:
|
|||||||
load<uint16_t>(tmp, n);
|
load<uint16_t>(tmp, n);
|
||||||
m_trail = tmp;
|
m_trail = tmp;
|
||||||
if(m_trail == 0) {
|
if(m_trail == 0) {
|
||||||
unpack_bin(m_user, data, n, m_trail, obj);
|
unpack_bin(m_user, n, m_trail, obj);
|
||||||
int ret = push_proc(obj, off);
|
int ret = push_proc(obj, off);
|
||||||
if (ret != 0) return ret;
|
if (ret != 0) return ret;
|
||||||
}
|
}
|
||||||
@ -607,7 +607,7 @@ public:
|
|||||||
load<uint32_t>(tmp, n);
|
load<uint32_t>(tmp, n);
|
||||||
m_trail = tmp;
|
m_trail = tmp;
|
||||||
if(m_trail == 0) {
|
if(m_trail == 0) {
|
||||||
unpack_str(m_user, data, n, m_trail, obj);
|
unpack_str(m_user, n, m_trail, obj);
|
||||||
int ret = push_proc(obj, off);
|
int ret = push_proc(obj, off);
|
||||||
if (ret != 0) return ret;
|
if (ret != 0) return ret;
|
||||||
}
|
}
|
||||||
@ -621,7 +621,7 @@ public:
|
|||||||
load<uint32_t>(tmp, n);
|
load<uint32_t>(tmp, n);
|
||||||
m_trail = tmp;
|
m_trail = tmp;
|
||||||
if(m_trail == 0) {
|
if(m_trail == 0) {
|
||||||
unpack_bin(m_user, data, n, m_trail, obj);
|
unpack_bin(m_user, n, m_trail, obj);
|
||||||
int ret = push_proc(obj, off);
|
int ret = push_proc(obj, off);
|
||||||
if (ret != 0) return ret;
|
if (ret != 0) return ret;
|
||||||
}
|
}
|
||||||
@ -645,12 +645,12 @@ public:
|
|||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case ACS_STR_VALUE: {
|
case ACS_STR_VALUE: {
|
||||||
unpack_str(m_user, data, n, m_trail, obj);
|
unpack_str(m_user, n, m_trail, obj);
|
||||||
int ret = push_proc(obj, off);
|
int ret = push_proc(obj, off);
|
||||||
if (ret != 0) return ret;
|
if (ret != 0) return ret;
|
||||||
} break;
|
} break;
|
||||||
case ACS_BIN_VALUE: {
|
case ACS_BIN_VALUE: {
|
||||||
unpack_bin(m_user, data, n, m_trail, obj);
|
unpack_bin(m_user, n, m_trail, obj);
|
||||||
int ret = push_proc(obj, off);
|
int ret = push_proc(obj, off);
|
||||||
if (ret != 0) return ret;
|
if (ret != 0) return ret;
|
||||||
} break;
|
} break;
|
||||||
@ -1379,7 +1379,7 @@ inline void unpack(unpacked* result,
|
|||||||
else unpack(*result, data, len, f, user_data);
|
else unpack(*result, data, len, f, user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool unpacker::default_reference_func(type::object_type type, uint64_t len, void*)
|
bool unpacker::default_reference_func(type::object_type /*type*/, uint64_t /*len*/, void*)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
23
include/msgpack/util.h
Normal file
23
include/msgpack/util.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* MessagePack for C utilities
|
||||||
|
*
|
||||||
|
* Copyright (C) 2014 FURUHASHI Sadayuki
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
#ifndef MSGPACK_UTIL_H
|
||||||
|
#define MSGPACK_UTIL_H
|
||||||
|
|
||||||
|
#define MSGPACK_UNUSED(a) (void)(a)
|
||||||
|
|
||||||
|
#endif /* MSGPACK_UTIL_H */
|
@ -36,6 +36,7 @@ nobase_include_HEADERS = \
|
|||||||
../include/msgpack/pack_template.h \
|
../include/msgpack/pack_template.h \
|
||||||
../include/msgpack/unpack_define.h \
|
../include/msgpack/unpack_define.h \
|
||||||
../include/msgpack/unpack_template.h \
|
../include/msgpack/unpack_template.h \
|
||||||
|
../include/msgpack/util.h \
|
||||||
../include/msgpack/sysdep.h \
|
../include/msgpack/sysdep.h \
|
||||||
../include/msgpack.h \
|
../include/msgpack.h \
|
||||||
../include/msgpack/sbuffer.h \
|
../include/msgpack/sbuffer.h \
|
||||||
|
136
src/unpack.c
136
src/unpack.c
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "msgpack/unpack.h"
|
#include "msgpack/unpack.h"
|
||||||
#include "msgpack/unpack_define.h"
|
#include "msgpack/unpack_define.h"
|
||||||
|
#include "msgpack/util.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifdef _msgpack_atomic_counter_header
|
#ifdef _msgpack_atomic_counter_header
|
||||||
@ -56,50 +57,143 @@ static int template_execute(
|
|||||||
|
|
||||||
|
|
||||||
static inline msgpack_object template_callback_root(unpack_user* u)
|
static inline msgpack_object template_callback_root(unpack_user* u)
|
||||||
{ msgpack_object o = { MSGPACK_OBJECT_NIL }; return o; }
|
{
|
||||||
|
MSGPACK_UNUSED(u);
|
||||||
|
msgpack_object o;
|
||||||
|
o.type = MSGPACK_OBJECT_NIL;
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
static inline int template_callback_uint8(unpack_user* u, uint8_t d, msgpack_object* o)
|
static inline int template_callback_uint8(unpack_user* u, uint8_t d, msgpack_object* o)
|
||||||
{ o->type = MSGPACK_OBJECT_POSITIVE_INTEGER; o->via.u64 = d; return 0; }
|
{
|
||||||
|
MSGPACK_UNUSED(u);
|
||||||
|
o->type = MSGPACK_OBJECT_POSITIVE_INTEGER;
|
||||||
|
o->via.u64 = d;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static inline int template_callback_uint16(unpack_user* u, uint16_t d, msgpack_object* o)
|
static inline int template_callback_uint16(unpack_user* u, uint16_t d, msgpack_object* o)
|
||||||
{ o->type = MSGPACK_OBJECT_POSITIVE_INTEGER; o->via.u64 = d; return 0; }
|
{
|
||||||
|
MSGPACK_UNUSED(u);
|
||||||
|
o->type = MSGPACK_OBJECT_POSITIVE_INTEGER;
|
||||||
|
o->via.u64 = d;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static inline int template_callback_uint32(unpack_user* u, uint32_t d, msgpack_object* o)
|
static inline int template_callback_uint32(unpack_user* u, uint32_t d, msgpack_object* o)
|
||||||
{ o->type = MSGPACK_OBJECT_POSITIVE_INTEGER; o->via.u64 = d; return 0; }
|
{
|
||||||
|
MSGPACK_UNUSED(u);
|
||||||
|
o->type = MSGPACK_OBJECT_POSITIVE_INTEGER;
|
||||||
|
o->via.u64 = d;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static inline int template_callback_uint64(unpack_user* u, uint64_t d, msgpack_object* o)
|
static inline int template_callback_uint64(unpack_user* u, uint64_t d, msgpack_object* o)
|
||||||
{ o->type = MSGPACK_OBJECT_POSITIVE_INTEGER; o->via.u64 = d; return 0; }
|
{
|
||||||
|
MSGPACK_UNUSED(u);
|
||||||
|
o->type = MSGPACK_OBJECT_POSITIVE_INTEGER;
|
||||||
|
o->via.u64 = d;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static inline int template_callback_int8(unpack_user* u, int8_t d, msgpack_object* o)
|
static inline int template_callback_int8(unpack_user* u, int8_t d, msgpack_object* o)
|
||||||
{ if(d >= 0) { o->type = MSGPACK_OBJECT_POSITIVE_INTEGER; o->via.u64 = (uint64_t)d; return 0; }
|
{
|
||||||
else { o->type = MSGPACK_OBJECT_NEGATIVE_INTEGER; o->via.i64 = d; return 0; } }
|
MSGPACK_UNUSED(u);
|
||||||
|
if(d >= 0) {
|
||||||
|
o->type = MSGPACK_OBJECT_POSITIVE_INTEGER;
|
||||||
|
o->via.u64 = (uint64_t)d;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
o->type = MSGPACK_OBJECT_NEGATIVE_INTEGER;
|
||||||
|
o->via.i64 = d;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static inline int template_callback_int16(unpack_user* u, int16_t d, msgpack_object* o)
|
static inline int template_callback_int16(unpack_user* u, int16_t d, msgpack_object* o)
|
||||||
{ if(d >= 0) { o->type = MSGPACK_OBJECT_POSITIVE_INTEGER; o->via.u64 = (uint64_t)d; return 0; }
|
{
|
||||||
else { o->type = MSGPACK_OBJECT_NEGATIVE_INTEGER; o->via.i64 = d; return 0; } }
|
MSGPACK_UNUSED(u);
|
||||||
|
if(d >= 0) {
|
||||||
|
o->type = MSGPACK_OBJECT_POSITIVE_INTEGER;
|
||||||
|
o->via.u64 = (uint64_t)d;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
o->type = MSGPACK_OBJECT_NEGATIVE_INTEGER;
|
||||||
|
o->via.i64 = d;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static inline int template_callback_int32(unpack_user* u, int32_t d, msgpack_object* o)
|
static inline int template_callback_int32(unpack_user* u, int32_t d, msgpack_object* o)
|
||||||
{ if(d >= 0) { o->type = MSGPACK_OBJECT_POSITIVE_INTEGER; o->via.u64 = (uint64_t)d; return 0; }
|
{
|
||||||
else { o->type = MSGPACK_OBJECT_NEGATIVE_INTEGER; o->via.i64 = d; return 0; } }
|
MSGPACK_UNUSED(u);
|
||||||
|
if(d >= 0) {
|
||||||
|
o->type = MSGPACK_OBJECT_POSITIVE_INTEGER;
|
||||||
|
o->via.u64 = (uint64_t)d;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
o->type = MSGPACK_OBJECT_NEGATIVE_INTEGER;
|
||||||
|
o->via.i64 = d;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static inline int template_callback_int64(unpack_user* u, int64_t d, msgpack_object* o)
|
static inline int template_callback_int64(unpack_user* u, int64_t d, msgpack_object* o)
|
||||||
{ if(d >= 0) { o->type = MSGPACK_OBJECT_POSITIVE_INTEGER; o->via.u64 = (uint64_t)d; return 0; }
|
{
|
||||||
else { o->type = MSGPACK_OBJECT_NEGATIVE_INTEGER; o->via.i64 = d; return 0; } }
|
MSGPACK_UNUSED(u);
|
||||||
|
if(d >= 0) {
|
||||||
|
o->type = MSGPACK_OBJECT_POSITIVE_INTEGER;
|
||||||
|
o->via.u64 = (uint64_t)d;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
o->type = MSGPACK_OBJECT_NEGATIVE_INTEGER;
|
||||||
|
o->via.i64 = d;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static inline int template_callback_float(unpack_user* u, float d, msgpack_object* o)
|
static inline int template_callback_float(unpack_user* u, float d, msgpack_object* o)
|
||||||
{ o->type = MSGPACK_OBJECT_DOUBLE; o->via.dec = d; return 0; }
|
{
|
||||||
|
MSGPACK_UNUSED(u);
|
||||||
|
o->type = MSGPACK_OBJECT_DOUBLE;
|
||||||
|
o->via.dec = d;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static inline int template_callback_double(unpack_user* u, double d, msgpack_object* o)
|
static inline int template_callback_double(unpack_user* u, double d, msgpack_object* o)
|
||||||
{ o->type = MSGPACK_OBJECT_DOUBLE; o->via.dec = d; return 0; }
|
{
|
||||||
|
MSGPACK_UNUSED(u);
|
||||||
|
o->type = MSGPACK_OBJECT_DOUBLE;
|
||||||
|
o->via.dec = d;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static inline int template_callback_nil(unpack_user* u, msgpack_object* o)
|
static inline int template_callback_nil(unpack_user* u, msgpack_object* o)
|
||||||
{ o->type = MSGPACK_OBJECT_NIL; return 0; }
|
{
|
||||||
|
MSGPACK_UNUSED(u);
|
||||||
|
o->type = MSGPACK_OBJECT_NIL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static inline int template_callback_true(unpack_user* u, msgpack_object* o)
|
static inline int template_callback_true(unpack_user* u, msgpack_object* o)
|
||||||
{ o->type = MSGPACK_OBJECT_BOOLEAN; o->via.boolean = true; return 0; }
|
{
|
||||||
|
MSGPACK_UNUSED(u);
|
||||||
|
o->type = MSGPACK_OBJECT_BOOLEAN;
|
||||||
|
o->via.boolean = true;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static inline int template_callback_false(unpack_user* u, msgpack_object* o)
|
static inline int template_callback_false(unpack_user* u, msgpack_object* o)
|
||||||
{ o->type = MSGPACK_OBJECT_BOOLEAN; o->via.boolean = false; return 0; }
|
{
|
||||||
|
MSGPACK_UNUSED(u);
|
||||||
|
o->type = MSGPACK_OBJECT_BOOLEAN;
|
||||||
|
o->via.boolean = false;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static inline int template_callback_array(unpack_user* u, unsigned int n, msgpack_object* o)
|
static inline int template_callback_array(unpack_user* u, unsigned int n, msgpack_object* o)
|
||||||
{
|
{
|
||||||
@ -112,6 +206,7 @@ static inline int template_callback_array(unpack_user* u, unsigned int n, msgpac
|
|||||||
|
|
||||||
static inline int template_callback_array_item(unpack_user* u, msgpack_object* c, msgpack_object o)
|
static inline int template_callback_array_item(unpack_user* u, msgpack_object* c, msgpack_object o)
|
||||||
{
|
{
|
||||||
|
MSGPACK_UNUSED(u);
|
||||||
#if defined(__GNUC__) && !defined(__clang__)
|
#if defined(__GNUC__) && !defined(__clang__)
|
||||||
memcpy(&c->via.array.ptr[c->via.array.size], &o, sizeof(msgpack_object));
|
memcpy(&c->via.array.ptr[c->via.array.size], &o, sizeof(msgpack_object));
|
||||||
#else /* __GNUC__ && !__clang__ */
|
#else /* __GNUC__ && !__clang__ */
|
||||||
@ -132,6 +227,7 @@ static inline int template_callback_map(unpack_user* u, unsigned int n, msgpack_
|
|||||||
|
|
||||||
static inline int template_callback_map_item(unpack_user* u, msgpack_object* c, msgpack_object k, msgpack_object v)
|
static inline int template_callback_map_item(unpack_user* u, msgpack_object* c, msgpack_object k, msgpack_object v)
|
||||||
{
|
{
|
||||||
|
MSGPACK_UNUSED(u);
|
||||||
#if defined(__GNUC__) && !defined(__clang__)
|
#if defined(__GNUC__) && !defined(__clang__)
|
||||||
memcpy(&c->via.map.ptr[c->via.map.size].key, &k, sizeof(msgpack_object));
|
memcpy(&c->via.map.ptr[c->via.map.size].key, &k, sizeof(msgpack_object));
|
||||||
memcpy(&c->via.map.ptr[c->via.map.size].val, &v, sizeof(msgpack_object));
|
memcpy(&c->via.map.ptr[c->via.map.size].val, &v, sizeof(msgpack_object));
|
||||||
@ -145,6 +241,8 @@ static inline int template_callback_map_item(unpack_user* u, msgpack_object* c,
|
|||||||
|
|
||||||
static inline int template_callback_str(unpack_user* u, const char* b, const char* p, unsigned int l, msgpack_object* o)
|
static inline int template_callback_str(unpack_user* u, const char* b, const char* p, unsigned int l, msgpack_object* o)
|
||||||
{
|
{
|
||||||
|
MSGPACK_UNUSED(u);
|
||||||
|
MSGPACK_UNUSED(b);
|
||||||
o->type = MSGPACK_OBJECT_STR;
|
o->type = MSGPACK_OBJECT_STR;
|
||||||
o->via.str.ptr = p;
|
o->via.str.ptr = p;
|
||||||
o->via.str.size = l;
|
o->via.str.size = l;
|
||||||
@ -154,6 +252,8 @@ static inline int template_callback_str(unpack_user* u, const char* b, const cha
|
|||||||
|
|
||||||
static inline int template_callback_bin(unpack_user* u, const char* b, const char* p, unsigned int l, msgpack_object* o)
|
static inline int template_callback_bin(unpack_user* u, const char* b, const char* p, unsigned int l, msgpack_object* o)
|
||||||
{
|
{
|
||||||
|
MSGPACK_UNUSED(u);
|
||||||
|
MSGPACK_UNUSED(b);
|
||||||
o->type = MSGPACK_OBJECT_BIN;
|
o->type = MSGPACK_OBJECT_BIN;
|
||||||
o->via.bin.ptr = p;
|
o->via.bin.ptr = p;
|
||||||
o->via.bin.size = l;
|
o->via.bin.size = l;
|
||||||
|
@ -5,7 +5,7 @@ struct myclass {
|
|||||||
myclass() : num(0), str("default") { }
|
myclass() : num(0), str("default") { }
|
||||||
|
|
||||||
myclass(int num, const std::string& str) :
|
myclass(int num, const std::string& str) :
|
||||||
num(0), str("default") { }
|
num(num), str(str) { }
|
||||||
|
|
||||||
~myclass() { }
|
~myclass() { }
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_message(msgpack::object obj, msgpack::unique_ptr<msgpack::zone> z)
|
void on_message(msgpack::object obj, msgpack::unique_ptr<msgpack::zone>)
|
||||||
{
|
{
|
||||||
EXPECT_EQ(expect, obj.as<int>());
|
EXPECT_EQ(expect, obj.as<int>());
|
||||||
}
|
}
|
||||||
@ -283,7 +283,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_message(msgpack::object obj, msgpack::unique_ptr<msgpack::zone> z)
|
void on_message(msgpack::object obj, msgpack::unique_ptr<msgpack::zone>)
|
||||||
{
|
{
|
||||||
EXPECT_EQ(expect, obj.as<int>());
|
EXPECT_EQ(expect, obj.as<int>());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user