msgpack-c
msgpack-c copied to clipboard
Preserve fixint size on deserialization
Information is lost on deserialization MSGPACK_OBJECT_POSITIVE_INTEGER
and MSGPACK_OBJECT_NEGATIVE_INTEGER
is not enough resolution, especially when the format explicitly stores different sized fixint. Please can you provide a way to access the type the object was packed with?
int8 int16 int32 int64 uint8 uint16 uint32 uint64
Do you mean to provide these types: MSGPACK_OBJECT_POSITIVE_INTEGER_8
, MSGPACK_OBJECT_POSITIVE_INTEGER_16
, MSGPACK_OBJECT_POSITIVE_INTEGER_32
, MSGPACK_OBJECT_POSITIVE_INTEGER_64
and MSGPACK_OBJECT_NEGATIVE_INTEGER_8
,MSGPACK_OBJECT_NEGATIVE_INTEGER_16
,MSGPACK_OBJECT_NEGATIVE_INTEGER_32
,MSGPACK_OBJECT_NEGATIVE_INTEGER_64
?
Not only that, but a preservation of sign:
Lets say the stream contains an "int 8" as described in the spec:
int 8 stores a 8-bit signed integer
+--------+--------+
| 0xd0 |ZZZZZZZZ|
+--------+--------+
When unpacked with msgpack-c, if the value is > 0, it is recast as uint64. There's no way of knowing if the stored value was actually an int8 uint16, int32, etc. Even if uint64 can be recast, the stored type information is lost.
Providing some way to access this information would be very useful.
Further demonstration, the following assertion fails:
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, (std::int8_t)123);
assert(msgpack::unpack(sbuf.data(), sbuf.size()).get().type == MSGPACK_OBJECT_NEGATIVE_INTEGER);
The unpacked type is unsigned even though the original was signed.
See https://github.com/msgpack/msgpack/issues/164#issuecomment-86368081