1
0
mirror of https://github.com/nlohmann/json.git synced 2025-07-28 12:02:00 +03:00

🚧 some changes to the BSON code

- added fuzz testers
- added some reference files
- made an exception text more clear
This commit is contained in:
Niels Lohmann
2018-10-24 15:43:37 +02:00
parent bba159121f
commit e2c5913a50
13 changed files with 218 additions and 32 deletions

View File

@ -553,13 +553,13 @@ struct is_constructible_object_type_impl <
static constexpr bool value =
std::is_constructible<typename ConstructibleObjectType::key_type,
typename object_t::key_type>::value and
std::is_same<typename object_t::mapped_type,
typename ConstructibleObjectType::mapped_type>::value or
(has_from_json<BasicJsonType,
(std::is_same<typename object_t::mapped_type,
typename ConstructibleObjectType::mapped_type>::value or
has_non_default_from_json <
BasicJsonType,
typename ConstructibleObjectType::mapped_type >::value);
(has_from_json<BasicJsonType,
typename ConstructibleObjectType::mapped_type>::value or
has_non_default_from_json <
BasicJsonType,
typename ConstructibleObjectType::mapped_type >::value));
};
template <typename BasicJsonType, typename ConstructibleObjectType>
@ -9234,14 +9234,22 @@ class binary_writer
{
switch (j.type())
{
default:
JSON_THROW(type_error::create(317, "JSON value of type " + std::to_string(static_cast<std::uint8_t>(j.type())) + " cannot be serialized to requested format"));
break;
case value_t::discarded:
break;
case value_t::object:
{
write_bson_object(*j.m_value.object);
break;
}
case value_t::discarded:
{
break;
}
default:
{
JSON_THROW(type_error::create(317, "to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name())));
break;
}
}
}
@ -9267,7 +9275,7 @@ class binary_writer
std::memcpy(vec.data(), &n, sizeof(NumberType));
// step 2: write array to output (with possible reordering)
if (is_little_endian && !OutputIsLittleEndian)
if (is_little_endian and not OutputIsLittleEndian)
{
// reverse byte order prior to conversion if necessary
std::reverse(vec.begin(), vec.end());