fxamacker / cbor

CBOR codec (RFC 8949) with CBOR tags, Go struct tags (toarray, keyasint, omitempty), float64/32/16, big.Int, and fuzz tested billions of execs.
MIT License
733 stars 60 forks source link

feature: `IntDecMode` value for `int64` with overflow to `*big.Int` #438

Closed extemporalgenome closed 10 months ago

extemporalgenome commented 12 months ago

Is your feature request related to a problem? Please describe.

The duality of decoding into int64/uint64 when given an empty interface has great affinity to the CBOR data model, but in applications that predominantly model integers as int64, yet still want access to arbitrary precision integers, IntDecConvertSigned still leaves an awkward gap (at least from what I can infer from the documentation):

Describe the solution you'd like

An additional IntDecMode which behaves like IntDecConvertSigned, except that in any case where overflowing values yield an UnmarshalTypeError, they instead succeed with a *big.Int.

Describe alternatives you've considered

fxamacker commented 11 months ago

Thanks for the great write-up. I like your suggested solution and will resolve this issue in the next release.

The first alternative is also appealing but I'm reluctant to risk breaking compatibility (unless it is to fix conformance to RFC 8949).

extemporalgenome commented 9 months ago

Thanks!