Skip to content

Serialize numeric types with smallest lossless format #2

Description

@timothy-shields

What do you think about serializing numeric types with the smallest lossless format? For example, if I have a double[] of length N containing 0's and 1's, its contents (after the header) would be stored using N bytes, because 0 and 1 fit losslessly into a positive fixnum. If I try to then deserialize to a double[], that would work.

msgpack-cli is already doing this for ints and uints internally.

The implementation of DoubleMsgPackValue.Pack would become something logically similar to this:

public override void Pack(Packer packer)
{
    if (this.Value == (int)this.Value)
    {
        packer.Pack(this.Value < 0 ? (int)this.Value : (uint)this.Value);
    }
    else if (this.Value == (float)this.Value)
    {
        packer.Pack((float)this.Value);
    }
    else
    {
        packer.Pack(this.Value);
    }
}

What are your thoughts? This could potentially be an optional configuration on the MessagePackWriter. I'd be willing to help out with this.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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