Skip to content
This repository was archived by the owner on Jan 8, 2026. It is now read-only.
This repository was archived by the owner on Jan 8, 2026. It is now read-only.

Specify encoding of numbers in DAG-CBOR #80

@vmx

Description

@vmx

Numbers can be represented in different ways in CBOR. We should specify how they should be encoded so that all implementations will result with the same binary representation, hence the same hash.

For integers we can follow the Canonical CBOR as specified in the CBOR RFC and use the smallest possible representation.

For floats I'd also follow the recommendation from the Canonical CBOR and represent them as small as possible.

Then there's the last case, floats without a fraction, which actually triggered this issue (see ipld/interface-ipld-format#9 (comment)).

I would do it the js-ipfs way and use an integer if possible, which aligns well with the Converting from JSON to CBOR section of the CBOR RFC. I'm not sure if "without fractional parts" only mean numbers without a decimal point or also include numbers which have only zeros after the decimal point. I would store numbers with a decimal point and zeros only as integer.

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