mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-20 22:31:33 +02:00
Merge pull request #36 from redboltz/support_plain_char
Supported 'plain' char.
This commit is contained in:
@@ -372,6 +372,28 @@ msgpack_pack_inline_func(_int64)(msgpack_pack_user x, int64_t d)
|
|||||||
msgpack_pack_real_int64(x, d);
|
msgpack_pack_real_int64(x, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
msgpack_pack_inline_func(_char)(msgpack_pack_user x, char d)
|
||||||
|
{
|
||||||
|
#if defined(CHAR_MIN)
|
||||||
|
#if CHAR_MIN < 0
|
||||||
|
msgpack_pack_real_int8(x, d);
|
||||||
|
#else
|
||||||
|
msgpack_pack_real_uint8(x, d);
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#error CHAR_MIN is not defined
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
msgpack_pack_inline_func(_signed_char)(msgpack_pack_user x, signed char d)
|
||||||
|
{
|
||||||
|
msgpack_pack_real_int8(x, d);
|
||||||
|
}
|
||||||
|
|
||||||
|
msgpack_pack_inline_func(_unsigned_char)(msgpack_pack_user x, unsigned char d)
|
||||||
|
{
|
||||||
|
msgpack_pack_real_uint8(x, d);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef msgpack_pack_inline_func_cint
|
#ifdef msgpack_pack_inline_func_cint
|
||||||
|
|
||||||
|
@@ -52,10 +52,14 @@ static void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_w
|
|||||||
static msgpack_packer* msgpack_packer_new(void* data, msgpack_packer_write callback);
|
static msgpack_packer* msgpack_packer_new(void* data, msgpack_packer_write callback);
|
||||||
static void msgpack_packer_free(msgpack_packer* pk);
|
static void msgpack_packer_free(msgpack_packer* pk);
|
||||||
|
|
||||||
|
static int msgpack_pack_char(msgpack_packer* pk, char d);
|
||||||
|
|
||||||
|
static int msgpack_pack_signed_char(msgpack_packer* pk, signed char d);
|
||||||
static int msgpack_pack_short(msgpack_packer* pk, short d);
|
static int msgpack_pack_short(msgpack_packer* pk, short d);
|
||||||
static int msgpack_pack_int(msgpack_packer* pk, int d);
|
static int msgpack_pack_int(msgpack_packer* pk, int d);
|
||||||
static int msgpack_pack_long(msgpack_packer* pk, long d);
|
static int msgpack_pack_long(msgpack_packer* pk, long d);
|
||||||
static int msgpack_pack_long_long(msgpack_packer* pk, long long d);
|
static int msgpack_pack_long_long(msgpack_packer* pk, long long d);
|
||||||
|
static int msgpack_pack_unsigned_char(msgpack_packer* pk, unsigned char d);
|
||||||
static int msgpack_pack_unsigned_short(msgpack_packer* pk, unsigned short d);
|
static int msgpack_pack_unsigned_short(msgpack_packer* pk, unsigned short d);
|
||||||
static int msgpack_pack_unsigned_int(msgpack_packer* pk, unsigned int d);
|
static int msgpack_pack_unsigned_int(msgpack_packer* pk, unsigned int d);
|
||||||
static int msgpack_pack_unsigned_long(msgpack_packer* pk, unsigned long d);
|
static int msgpack_pack_unsigned_long(msgpack_packer* pk, unsigned long d);
|
||||||
|
@@ -54,10 +54,13 @@ public:
|
|||||||
packer<Stream>& pack_fix_int32(int32_t d);
|
packer<Stream>& pack_fix_int32(int32_t d);
|
||||||
packer<Stream>& pack_fix_int64(int64_t d);
|
packer<Stream>& pack_fix_int64(int64_t d);
|
||||||
|
|
||||||
|
packer<Stream>& pack_char(char d);
|
||||||
|
packer<Stream>& pack_signed_char(signed char d);
|
||||||
packer<Stream>& pack_short(short d);
|
packer<Stream>& pack_short(short d);
|
||||||
packer<Stream>& pack_int(int d);
|
packer<Stream>& pack_int(int d);
|
||||||
packer<Stream>& pack_long(long d);
|
packer<Stream>& pack_long(long d);
|
||||||
packer<Stream>& pack_long_long(long long d);
|
packer<Stream>& pack_long_long(long long d);
|
||||||
|
packer<Stream>& pack_unsigned_char(unsigned char d);
|
||||||
packer<Stream>& pack_unsigned_short(unsigned short d);
|
packer<Stream>& pack_unsigned_short(unsigned short d);
|
||||||
packer<Stream>& pack_unsigned_int(unsigned int d);
|
packer<Stream>& pack_unsigned_int(unsigned int d);
|
||||||
packer<Stream>& pack_unsigned_long(unsigned long d);
|
packer<Stream>& pack_unsigned_long(unsigned long d);
|
||||||
@@ -96,10 +99,14 @@ private:
|
|||||||
static void _pack_fix_int32(Stream& x, int32_t d);
|
static void _pack_fix_int32(Stream& x, int32_t d);
|
||||||
static void _pack_fix_int64(Stream& x, int64_t d);
|
static void _pack_fix_int64(Stream& x, int64_t d);
|
||||||
|
|
||||||
|
static void _pack_char(Stream& x, char d);
|
||||||
|
|
||||||
|
static void _pack_signed_char(Stream& x, signed char d);
|
||||||
static void _pack_short(Stream& x, short d);
|
static void _pack_short(Stream& x, short d);
|
||||||
static void _pack_int(Stream& x, int d);
|
static void _pack_int(Stream& x, int d);
|
||||||
static void _pack_long(Stream& x, long d);
|
static void _pack_long(Stream& x, long d);
|
||||||
static void _pack_long_long(Stream& x, long long d);
|
static void _pack_long_long(Stream& x, long long d);
|
||||||
|
static void _pack_unsigned_char(Stream& x, unsigned char d);
|
||||||
static void _pack_unsigned_short(Stream& x, unsigned short d);
|
static void _pack_unsigned_short(Stream& x, unsigned short d);
|
||||||
static void _pack_unsigned_int(Stream& x, unsigned int d);
|
static void _pack_unsigned_int(Stream& x, unsigned int d);
|
||||||
static void _pack_unsigned_long(Stream& x, unsigned long d);
|
static void _pack_unsigned_long(Stream& x, unsigned long d);
|
||||||
@@ -238,6 +245,14 @@ inline packer<Stream>& packer<Stream>::pack_fix_int64(int64_t d)
|
|||||||
{ _pack_fix_int64(m_stream, d); return *this;}
|
{ _pack_fix_int64(m_stream, d); return *this;}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_char(char d)
|
||||||
|
{ _pack_char(m_stream, d); return *this; }
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_signed_char(signed char d)
|
||||||
|
{ _pack_signed_char(m_stream, d); return *this; }
|
||||||
|
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
inline packer<Stream>& packer<Stream>::pack_short(short d)
|
inline packer<Stream>& packer<Stream>::pack_short(short d)
|
||||||
{ _pack_short(m_stream, d); return *this; }
|
{ _pack_short(m_stream, d); return *this; }
|
||||||
@@ -254,6 +269,10 @@ template <typename Stream>
|
|||||||
inline packer<Stream>& packer<Stream>::pack_long_long(long long d)
|
inline packer<Stream>& packer<Stream>::pack_long_long(long long d)
|
||||||
{ _pack_long_long(m_stream, d); return *this; }
|
{ _pack_long_long(m_stream, d); return *this; }
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& packer<Stream>::pack_unsigned_char(unsigned char d)
|
||||||
|
{ _pack_unsigned_char(m_stream, d); return *this; }
|
||||||
|
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
inline packer<Stream>& packer<Stream>::pack_unsigned_short(unsigned short d)
|
inline packer<Stream>& packer<Stream>::pack_unsigned_short(unsigned short d)
|
||||||
{ _pack_unsigned_short(m_stream, d); return *this; }
|
{ _pack_unsigned_short(m_stream, d); return *this; }
|
||||||
|
@@ -57,15 +57,69 @@ namespace detail {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct is_signed {
|
||||||
|
static const bool value = std::numeric_limits<T>::is_signed;
|
||||||
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static inline T convert_integer(object o)
|
static inline T convert_integer(object o)
|
||||||
{
|
{
|
||||||
return detail::convert_integer_sign<T, std::numeric_limits<T>::is_signed>::convert(o);
|
return detail::convert_integer_sign<T, is_signed<T>::value>::convert(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <bool Signed>
|
||||||
|
struct pack_char_sign;
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct pack_char_sign<true> {
|
||||||
|
template <typename Stream>
|
||||||
|
static inline packer<Stream>& pack(packer<Stream>& o, char v) {
|
||||||
|
o.pack_int8(v); return o;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct pack_char_sign<false> {
|
||||||
|
template <typename Stream>
|
||||||
|
static inline packer<Stream>& pack(packer<Stream>& o, char v) {
|
||||||
|
o.pack_uint8(v); return o;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
static inline packer<Stream>& pack_char(packer<Stream>& o, char v) {
|
||||||
|
return pack_char_sign<is_signed<char>::value>::pack(o, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <bool Signed>
|
||||||
|
struct object_char_sign;
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct object_char_sign<true> {
|
||||||
|
static inline void make(object& o, char v) {
|
||||||
|
v < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v
|
||||||
|
: o.type = type::POSITIVE_INTEGER, o.via.u64 = v;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct object_char_sign<false> {
|
||||||
|
static inline void make(object& o, char v) {
|
||||||
|
o.type = type::POSITIVE_INTEGER, o.via.u64 = v;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline void object_char(object& o, char v) {
|
||||||
|
return object_char_sign<is_signed<char>::value>::make(o, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
} // namespace type
|
} // namespace type
|
||||||
|
|
||||||
|
inline char& operator>> (object const& o, char& v)
|
||||||
|
{ v = type::detail::convert_integer<char>(o); return v; }
|
||||||
|
|
||||||
|
|
||||||
inline signed char& operator>> (object o, signed char& v)
|
inline signed char& operator>> (object o, signed char& v)
|
||||||
{ v = type::detail::convert_integer<signed char>(o); return v; }
|
{ v = type::detail::convert_integer<signed char>(o); return v; }
|
||||||
@@ -98,49 +152,56 @@ inline unsigned long& operator>> (object o, unsigned long& v)
|
|||||||
inline unsigned long long& operator>> (object o, unsigned long long& v)
|
inline unsigned long long& operator>> (object o, unsigned long long& v)
|
||||||
{ v = type::detail::convert_integer<unsigned long long>(o); return v; }
|
{ v = type::detail::convert_integer<unsigned long long>(o); return v; }
|
||||||
|
|
||||||
|
template <typename Stream>
|
||||||
|
inline packer<Stream>& operator<< (packer<Stream>& o, char v)
|
||||||
|
{ return type::detail::pack_char(o, v); }
|
||||||
|
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
inline packer<Stream>& operator<< (packer<Stream>& o, const signed char& v)
|
inline packer<Stream>& operator<< (packer<Stream>& o, signed char v)
|
||||||
{ o.pack_int8(v); return o; }
|
{ o.pack_int8(v); return o; }
|
||||||
|
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
inline packer<Stream>& operator<< (packer<Stream>& o, const signed short& v)
|
inline packer<Stream>& operator<< (packer<Stream>& o, signed short v)
|
||||||
{ o.pack_short(v); return o; }
|
{ o.pack_short(v); return o; }
|
||||||
|
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
inline packer<Stream>& operator<< (packer<Stream>& o, const signed int& v)
|
inline packer<Stream>& operator<< (packer<Stream>& o, signed int v)
|
||||||
{ o.pack_int(v); return o; }
|
{ o.pack_int(v); return o; }
|
||||||
|
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
inline packer<Stream>& operator<< (packer<Stream>& o, const signed long& v)
|
inline packer<Stream>& operator<< (packer<Stream>& o, signed long v)
|
||||||
{ o.pack_long(v); return o; }
|
{ o.pack_long(v); return o; }
|
||||||
|
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
inline packer<Stream>& operator<< (packer<Stream>& o, const signed long long& v)
|
inline packer<Stream>& operator<< (packer<Stream>& o, signed long long v)
|
||||||
{ o.pack_long_long(v); return o; }
|
{ o.pack_long_long(v); return o; }
|
||||||
|
|
||||||
|
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
inline packer<Stream>& operator<< (packer<Stream>& o, const unsigned char& v)
|
inline packer<Stream>& operator<< (packer<Stream>& o, unsigned char v)
|
||||||
{ o.pack_uint8(v); return o; }
|
{ o.pack_uint8(v); return o; }
|
||||||
|
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
inline packer<Stream>& operator<< (packer<Stream>& o, const unsigned short& v)
|
inline packer<Stream>& operator<< (packer<Stream>& o, unsigned short v)
|
||||||
{ o.pack_unsigned_short(v); return o; }
|
{ o.pack_unsigned_short(v); return o; }
|
||||||
|
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
inline packer<Stream>& operator<< (packer<Stream>& o, const unsigned int& v)
|
inline packer<Stream>& operator<< (packer<Stream>& o, unsigned int v)
|
||||||
{ o.pack_unsigned_int(v); return o; }
|
{ o.pack_unsigned_int(v); return o; }
|
||||||
|
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
inline packer<Stream>& operator<< (packer<Stream>& o, const unsigned long& v)
|
inline packer<Stream>& operator<< (packer<Stream>& o, unsigned long v)
|
||||||
{ o.pack_unsigned_long(v); return o; }
|
{ o.pack_unsigned_long(v); return o; }
|
||||||
|
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
inline packer<Stream>& operator<< (packer<Stream>& o, const unsigned long long& v)
|
inline packer<Stream>& operator<< (packer<Stream>& o, unsigned long long v)
|
||||||
{ o.pack_unsigned_long_long(v); return o; }
|
{ o.pack_unsigned_long_long(v); return o; }
|
||||||
|
|
||||||
|
|
||||||
|
inline void operator<< (object& o, char v)
|
||||||
|
{ type::detail::object_char(o, 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; }
|
{ v < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v : o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||||
|
|
||||||
@@ -173,6 +234,10 @@ inline void operator<< (object& o, unsigned long long v)
|
|||||||
{ o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
|
{ o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||||
|
|
||||||
|
|
||||||
|
inline void operator<< (object::with_zone& o, char v)
|
||||||
|
{ static_cast<object&>(o) << v; }
|
||||||
|
|
||||||
|
|
||||||
inline void operator<< (object::with_zone& o, signed char v)
|
inline void operator<< (object::with_zone& o, signed char v)
|
||||||
{ static_cast<object&>(o) << v; }
|
{ static_cast<object&>(o) << v; }
|
||||||
|
|
||||||
@@ -185,7 +250,7 @@ inline void operator<< (object::with_zone& o, signed int v)
|
|||||||
inline void operator<< (object::with_zone& o, signed long v)
|
inline void operator<< (object::with_zone& o, signed long v)
|
||||||
{ static_cast<object&>(o) << v; }
|
{ static_cast<object&>(o) << v; }
|
||||||
|
|
||||||
inline void operator<< (object::with_zone& o, signed long long v)
|
inline void operator<< (object::with_zone& o, const signed long long& v)
|
||||||
{ static_cast<object&>(o) << v; }
|
{ static_cast<object&>(o) << v; }
|
||||||
|
|
||||||
|
|
||||||
@@ -201,7 +266,7 @@ inline void operator<< (object::with_zone& o, unsigned int v)
|
|||||||
inline void operator<< (object::with_zone& o, unsigned long v)
|
inline void operator<< (object::with_zone& o, unsigned long v)
|
||||||
{ static_cast<object&>(o) << v; }
|
{ static_cast<object&>(o) << v; }
|
||||||
|
|
||||||
inline void operator<< (object::with_zone& o, unsigned long long v)
|
inline void operator<< (object::with_zone& o, const unsigned long long& v)
|
||||||
{ static_cast<object&>(o) << v; }
|
{ static_cast<object&>(o) << v; }
|
||||||
|
|
||||||
|
|
||||||
|
@@ -45,6 +45,22 @@ const double kEPS = 1e-10;
|
|||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
|
TEST(MSGPACK, simple_buffer_char)
|
||||||
|
{
|
||||||
|
GEN_TEST(char);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(MSGPACK, simple_buffer_signed_char)
|
||||||
|
{
|
||||||
|
GEN_TEST(signed char);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(MSGPACK, simple_buffer_unsigned_char)
|
||||||
|
{
|
||||||
|
GEN_TEST(unsigned char);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(MSGPACK, simple_buffer_short)
|
TEST(MSGPACK, simple_buffer_short)
|
||||||
{
|
{
|
||||||
GEN_TEST(short);
|
GEN_TEST(short);
|
||||||
@@ -781,6 +797,21 @@ TEST(MSGPACK_USER_DEFINED, simple_buffer_union_member)
|
|||||||
} \
|
} \
|
||||||
} while(0);
|
} while(0);
|
||||||
|
|
||||||
|
TEST(MSGPACK, vrefbuffer_char)
|
||||||
|
{
|
||||||
|
GEN_TEST_VREF(char);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(MSGPACK, vrefbuffer_signed_char)
|
||||||
|
{
|
||||||
|
GEN_TEST_VREF(signed char);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(MSGPACK, vrefbuffer_unsigned_char)
|
||||||
|
{
|
||||||
|
GEN_TEST_VREF(unsigned char);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(MSGPACK, vrefbuffer_short)
|
TEST(MSGPACK, vrefbuffer_short)
|
||||||
{
|
{
|
||||||
GEN_TEST_VREF(short);
|
GEN_TEST_VREF(short);
|
||||||
@@ -901,6 +932,21 @@ TEST(MSGPACK, vrefbuffer_int64)
|
|||||||
; \
|
; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(MSGPACK, stream_char)
|
||||||
|
{
|
||||||
|
GEN_TEST_STREAM(char);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(MSGPACK, stream_signed_char)
|
||||||
|
{
|
||||||
|
GEN_TEST_STREAM(signed char);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(MSGPACK, stream_unsigned_char)
|
||||||
|
{
|
||||||
|
GEN_TEST_STREAM(unsigned char);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(MSGPACK, stream_short)
|
TEST(MSGPACK, stream_short)
|
||||||
{
|
{
|
||||||
GEN_TEST_STREAM(short);
|
GEN_TEST_STREAM(short);
|
||||||
|
@@ -76,6 +76,24 @@ const double kEPS = 1e-10;
|
|||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
|
TEST(MSGPACKC, simple_buffer_char)
|
||||||
|
{
|
||||||
|
#if defined(CHAR_MIN)
|
||||||
|
#if CHAR_MIN < 0
|
||||||
|
GEN_TEST_SIGNED(char, char);
|
||||||
|
#else
|
||||||
|
GEN_TEST_UNSIGNED(char, char);
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#error CHAR_MIN is not defined
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(MSGPACKC, simple_buffer_singed_char)
|
||||||
|
{
|
||||||
|
GEN_TEST_SIGNED(signed char, signed_char);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(MSGPACKC, simple_buffer_short)
|
TEST(MSGPACKC, simple_buffer_short)
|
||||||
{
|
{
|
||||||
GEN_TEST_SIGNED(short, short);
|
GEN_TEST_SIGNED(short, short);
|
||||||
@@ -96,6 +114,11 @@ TEST(MSGPACKC, simple_buffer_long_long)
|
|||||||
GEN_TEST_SIGNED(long long, long_long);
|
GEN_TEST_SIGNED(long long, long_long);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(MSGPACKC, simple_buffer_unsigned_char)
|
||||||
|
{
|
||||||
|
GEN_TEST_UNSIGNED(unsigned char, unsigned_char);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(MSGPACKC, simple_buffer_unsigned_short)
|
TEST(MSGPACKC, simple_buffer_unsigned_short)
|
||||||
{
|
{
|
||||||
GEN_TEST_UNSIGNED(unsigned short, unsigned_short);
|
GEN_TEST_UNSIGNED(unsigned short, unsigned_short);
|
||||||
|
Reference in New Issue
Block a user