Skip to content

Cannot serialize small floats in msgpack float format #1111

@romankarlstetter

Description

@romankarlstetter

Bug description
I stumbled over #1018, since I was not expecting my float values to be serialized as int64.

Furthermore, there currently does not seem to be a way to force serialization of a float to the float msgpack format.
I find this a bit inconsistent API-wise, because there's pack_fix_int32 (and others) for integers, which does force a certain serialization width.

Version: msgpack-cxx 6.1.0, but the problem is probably present since cpp-4.1.2.

Regarding the spec, I interpreted the following such that for "an object of a certain source type, serializers SHOULD use the format among the formats for that specific source type which represents the data in the smallest number of bytes."

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.

To Reproduce

msgpack::packer<std::stringstream> packer(s);
packer.pack_float(2);

Expected behavior
I want to be able to pack a float in the msgpack float representation.

This is also maybe related to #1070.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions