mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-05-24 06:04:44 +02:00
Fixed char packing support.
See https://github.com/msgpack/msgpack-c/issues/57#issuecomment-60670037
This commit is contained in:
parent
8455a2eb70
commit
837c5ecfc3
@ -70,30 +70,6 @@ namespace detail {
|
||||
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;
|
||||
|
||||
@ -163,12 +139,12 @@ inline object const& operator>> (object const& o, unsigned long long& v)
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, char v)
|
||||
{ return type::detail::pack_char(o, v); }
|
||||
{ o.pack_char(v); return o; }
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, signed char v)
|
||||
{ o.pack_int8(v); return o; }
|
||||
{ o.pack_signed_char(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, signed short v)
|
||||
@ -189,7 +165,7 @@ inline packer<Stream>& operator<< (packer<Stream>& o, signed long long v)
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, unsigned char v)
|
||||
{ o.pack_uint8(v); return o; }
|
||||
{ o.pack_unsigned_char(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, unsigned short v)
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <stdexcept>
|
||||
#include <limits>
|
||||
#include <cstring>
|
||||
#include <climits>
|
||||
|
||||
#include "sysdep.h"
|
||||
|
||||
@ -283,11 +284,25 @@ inline packer<Stream>& packer<Stream>::pack_fix_int64(int64_t d)
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_char(char d)
|
||||
{ _pack_char(m_stream, d); return *this; }
|
||||
{
|
||||
#if defined(CHAR_MIN)
|
||||
#if CHAR_MIN < 0
|
||||
pack_imp_int8(d);
|
||||
#else
|
||||
pack_imp_uint8(d);
|
||||
#endif
|
||||
#else
|
||||
#error CHAR_MIN is not defined
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_signed_char(signed char d)
|
||||
{ _pack_signed_char(m_stream, d); return *this; }
|
||||
{
|
||||
pack_imp_int8(d);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_short(short d)
|
||||
@ -424,7 +439,10 @@ inline packer<Stream>& packer<Stream>::pack_long_long(long long d)
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_unsigned_char(unsigned char d)
|
||||
{ _pack_unsigned_char(m_stream, d); return *this; }
|
||||
{
|
||||
pack_imp_uint8(d);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_unsigned_short(unsigned short d)
|
||||
|
Loading…
x
Reference in New Issue
Block a user