🔨 small improvements

parent 037e93f5
...@@ -68,6 +68,10 @@ class binary_reader ...@@ -68,6 +68,10 @@ class binary_reader
switch (format) switch (format)
{ {
case input_format_t::bson:
result = parse_bson_internal();
break;
case input_format_t::cbor: case input_format_t::cbor:
result = parse_cbor_internal(); result = parse_cbor_internal();
break; break;
...@@ -80,10 +84,6 @@ class binary_reader ...@@ -80,10 +84,6 @@ class binary_reader
result = parse_ubjson_internal(); result = parse_ubjson_internal();
break; break;
case input_format_t::bson:
result = parse_bson_internal();
break;
// LCOV_EXCL_START // LCOV_EXCL_START
default: default:
assert(false); assert(false);
...@@ -135,8 +135,8 @@ class binary_reader ...@@ -135,8 +135,8 @@ class binary_reader
*/ */
bool parse_bson_internal() bool parse_bson_internal()
{ {
std::int32_t documentSize; std::int32_t document_size;
get_number<std::int32_t, true>(input_format_t::bson, documentSize); get_number<std::int32_t, true>(input_format_t::bson, document_size);
if (JSON_UNLIKELY(not sax->start_object(std::size_t(-1)))) if (JSON_UNLIKELY(not sax->start_object(std::size_t(-1))))
{ {
...@@ -315,8 +315,8 @@ class binary_reader ...@@ -315,8 +315,8 @@ class binary_reader
*/ */
bool parse_bson_array() bool parse_bson_array()
{ {
std::int32_t documentSize; std::int32_t document_size;
get_number<std::int32_t, true>(input_format_t::bson, documentSize); get_number<std::int32_t, true>(input_format_t::bson, document_size);
if (JSON_UNLIKELY(not sax->start_array(std::size_t(-1)))) if (JSON_UNLIKELY(not sax->start_array(std::size_t(-1))))
{ {
......
...@@ -92,7 +92,7 @@ class input_stream_adapter : public input_adapter_protocol ...@@ -92,7 +92,7 @@ class input_stream_adapter : public input_adapter_protocol
class input_buffer_adapter : public input_adapter_protocol class input_buffer_adapter : public input_adapter_protocol
{ {
public: public:
input_buffer_adapter(const char* b, const std::size_t l) input_buffer_adapter(const char* b, const std::size_t l) noexcept
: cursor(b), limit(b + l) : cursor(b), limit(b + l)
{} {}
...@@ -240,7 +240,9 @@ template<typename WideStringType> ...@@ -240,7 +240,9 @@ template<typename WideStringType>
class wide_string_input_adapter : public input_adapter_protocol class wide_string_input_adapter : public input_adapter_protocol
{ {
public: public:
explicit wide_string_input_adapter(const WideStringType& w) : str(w) {} explicit wide_string_input_adapter(const WideStringType& w) noexcept
: str(w)
{}
std::char_traits<char>::int_type get_character() noexcept override std::char_traits<char>::int_type get_character() noexcept override
{ {
......
...@@ -30,7 +30,9 @@ template<typename CharType> ...@@ -30,7 +30,9 @@ template<typename CharType>
class output_vector_adapter : public output_adapter_protocol<CharType> class output_vector_adapter : public output_adapter_protocol<CharType>
{ {
public: public:
explicit output_vector_adapter(std::vector<CharType>& vec) : v(vec) {} explicit output_vector_adapter(std::vector<CharType>& vec) noexcept
: v(vec)
{}
void write_character(CharType c) override void write_character(CharType c) override
{ {
...@@ -51,7 +53,9 @@ template<typename CharType> ...@@ -51,7 +53,9 @@ template<typename CharType>
class output_stream_adapter : public output_adapter_protocol<CharType> class output_stream_adapter : public output_adapter_protocol<CharType>
{ {
public: public:
explicit output_stream_adapter(std::basic_ostream<CharType>& s) : stream(s) {} explicit output_stream_adapter(std::basic_ostream<CharType>& s) noexcept
: stream(s)
{}
void write_character(CharType c) override void write_character(CharType c) override
{ {
...@@ -72,7 +76,9 @@ template<typename CharType, typename StringType = std::basic_string<CharType>> ...@@ -72,7 +76,9 @@ template<typename CharType, typename StringType = std::basic_string<CharType>>
class output_string_adapter : public output_adapter_protocol<CharType> class output_string_adapter : public output_adapter_protocol<CharType>
{ {
public: public:
explicit output_string_adapter(StringType& s) : str(s) {} explicit output_string_adapter(StringType& s) noexcept
: str(s)
{}
void write_character(CharType c) override void write_character(CharType c) override
{ {
......
This diff is collapsed.
...@@ -37,14 +37,6 @@ TEST_CASE("BSON") ...@@ -37,14 +37,6 @@ TEST_CASE("BSON")
{ {
SECTION("individual values not supported") SECTION("individual values not supported")
{ {
SECTION("discarded")
{
// discarded values are not serialized
json j = json::value_t::discarded;
const auto result = json::to_bson(j);
CHECK(result.empty());
}
SECTION("null") SECTION("null")
{ {
json j = nullptr; json j = nullptr;
...@@ -392,32 +384,6 @@ TEST_CASE("BSON") ...@@ -392,32 +384,6 @@ TEST_CASE("BSON")
CHECK(json::from_bson(result, true, false) == j); CHECK(json::from_bson(result, true, false) == j);
} }
SECTION("discarded values are not serialized")
{
json j = json::value_t::discarded;
const auto result = json::to_bson(j);
CHECK(result.empty());
}
SECTION("discarded members are not serialized")
{
json j =
{
{ "entry", json::value_t::discarded }
};
std::vector<uint8_t> expected =
{
0x05, 0x00, 0x00, 0x00, // size (little endian)
// no entries
0x00 // end marker
};
const auto result = json::to_bson(j);
CHECK(result == expected);
}
SECTION("non-empty object with object member") SECTION("non-empty object with object member")
{ {
json j = json j =
...@@ -1136,7 +1102,7 @@ TEST_CASE("BSON numerical data") ...@@ -1136,7 +1102,7 @@ TEST_CASE("BSON numerical data")
}; };
CHECK_THROWS_AS(json::to_bson(j), json::out_of_range&); CHECK_THROWS_AS(json::to_bson(j), json::out_of_range&);
CHECK_THROWS_WITH(json::to_bson(j), "[json.exception.out_of_range.407] number overflow serializing " + std::to_string(i)); CHECK_THROWS_WITH(json::to_bson(j), "[json.exception.out_of_range.407] integer number " + std::to_string(i) + " cannot be represented by BSON as it does not fit int64");
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment