Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 2 more options for decoding CBOR integers to interface{} #457

Merged
merged 1 commit into from
Dec 28, 2023

Conversation

fxamacker
Copy link
Owner

@fxamacker fxamacker commented Dec 28, 2023

Closes #438

Added 2 new decoding options to IntDecMode which specifies how to decode CBOR integers (major type 0 and 1) to Go interface{}.

  • IntDecConvertSignedOrFail makes CBOR integers decode to:

    • int64 if value fits
    • return UnmarshalTypeError if value doesn't fit into int64
  • IntDecConvertSignedOrBigInt makes CBOR integers decode:

    • int64 if value fits
    • big.Int or *big.Int if value doesn't fit into int64

Including IntDecConvertNone (default setting), there are now 4 options for decoding CBOR unsigned or CBOR negative integers into interface{}.

Deprecated IntDecConvertSigned option in favor of other options for more consistent handling of values that don't git into int64.

Also updated comments for existing IntDecMode options.

Default behavior is unchanged to maintain backward compatibility.

decode.go Outdated Show resolved Hide resolved
decode.go Outdated Show resolved Hide resolved
decode.go Outdated Show resolved Hide resolved
Copy link
Contributor

@x448 x448 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic! Found a few nits about grammar in code comments.

Added 2 new decoding options to IntDecMode which specifies how to
decode CBOR integers (major type 0 and 1) to Go interface{}.

- IntDecConvertSignedOrFail makes CBOR integers decode to:
  * int64 if value fits
  * return UnmarshalTypeError if value doesn't fit into int64

- IntDecConvertSignedOrBigInt makes CBOR integers decode:
  * int64 if value fits
  * big.Int or *big.Int if value doesn't fit into int64

Including default setting (IntDecConvertNone), there are
now 4 options for decoding CBOR unsigned or CBOR negative
integers into interface{}.

Deprecated IntDecConvertSigned option in favor of other options
for more consistent handling of values that don't git into int64.

Also updated comments for existing IntDecMode options.
@fxamacker fxamacker force-pushed the fxamacker/add-option-to-IntDecMode branch from 863358d to b5a6ef0 Compare December 28, 2023 20:49
@fxamacker fxamacker merged commit 0e952c7 into master Dec 28, 2023
17 checks passed
@fxamacker fxamacker deleted the fxamacker/add-option-to-IntDecMode branch December 28, 2023 21:18
@fxamacker fxamacker added this to the v2.6.0 milestone Dec 29, 2023
@fxamacker fxamacker changed the title Add 2 more options for decoding CBOR integers to any Add 2 more options for decoding CBOR integers to interface{} Dec 29, 2023
@fxamacker fxamacker added the enhancement New feature or request label Dec 29, 2023
@extemporalgenome
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature: IntDecMode value for int64 with overflow to *big.Int
3 participants