mirror of
https://github.com/nlohmann/json.git
synced 2025-07-28 12:02:00 +03:00
✨ add option to process binary subtypes in CBOR
This commit is contained in:
@ -8269,8 +8269,9 @@ namespace detail
|
||||
/// how to treat CBOR tags
|
||||
enum class cbor_tag_handler_t
|
||||
{
|
||||
error, ///< throw a parse_error exception in case of a tag
|
||||
ignore ///< ignore tags
|
||||
error, ///< throw a parse_error exception in case of a tag
|
||||
ignore, ///< ignore tags
|
||||
store ///< store tags as binary type
|
||||
};
|
||||
|
||||
/*!
|
||||
@ -8961,30 +8962,31 @@ class binary_reader
|
||||
|
||||
case cbor_tag_handler_t::ignore:
|
||||
{
|
||||
// ignore binary subtype
|
||||
switch (current)
|
||||
{
|
||||
case 0xD8:
|
||||
{
|
||||
std::uint8_t len{};
|
||||
get_number(input_format_t::cbor, len);
|
||||
std::uint8_t subtype_to_ignore{};
|
||||
get_number(input_format_t::cbor, subtype_to_ignore);
|
||||
break;
|
||||
}
|
||||
case 0xD9:
|
||||
{
|
||||
std::uint16_t len{};
|
||||
get_number(input_format_t::cbor, len);
|
||||
std::uint16_t subtype_to_ignore{};
|
||||
get_number(input_format_t::cbor, subtype_to_ignore);
|
||||
break;
|
||||
}
|
||||
case 0xDA:
|
||||
{
|
||||
std::uint32_t len{};
|
||||
get_number(input_format_t::cbor, len);
|
||||
std::uint32_t subtype_to_ignore{};
|
||||
get_number(input_format_t::cbor, subtype_to_ignore);
|
||||
break;
|
||||
}
|
||||
case 0xDB:
|
||||
{
|
||||
std::uint64_t len{};
|
||||
get_number(input_format_t::cbor, len);
|
||||
std::uint64_t subtype_to_ignore{};
|
||||
get_number(input_format_t::cbor, subtype_to_ignore);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -8993,6 +8995,47 @@ class binary_reader
|
||||
return parse_cbor_internal(true, tag_handler);
|
||||
}
|
||||
|
||||
case cbor_tag_handler_t::store:
|
||||
{
|
||||
binary_t b;
|
||||
// use binary subtype and store in binary container
|
||||
switch (current)
|
||||
{
|
||||
case 0xD8:
|
||||
{
|
||||
std::uint8_t subtype{};
|
||||
get_number(input_format_t::cbor, subtype);
|
||||
b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
|
||||
break;
|
||||
}
|
||||
case 0xD9:
|
||||
{
|
||||
std::uint16_t subtype{};
|
||||
get_number(input_format_t::cbor, subtype);
|
||||
b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
|
||||
break;
|
||||
}
|
||||
case 0xDA:
|
||||
{
|
||||
std::uint32_t subtype{};
|
||||
get_number(input_format_t::cbor, subtype);
|
||||
b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
|
||||
break;
|
||||
}
|
||||
case 0xDB:
|
||||
{
|
||||
std::uint64_t subtype{};
|
||||
get_number(input_format_t::cbor, subtype);
|
||||
b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
get();
|
||||
return get_cbor_binary(b) && sax->binary(b);
|
||||
}
|
||||
|
||||
default: // LCOV_EXCL_LINE
|
||||
JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
|
||||
return false; // LCOV_EXCL_LINE
|
||||
|
Reference in New Issue
Block a user