-
Notifications
You must be signed in to change notification settings - Fork 932
Closed
Description
As the spec states:
If an object can be represented in multiple possible output formats, serializers SHOULD use the format which represents the data in the smallest number of bytes.
should double and float be packed in the smallest way possible.
Currently double and floats are packed in full size. Even if they store the value 0. The following change would "fix" this issue for double.
template <typename Stream>
inline packer<Stream>& packer<Stream>::pack_double(double d)
{
if (d == int64_t(d))
{
pack_imp_int64(int64_t(d));
return *this;
}
union { double f; uint64_t i; } mem;
mem.f = d;
char buf[9];
buf[0] = static_cast<char>(0xcbu);
#if defined(TARGET_OS_IPHONE)
// ok
#elif defined(__arm__) && !(__ARM_EABI__) // arm-oabi
// https://github.com/msgpack/msgpack-perl/pull/1
mem.i = (mem.i & 0xFFFFFFFFUL) << 32UL | (mem.i >> 32UL);
#endif
_msgpack_store64(&buf[1], mem.i);
append_buffer(buf, 9);
return *this;
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels