mirror of
https://github.com/msgpack/msgpack-c.git
synced 2026-01-10 08:05:13 +01:00
Replaced C-style casts with C++ style casts.
This commit is contained in:
@@ -530,7 +530,7 @@ std::ostream& operator<< (std::ostream& s, const object& o)
|
||||
|
||||
default:
|
||||
// FIXME
|
||||
s << "#<UNKNOWN " << (uint16_t)o.type << ">";
|
||||
s << "#<UNKNOWN " << static_cast<uint16_t>(o.type) << ">";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -616,11 +616,11 @@ inline packer<Stream>& packer<Stream>::pack_array(size_t n)
|
||||
append_buffer(&d, 1);
|
||||
} else if(n < 65536) {
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xdc); _msgpack_store16(&buf[1], (uint16_t)n);
|
||||
buf[0] = static_cast<char>(0xdc); _msgpack_store16(&buf[1], static_cast<uint16_t>(n));
|
||||
append_buffer(buf, 3);
|
||||
} else {
|
||||
char buf[5];
|
||||
buf[0] = static_cast<char>(0xdd); _msgpack_store32(&buf[1], (uint32_t)n);
|
||||
buf[0] = static_cast<char>(0xdd); _msgpack_store32(&buf[1], static_cast<uint32_t>(n));
|
||||
append_buffer(buf, 5);
|
||||
}
|
||||
return *this;
|
||||
@@ -635,11 +635,11 @@ inline packer<Stream>& packer<Stream>::pack_map(size_t n)
|
||||
append_buffer(&buf, 1);
|
||||
} else if(n < 65536) {
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xde); _msgpack_store16(&buf[1], (uint16_t)n);
|
||||
buf[0] = static_cast<char>(0xde); _msgpack_store16(&buf[1], static_cast<uint16_t>(n));
|
||||
append_buffer(buf, 3);
|
||||
} else {
|
||||
char buf[5];
|
||||
buf[0] = static_cast<char>(0xdf); _msgpack_store32(&buf[1], (uint32_t)n);
|
||||
buf[0] = static_cast<char>(0xdf); _msgpack_store32(&buf[1], static_cast<uint32_t>(n));
|
||||
append_buffer(buf, 5);
|
||||
}
|
||||
return *this;
|
||||
@@ -649,20 +649,20 @@ template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_str(size_t l)
|
||||
{
|
||||
if(l < 32) {
|
||||
unsigned char d = 0xa0 | (uint8_t)l;
|
||||
unsigned char d = 0xa0 | static_cast<uint8_t>(l);
|
||||
char buf = take8_8(d);
|
||||
append_buffer(&buf, 1);
|
||||
} else if(l < 256) {
|
||||
char buf[2];
|
||||
buf[0] = static_cast<char>(0xd9); buf[1] = (uint8_t)l;
|
||||
buf[0] = static_cast<char>(0xd9); buf[1] = static_cast<uint8_t>(l);
|
||||
append_buffer(buf, 2);
|
||||
} else if(l < 65536) {
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xda); _msgpack_store16(&buf[1], (uint16_t)l);
|
||||
buf[0] = static_cast<char>(0xda); _msgpack_store16(&buf[1], static_cast<uint16_t>(l));
|
||||
append_buffer(buf, 3);
|
||||
} else {
|
||||
char buf[5];
|
||||
buf[0] = static_cast<char>(0xdb); _msgpack_store32(&buf[1], (uint32_t)l);
|
||||
buf[0] = static_cast<char>(0xdb); _msgpack_store32(&buf[1], static_cast<uint32_t>(l));
|
||||
append_buffer(buf, 5);
|
||||
}
|
||||
return *this;
|
||||
@@ -680,15 +680,15 @@ inline packer<Stream>& packer<Stream>::pack_bin(size_t l)
|
||||
{
|
||||
if(l < 256) {
|
||||
char buf[2];
|
||||
buf[0] = static_cast<char>(0xc4); buf[1] = (uint8_t)l;
|
||||
buf[0] = static_cast<char>(0xc4); buf[1] = static_cast<uint8_t>(l);
|
||||
append_buffer(buf, 2);
|
||||
} else if(l < 65536) {
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xc5); _msgpack_store16(&buf[1], (uint16_t)l);
|
||||
buf[0] = static_cast<char>(0xc5); _msgpack_store16(&buf[1], static_cast<uint16_t>(l));
|
||||
append_buffer(buf, 3);
|
||||
} else {
|
||||
char buf[5];
|
||||
buf[0] = static_cast<char>(0xc6); _msgpack_store32(&buf[1], (uint32_t)l);
|
||||
buf[0] = static_cast<char>(0xc6); _msgpack_store32(&buf[1], static_cast<uint32_t>(l));
|
||||
append_buffer(buf, 5);
|
||||
}
|
||||
return *this;
|
||||
@@ -731,7 +731,7 @@ inline void packer<Stream>::pack_imp_uint16(T d)
|
||||
} else {
|
||||
/* unsigned 16 */
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xcd); _msgpack_store16(&buf[1], (uint16_t)d);
|
||||
buf[0] = static_cast<char>(0xcd); _msgpack_store16(&buf[1], static_cast<uint16_t>(d));
|
||||
append_buffer(buf, 3);
|
||||
}
|
||||
}
|
||||
@@ -754,12 +754,12 @@ inline void packer<Stream>::pack_imp_uint32(T d)
|
||||
if(d < (1<<16)) {
|
||||
/* unsigned 16 */
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xcd); _msgpack_store16(&buf[1], (uint16_t)d);
|
||||
buf[0] = static_cast<char>(0xcd); _msgpack_store16(&buf[1], static_cast<uint16_t>(d));
|
||||
append_buffer(buf, 3);
|
||||
} else {
|
||||
/* unsigned 32 */
|
||||
char buf[5];
|
||||
buf[0] = static_cast<char>(0xce); _msgpack_store32(&buf[1], (uint32_t)d);
|
||||
buf[0] = static_cast<char>(0xce); _msgpack_store32(&buf[1], static_cast<uint32_t>(d));
|
||||
append_buffer(buf, 5);
|
||||
}
|
||||
}
|
||||
@@ -783,12 +783,12 @@ inline void packer<Stream>::pack_imp_uint64(T d)
|
||||
if(d < (1ULL<<16)) {
|
||||
/* unsigned 16 */
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xcd); _msgpack_store16(&buf[1], (uint16_t)d);
|
||||
buf[0] = static_cast<char>(0xcd); _msgpack_store16(&buf[1], static_cast<uint16_t>(d));
|
||||
append_buffer(buf, 3);
|
||||
} else if(d < (1ULL<<32)) {
|
||||
/* unsigned 32 */
|
||||
char buf[5];
|
||||
buf[0] = static_cast<char>(0xce); _msgpack_store32(&buf[1], (uint32_t)d);
|
||||
buf[0] = static_cast<char>(0xce); _msgpack_store32(&buf[1], static_cast<uint32_t>(d));
|
||||
append_buffer(buf, 5);
|
||||
} else {
|
||||
/* unsigned 64 */
|
||||
@@ -822,7 +822,7 @@ inline void packer<Stream>::pack_imp_int16(T d)
|
||||
if(d < -(1<<7)) {
|
||||
/* signed 16 */
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xd1); _msgpack_store16(&buf[1], (int16_t)d);
|
||||
buf[0] = static_cast<char>(0xd1); _msgpack_store16(&buf[1], static_cast<int16_t>(d));
|
||||
append_buffer(buf, 3);
|
||||
} else {
|
||||
/* signed 8 */
|
||||
@@ -841,7 +841,7 @@ inline void packer<Stream>::pack_imp_int16(T d)
|
||||
} else {
|
||||
/* unsigned 16 */
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xcd); _msgpack_store16(&buf[1], (uint16_t)d);
|
||||
buf[0] = static_cast<char>(0xcd); _msgpack_store16(&buf[1], static_cast<uint16_t>(d));
|
||||
append_buffer(buf, 3);
|
||||
}
|
||||
}
|
||||
@@ -855,12 +855,12 @@ inline void packer<Stream>::pack_imp_int32(T d)
|
||||
if(d < -(1<<15)) {
|
||||
/* signed 32 */
|
||||
char buf[5];
|
||||
buf[0] = static_cast<char>(0xd2); _msgpack_store32(&buf[1], (int32_t)d);
|
||||
buf[0] = static_cast<char>(0xd2); _msgpack_store32(&buf[1], static_cast<int32_t>(d));
|
||||
append_buffer(buf, 5);
|
||||
} else if(d < -(1<<7)) {
|
||||
/* signed 16 */
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xd1); _msgpack_store16(&buf[1], (int16_t)d);
|
||||
buf[0] = static_cast<char>(0xd1); _msgpack_store16(&buf[1], static_cast<int16_t>(d));
|
||||
append_buffer(buf, 3);
|
||||
} else {
|
||||
/* signed 8 */
|
||||
@@ -879,12 +879,12 @@ inline void packer<Stream>::pack_imp_int32(T d)
|
||||
} else if(d < (1<<16)) {
|
||||
/* unsigned 16 */
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xcd); _msgpack_store16(&buf[1], (uint16_t)d);
|
||||
buf[0] = static_cast<char>(0xcd); _msgpack_store16(&buf[1], static_cast<uint16_t>(d));
|
||||
append_buffer(buf, 3);
|
||||
} else {
|
||||
/* unsigned 32 */
|
||||
char buf[5];
|
||||
buf[0] = static_cast<char>(0xce); _msgpack_store32(&buf[1], (uint32_t)d);
|
||||
buf[0] = static_cast<char>(0xce); _msgpack_store32(&buf[1], static_cast<uint32_t>(d));
|
||||
append_buffer(buf, 5);
|
||||
}
|
||||
}
|
||||
@@ -904,14 +904,14 @@ inline void packer<Stream>::pack_imp_int64(T d)
|
||||
} else {
|
||||
/* signed 32 */
|
||||
char buf[5];
|
||||
buf[0] = static_cast<char>(0xd2); _msgpack_store32(&buf[1], (int32_t)d);
|
||||
buf[0] = static_cast<char>(0xd2); _msgpack_store32(&buf[1], static_cast<int32_t>(d));
|
||||
append_buffer(buf, 5);
|
||||
}
|
||||
} else {
|
||||
if(d < -(1<<7)) {
|
||||
/* signed 16 */
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xd1); _msgpack_store16(&buf[1], (int16_t)d);
|
||||
buf[0] = static_cast<char>(0xd1); _msgpack_store16(&buf[1], static_cast<int16_t>(d));
|
||||
append_buffer(buf, 3);
|
||||
} else {
|
||||
/* signed 8 */
|
||||
@@ -932,14 +932,14 @@ inline void packer<Stream>::pack_imp_int64(T d)
|
||||
} else {
|
||||
/* unsigned 16 */
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xcd); _msgpack_store16(&buf[1], (uint16_t)d);
|
||||
buf[0] = static_cast<char>(0xcd); _msgpack_store16(&buf[1], static_cast<uint16_t>(d));
|
||||
append_buffer(buf, 3);
|
||||
}
|
||||
} else {
|
||||
if(d < (1LL<<32)) {
|
||||
/* unsigned 32 */
|
||||
char buf[5];
|
||||
buf[0] = static_cast<char>(0xce); _msgpack_store32(&buf[1], (uint32_t)d);
|
||||
buf[0] = static_cast<char>(0xce); _msgpack_store32(&buf[1], static_cast<uint32_t>(d));
|
||||
append_buffer(buf, 5);
|
||||
} else {
|
||||
/* unsigned 64 */
|
||||
|
||||
@@ -30,13 +30,13 @@ namespace msgpack {
|
||||
inline float& operator>> (object const& o, float& v)
|
||||
{
|
||||
if(o.type == type::DOUBLE) {
|
||||
v = (float)o.via.dec;
|
||||
v = static_cast<float>(o.via.dec);
|
||||
}
|
||||
else if (o.type == type::POSITIVE_INTEGER) {
|
||||
v = (float)o.via.u64;
|
||||
v = static_cast<float>(o.via.u64);
|
||||
}
|
||||
else if (o.type == type::NEGATIVE_INTEGER) {
|
||||
v = (float)o.via.i64;
|
||||
v = static_cast<float>(o.via.i64);
|
||||
}
|
||||
else {
|
||||
throw type_error();
|
||||
@@ -58,10 +58,10 @@ inline double& operator>> (object const& o, double& v)
|
||||
v = o.via.dec;
|
||||
}
|
||||
else if (o.type == type::POSITIVE_INTEGER) {
|
||||
v = (double)o.via.u64;
|
||||
v = static_cast<double>(o.via.u64);
|
||||
}
|
||||
else if (o.type == type::NEGATIVE_INTEGER) {
|
||||
v = (double)o.via.i64;
|
||||
v = static_cast<double>(o.via.i64);
|
||||
}
|
||||
else {
|
||||
throw type_error();
|
||||
@@ -80,7 +80,7 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const double& v)
|
||||
inline void operator<< (object& o, float v)
|
||||
{
|
||||
o.type = type::DOUBLE;
|
||||
o.via.dec = (double)v;
|
||||
o.via.dec = static_cast<double>(v);
|
||||
}
|
||||
|
||||
inline void operator<< (object& o, double v)
|
||||
|
||||
@@ -33,13 +33,13 @@ namespace detail {
|
||||
struct convert_integer_sign<T, true> {
|
||||
static inline T convert(object const& o) {
|
||||
if(o.type == type::POSITIVE_INTEGER) {
|
||||
if(o.via.u64 > (uint64_t)std::numeric_limits<T>::max())
|
||||
if(o.via.u64 > static_cast<uint64_t>(std::numeric_limits<T>::max()))
|
||||
{ throw type_error(); }
|
||||
return (T)o.via.u64;
|
||||
return static_cast<T>(o.via.u64);
|
||||
} else if(o.type == type::NEGATIVE_INTEGER) {
|
||||
if(o.via.i64 < (int64_t)std::numeric_limits<T>::min())
|
||||
if(o.via.i64 < static_cast<int64_t>(std::numeric_limits<T>::min()))
|
||||
{ throw type_error(); }
|
||||
return (T)o.via.i64;
|
||||
return static_cast<T>(o.via.i64);
|
||||
}
|
||||
throw type_error();
|
||||
}
|
||||
@@ -49,9 +49,9 @@ namespace detail {
|
||||
struct convert_integer_sign<T, false> {
|
||||
static inline T convert(object const& o) {
|
||||
if(o.type == type::POSITIVE_INTEGER) {
|
||||
if(o.via.u64 > (uint64_t)std::numeric_limits<T>::max())
|
||||
if(o.via.u64 > static_cast<uint64_t>(std::numeric_limits<T>::max()))
|
||||
{ throw type_error(); }
|
||||
return (T)o.via.u64;
|
||||
return static_cast<T>(o.via.u64);
|
||||
}
|
||||
throw type_error();
|
||||
}
|
||||
|
||||
@@ -51,9 +51,9 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const std::string& v)
|
||||
inline void operator<< (object::with_zone& o, const std::string& v)
|
||||
{
|
||||
o.type = type::STR;
|
||||
char* ptr = (char*)o.zone->allocate_align(v.size());
|
||||
char* ptr = static_cast<char*>(o.zone->allocate_align(v.size()));
|
||||
o.via.str.ptr = ptr;
|
||||
o.via.str.size = (uint32_t)v.size();
|
||||
o.via.str.size = static_cast<uint32_t>(v.size());
|
||||
memcpy(ptr, v.data(), v.size());
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ inline void operator<< (object& o, const std::string& v)
|
||||
{
|
||||
o.type = type::STR;
|
||||
o.via.str.ptr = v.data();
|
||||
o.via.str.size = (uint32_t)v.size();
|
||||
o.via.str.size = static_cast<uint32_t>(v.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ struct unpack_array {
|
||||
bool operator()(unpack_user&u, unsigned int n, object& o) const {
|
||||
o.type = type::ARRAY;
|
||||
o.via.array.size = 0;
|
||||
o.via.array.ptr = (object*)u.zone().allocate_align(n*sizeof(object));
|
||||
o.via.array.ptr = static_cast<object*>(u.zone().allocate_align(n*sizeof(object)));
|
||||
if(o.via.array.ptr == nullptr) { return false; }
|
||||
return true;
|
||||
}
|
||||
@@ -128,7 +128,7 @@ struct unpack_map {
|
||||
bool operator()(unpack_user& u, unsigned int n, object& o) const {
|
||||
o.type = type::MAP;
|
||||
o.via.map.size = 0;
|
||||
o.via.map.ptr = (object_kv*)u.zone().allocate_align(n*sizeof(object_kv));
|
||||
o.via.map.ptr = static_cast<object_kv*>(u.zone().allocate_align(n*sizeof(object_kv)));
|
||||
if(o.via.map.ptr == nullptr) { return false; }
|
||||
return true;
|
||||
}
|
||||
@@ -184,26 +184,24 @@ private:
|
||||
|
||||
inline void init_count(void* buffer)
|
||||
{
|
||||
*(volatile _msgpack_atomic_counter_t*)buffer = 1;
|
||||
*reinterpret_cast<volatile _msgpack_atomic_counter_t*>(buffer) = 1;
|
||||
}
|
||||
|
||||
inline void decl_count(void* buffer)
|
||||
{
|
||||
// atomic if(--*(_msgpack_atomic_counter_t*)buffer == 0) { free(buffer); }
|
||||
if(_msgpack_sync_decr_and_fetch((volatile _msgpack_atomic_counter_t*)buffer) == 0) {
|
||||
if(_msgpack_sync_decr_and_fetch(reinterpret_cast<volatile _msgpack_atomic_counter_t*>(buffer)) == 0) {
|
||||
free(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
inline void incr_count(void* buffer)
|
||||
{
|
||||
// atomic ++*(_msgpack_atomic_counter_t*)buffer;
|
||||
_msgpack_sync_incr_and_fetch((volatile _msgpack_atomic_counter_t*)buffer);
|
||||
_msgpack_sync_incr_and_fetch(reinterpret_cast<volatile _msgpack_atomic_counter_t*>(buffer));
|
||||
}
|
||||
|
||||
inline _msgpack_atomic_counter_t get_count(void* buffer)
|
||||
{
|
||||
return *(volatile _msgpack_atomic_counter_t*)buffer;
|
||||
return *reinterpret_cast<volatile _msgpack_atomic_counter_t*>(buffer);
|
||||
}
|
||||
|
||||
struct fix_tag {
|
||||
@@ -872,7 +870,7 @@ inline unpacker::unpacker(size_t initial_buffer_size)
|
||||
initial_buffer_size = COUNTER_SIZE;
|
||||
}
|
||||
|
||||
char* buffer = reinterpret_cast<char*>(::malloc(initial_buffer_size));
|
||||
char* buffer = static_cast<char*>(::malloc(initial_buffer_size));
|
||||
if(!buffer) {
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
@@ -929,7 +927,7 @@ inline void unpacker::expand_buffer(size_t size)
|
||||
next_size *= 2;
|
||||
}
|
||||
|
||||
char* tmp = reinterpret_cast<char*>(::realloc(buffer_, next_size));
|
||||
char* tmp = static_cast<char*>(::realloc(buffer_, next_size));
|
||||
if(!tmp) {
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
@@ -944,7 +942,7 @@ inline void unpacker::expand_buffer(size_t size)
|
||||
next_size *= 2;
|
||||
}
|
||||
|
||||
char* tmp = reinterpret_cast<char*>(::malloc(next_size));
|
||||
char* tmp = static_cast<char*>(::malloc(next_size));
|
||||
if(!tmp) {
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ public:
|
||||
tail_ = nvec + nused;
|
||||
}
|
||||
|
||||
tail_->iov_base = (char*)buf;
|
||||
tail_->iov_base = const_cast<char*>(buf);
|
||||
tail_->iov_len = len;
|
||||
++tail_;
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ public:
|
||||
|
||||
size_t size() const
|
||||
{
|
||||
return (char*)stream_.next_out - data_;
|
||||
return reinterpret_cast<char*>(stream_.next_out) - data_;
|
||||
}
|
||||
|
||||
void reset()
|
||||
|
||||
Reference in New Issue
Block a user