Skip to content

Control over int encoding #124

Description

@waalge

Is there a way to force the encoder to only use bigint, and always use most compact representation?

The only number I'm handling are ints, and typically using bigint since they may be large.

I want the encoding in JS to be the same as say an implementation in rust, in which int are encoded in the most compact form.

When I try to encode 1n I get

encoder.encode(1n).toString("hex")
// '1b0000000000000001'

But i want it to say 1. I get this helpful for round tripping.

In this case I can convert to Number

encoder.encode(Number(1n)).toString("hex")
//'01'

This is what I want.
However the same does not work for

encoder.encode(Number(-4294967296n)).toString("hex")
//'fbc1f0000000000000'

whereas I would like it to 3AFFFFFFFF

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions