feat(cbor): Add BigInteger support with RFC 8949 §3.4.3 compliance#4611
Open
e-thoman wants to merge 7 commits intosmithy-lang:mainfrom
Open
feat(cbor): Add BigInteger support with RFC 8949 §3.4.3 compliance#4611e-thoman wants to merge 7 commits intosmithy-lang:mainfrom
e-thoman wants to merge 7 commits intosmithy-lang:mainfrom
Conversation
Add CBOR encoding and decoding support for BigInteger using CBOR tags 2 (positive bignum) and 3 (negative bignum) as specified by RFC 8949 §3.4.3 and the Smithy RPC v2 CBOR protocol. - Preferred serialization: values fitting in u64/i64 use major types 0/1 instead of bignum tags - Tag 3 correctly encodes -1-n per RFC 8949 - Handle minicbor Int type for major type 1 values exceeding i64 range - Add num-bigint dependency to aws-smithy-cbor - Codegen: BigIntegerShape delegates to decoder.big_integer() / encoder.big_integer() - BigDecimal remains unsupported with CBOR (fails at codegen time) - Comprehensive tests: round-trip, RFC 8949 Appendix A interop, edge cases Resolves: smithy-rs#4473
lauzadis
reviewed
Apr 22, 2026
| @@ -125,6 +125,65 @@ impl Encoder { | |||
| } | |||
|
|
|||
| /// Writes a blob. Collapses header+data into a single reserve+write. | |||
There was a problem hiding this comment.
nit: this comment was accidentally detached from pub fn blob below
|
|
||
| #[test] | ||
| fn big_integer_round_trip_positive() { | ||
| for value in ["0", "1", "23", "256", "65535", "18446744073709551615"] { |
There was a problem hiding this comment.
should we also test round-tripping of positive signed values here? (e.g. +123)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add CBOR encoding and decoding support for BigInteger using CBOR tags 2 (positive bignum) and 3 (negative bignum) as specified by RFC 8949 §3.4.3 and the Smithy RPC v2 CBOR protocol.
Resolves: smithy-rs#4473
Motivation and Context
BigInteger was previously unsupported with the CBOR protocol — attempting to use a
BigIntegerShapein a Smithy model with RPC v2 CBOR would fail at codegen time with aCodegenException.This blocked any service or client that needed arbitrary-precision integers over CBOR. The Smithy RPC v2 CBOR spec requires BigInteger support via CBOR tags 2 and 3 (RFC 8949 §3.4.3), and this
change implements that requirement. See smithy-rs#4473.
Description
Rust runtime (
aws-smithy-cbor):big_integer()toEncoder— writes values using preferred serialization (major type 0/1 for values fitting u64/i64, tags 2/3 for larger values). Tag 3 encodes the byte string asnwhere the value is
-1 - nper RFC 8949.big_integer()toDecoder— reads CBOR tags 2/3 (bignum), plain unsigned/signed integers (major types 0/1), and minicborInttype for major type 1 values exceeding i64 range.num-bigint0.4 dependency for arbitrary-precision integer arithmetic.strip_leading_zeroes()helper for preferred bignum serialization.Codegen (
codegen-core):CborParserGenerator.kt:BigIntegerShapenow emitsdecoder.big_integer()instead of throwingCodegenException.CborSerializerGenerator.kt:BigIntegerShapenow emitsencoder.big_integer()instead of throwingCodegenException.BigDecimalShaperemains unsupported (still throwsCodegenException).Testing
aws-smithy-cborcovering:CodegenExceptionaws-smithy-cbortests passChecklist
.changelogdirectory, specifying "client," "server," or both in theapplies_tokey.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.