Skip to content

fix: uints are ok#20

Merged
frrist merged 2 commits into
mainfrom
ash/fix/uint-is-ok
May 15, 2026
Merged

fix: uints are ok#20
frrist merged 2 commits into
mainfrom
ash/fix/uint-is-ok

Conversation

@alanshaw
Copy link
Copy Markdown
Member

@alanshaw alanshaw commented May 15, 2026

Nowhere on the IPLD docs/specs is there any mention of uint being supported.

The only discussion I can find of this is here and here.

It is NOT supported in IPLD.

HOWEVER

CBOR does not support uints either! It supports positive and negative ints. The cbor-gen tool just outputs the correct header depending on the type and value. i.e. for int it outputs either "unsigned int header" or "negative int header" and when it has a uint, it only outputs "unsigned int header" (since it cannot be negative).

So by using uints, we're still outputting dag-cbor compliant encoding data.

Where it gets interesting is when you deserialize. If you're trying to deserialize into a uint, then cbor-gen actually gives you more type safety since it'll try to read a "unsigned int header" and will fail if it sees a "negative int header", which saves us having to do a bunch of < 0 checks in code.

i.e. we should just use uint where it's appropriate and stop worrying.

@alanshaw alanshaw requested review from Peeja and frrist May 15, 2026 14:42
@frrist frrist merged commit 935195a into main May 15, 2026
4 checks passed
@alanshaw alanshaw deleted the ash/fix/uint-is-ok branch May 16, 2026 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants