Skip to content

Commit 6b54d47

Browse files
committed
Fix stale CBOR tag docs and add store-mode binary-payload test
The "Incomplete mapping" warning still listed tags 0-5 (date/time, bignum, decimal fraction, bigfloat) and 21-23 (expected conversions) as unsupported, even though they now parse correctly under cbor_tag_handler_t::ignore/store, same as 0xC6..0xD4/0xD8..0xDB. Remove those five bullets and cross-reference the "Tagged items" warning below, matching the equivalent docs fix landed independently in PR #5367. Also add a cbor_tag_handler_t::store test that wraps a binary payload (not just a string) for every byte in 0xC0..0xD7, confirming these tags are unwrapped the same way as 0xC6..0xD4 rather than mistaken for the 0xD8..0xDB binary-subtype marker syntax, per review feedback on #5331. Signed-off-by: sahilkamate03 <45514385+sahilkamate03@users.noreply.github.com>
1 parent 9c1bf19 commit 6b54d47

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

docs/mkdocs/docs/features/binary_formats/cbor.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,11 @@ The library maps CBOR types to JSON value types as follows:
160160

161161
The mapping is **incomplete** in the sense that not all CBOR types can be converted to a JSON value. The following CBOR types are not supported and will yield parse errors:
162162

163-
- date/time (0xC0..0xC1)
164-
- bignum (0xC2..0xC3)
165-
- decimal fraction (0xC4)
166-
- bigfloat (0xC5)
167-
- expected conversions (0xD5..0xD7)
168163
- simple values (0xE0..0xF3, 0xF8)
169164
- undefined (0xF7)
170165

166+
Tagged items (0xC0..0xDB) are not interpreted either; see the note on tagged items below.
167+
171168
!!! warning "Negative integer overflow"
172169

173170
CBOR negative integers (major type 1) are decoded as `-1 - n`. If the encoded magnitude `n` is too large for the
@@ -181,7 +178,7 @@ The library maps CBOR types to JSON value types as follows:
181178

182179
!!! warning "Tagged items"
183180

184-
Tagged items (`0xC0`..`0xDB`) will throw a parse error by default. They can be ignored by passing `cbor_tag_handler_t::ignore` to function `from_cbor`. They can be stored by passing `cbor_tag_handler_t::store` to function `from_cbor`.
181+
Tagged items (0xC0..0xDB) will throw a parse error by default. They can be ignored by passing `cbor_tag_handler_t::ignore` to function `from_cbor`, in which case the tag is skipped and the enclosed data item is parsed on its own. They can be stored by passing `cbor_tag_handler_t::store` to function `from_cbor`. Note that no tag is ever interpreted: for instance, a text string tagged with tag 0 (date/time) stays a string.
185182

186183
??? example
187184

tests/src/unit-cbor.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2565,6 +2565,9 @@ TEST_CASE("Tagged values")
25652565
const json j = "s";
25662566
auto v = json::to_cbor(j);
25672567

2568+
const json j_bin_payload = json::binary(std::vector<std::uint8_t> {0x01, 0x02, 0x03});
2569+
auto v_bin_payload = json::to_cbor(j_bin_payload);
2570+
25682571
SECTION("0xC0..0xD7")
25692572
{
25702573
for (const auto b : std::vector<std::uint8_t>
@@ -2591,6 +2594,12 @@ TEST_CASE("Tagged values")
25912594

25922595
auto j_tagged_stored = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::store);
25932596
CHECK(j_tagged_stored == j);
2597+
2598+
auto v_binary_tagged = v_bin_payload;
2599+
v_binary_tagged.insert(v_binary_tagged.begin(), b);
2600+
auto j_binary_tagged_stored = json::from_cbor(v_binary_tagged, true, true, json::cbor_tag_handler_t::store);
2601+
CHECK(j_binary_tagged_stored == j_bin_payload);
2602+
CHECK(!j_binary_tagged_stored.get_binary().has_subtype());
25942603
}
25952604
}
25962605

0 commit comments

Comments
 (0)