diff --git a/include/nlohmann/detail/output/serializer.hpp b/include/nlohmann/detail/output/serializer.hpp index ed20b0d9e1..690aa58d5e 100644 --- a/include/nlohmann/detail/output/serializer.hpp +++ b/include/nlohmann/detail/output/serializer.hpp @@ -104,272 +104,320 @@ class serializer @param[in] indent_step the indent level @param[in] current_indent the current indent level (only used internally) */ - void dump(const BasicJsonType& val, + void dump(const BasicJsonType& start_val, const bool pretty_print, const bool ensure_ascii, const unsigned int indent_step, - const unsigned int current_indent = 0) + const unsigned int start_indent = 0) { - switch (val.m_data.m_type) + struct dump_state { - case value_t::object: - { - if (val.m_data.m_value.object->empty()) - { - o->write_characters("{}", 2); - return; - } + const BasicJsonType& val; + const unsigned int new_indent; + const unsigned int offset; + const decltype(start_val.m_data.m_value.object->cbegin()) iterator; + }; + std::vector stack; + stack.push_back({start_val, start_indent, 0}); - if (pretty_print) + while (!stack.empty()) + { + const dump_state& state = stack.back(); + const BasicJsonType& val = state.val; + const unsigned int current_indent = state.new_indent; + const unsigned int offset = state.offset; + auto iterator = state.iterator; + stack.pop_back(); + + switch (val.m_data.m_type) + { + case value_t::object: { - o->write_characters("{\n", 2); - - // variable to hold indentation for recursive calls - const auto new_indent = current_indent + indent_step; - if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent)) + if (val.m_data.m_value.object->empty()) { - indent_string.resize(indent_string.size() * 2, ' '); + o->write_characters("{}", 2); + continue; } - // first n-1 elements - auto i = val.m_data.m_value.object->cbegin(); - for (std::size_t cnt = 0; cnt < val.m_data.m_value.object->size() - 1; ++cnt, ++i) + if (pretty_print) { - o->write_characters(indent_string.c_str(), new_indent); - o->write_character('\"'); - dump_escaped(i->first, ensure_ascii); - o->write_characters("\": ", 3); - dump(i->second, true, ensure_ascii, indent_step, new_indent); - o->write_characters(",\n", 2); - } - - // last element - JSON_ASSERT(i != val.m_data.m_value.object->cend()); - JSON_ASSERT(std::next(i) == val.m_data.m_value.object->cend()); - o->write_characters(indent_string.c_str(), new_indent); - o->write_character('\"'); - dump_escaped(i->first, ensure_ascii); - o->write_characters("\": ", 3); - dump(i->second, true, ensure_ascii, indent_step, new_indent); + // variable to hold indentation for recursive calls + unsigned int new_indent = current_indent; + auto i = val.m_data.m_value.object->cbegin(); + if (offset == 0) + { + o->write_characters("{\n", 2); - o->write_character('\n'); - o->write_characters(indent_string.c_str(), current_indent); - o->write_character('}'); - } - else - { - o->write_character('{'); + new_indent = current_indent + indent_step; + if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent)) + { + indent_string.resize(indent_string.size() * 2, ' '); + } + } + else if (offset < val.m_data.m_value.object->size()) + { + o->write_characters(",\n", 2); + i = iterator; + } - // first n-1 elements - auto i = val.m_data.m_value.object->cbegin(); - for (std::size_t cnt = 0; cnt < val.m_data.m_value.object->size() - 1; ++cnt, ++i) - { - o->write_character('\"'); - dump_escaped(i->first, ensure_ascii); - o->write_characters("\":", 2); - dump(i->second, false, ensure_ascii, indent_step, current_indent); - o->write_character(','); + // first n-1 elements + if (offset < val.m_data.m_value.object->size() - 1) + { + o->write_characters(indent_string.c_str(), new_indent); + o->write_character('\"'); + dump_escaped(i->first, ensure_ascii); + o->write_characters("\": ", 3); + stack.push_back({.val = val, .new_indent = new_indent, .offset = offset + 1, .iterator = std::next(i)}); + stack.push_back({.val = i->second, .new_indent = new_indent, .offset = 0}); + continue; + } + else if (offset < val.m_data.m_value.object->size()) + { + // last element + JSON_ASSERT(i != val.m_data.m_value.object->cend()); + JSON_ASSERT(std::next(i) == val.m_data.m_value.object->cend()); + o->write_characters(indent_string.c_str(), new_indent); + o->write_character('\"'); + dump_escaped(i->first, ensure_ascii); + o->write_characters("\": ", 3); + stack.push_back({.val = val, .new_indent = new_indent, .offset = offset + 1, .iterator = std::next(i)}); + stack.push_back({.val = i->second, .new_indent = new_indent, .offset = 0}); + continue; + } + else + { + o->write_character('\n'); + o->write_characters(indent_string.c_str(), new_indent - indent_step); + o->write_character('}'); + } } + else + { + auto i = val.m_data.m_value.object->cbegin(); + if (offset == 0) + { + o->write_character('{'); + } + else if (offset < val.m_data.m_value.object->size()) + { + i = iterator; + o->write_character(','); + } - // last element - JSON_ASSERT(i != val.m_data.m_value.object->cend()); - JSON_ASSERT(std::next(i) == val.m_data.m_value.object->cend()); - o->write_character('\"'); - dump_escaped(i->first, ensure_ascii); - o->write_characters("\":", 2); - dump(i->second, false, ensure_ascii, indent_step, current_indent); - - o->write_character('}'); - } - - return; - } + if (offset < val.m_data.m_value.object->size()) + { + o->write_character('\"'); + dump_escaped(i->first, ensure_ascii); + o->write_characters("\":", 2); + stack.push_back({.val = val, .new_indent = current_indent, .offset = offset + 1, .iterator = std::next(i)}); + stack.push_back({.val = i->second, .new_indent = current_indent, .offset = 0}); + continue; + } + else + { + o->write_character('}'); + } + } - case value_t::array: - { - if (val.m_data.m_value.array->empty()) - { - o->write_characters("[]", 2); - return; + continue; } - if (pretty_print) + case value_t::array: { - o->write_characters("[\n", 2); - - // variable to hold indentation for recursive calls - const auto new_indent = current_indent + indent_step; - if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent)) + if (val.m_data.m_value.array->empty()) { - indent_string.resize(indent_string.size() * 2, ' '); + o->write_characters("[]", 2); + continue; } - // first n-1 elements - for (auto i = val.m_data.m_value.array->cbegin(); - i != val.m_data.m_value.array->cend() - 1; ++i) + if (pretty_print) { - o->write_characters(indent_string.c_str(), new_indent); - dump(*i, true, ensure_ascii, indent_step, new_indent); - o->write_characters(",\n", 2); - } - - // last element - JSON_ASSERT(!val.m_data.m_value.array->empty()); - o->write_characters(indent_string.c_str(), new_indent); - dump(val.m_data.m_value.array->back(), true, ensure_ascii, indent_step, new_indent); + // variable to hold indentation for recursive calls + unsigned int new_indent = current_indent; + if (offset == 0) + { + o->write_characters("[\n", 2); - o->write_character('\n'); - o->write_characters(indent_string.c_str(), current_indent); - o->write_character(']'); - } - else - { - o->write_character('['); + new_indent = current_indent + indent_step; + if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent)) + { + indent_string.resize(indent_string.size() * 2, ' '); + } + } + else if (offset < val.m_data.m_value.array->size()) + { + o->write_characters(",\n", 2); + } - // first n-1 elements - for (auto i = val.m_data.m_value.array->cbegin(); - i != val.m_data.m_value.array->cend() - 1; ++i) - { - dump(*i, false, ensure_ascii, indent_step, current_indent); - o->write_character(','); + if (offset < val.m_data.m_value.array->size()) + { + o->write_characters(indent_string.c_str(), new_indent); + stack.push_back({.val = val, .new_indent = new_indent, .offset = offset + 1}); + stack.push_back({.val = (*val.m_data.m_value.array)[offset], .new_indent = new_indent, .offset = 0}); + continue; + } + else + { + o->write_character('\n'); + o->write_characters(indent_string.c_str(), new_indent - indent_step); + o->write_character(']'); + } } + else + { + if (offset == 0) + { + o->write_character('['); + } + else if (offset < val.m_data.m_value.array->size()) + { + o->write_character(','); + } + if (offset < val.m_data.m_value.array->size()) + { + stack.push_back({.val = val, .new_indent = current_indent, .offset = offset + 1}); - // last element - JSON_ASSERT(!val.m_data.m_value.array->empty()); - dump(val.m_data.m_value.array->back(), false, ensure_ascii, indent_step, current_indent); + stack.push_back({.val = (*val.m_data.m_value.array)[offset], .new_indent = current_indent, .offset = 0}); + continue; + } + else + { + o->write_character(']'); + } + } - o->write_character(']'); + continue; } - return; - } - - case value_t::string: - { - o->write_character('\"'); - dump_escaped(*val.m_data.m_value.string, ensure_ascii); - o->write_character('\"'); - return; - } - - case value_t::binary: - { - if (pretty_print) + case value_t::string: { - o->write_characters("{\n", 2); + o->write_character('\"'); + dump_escaped(*val.m_data.m_value.string, ensure_ascii); + o->write_character('\"'); + continue; + } - // variable to hold indentation for recursive calls - const auto new_indent = current_indent + indent_step; - if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent)) + case value_t::binary: + { + if (pretty_print) { - indent_string.resize(indent_string.size() * 2, ' '); - } + o->write_characters("{\n", 2); - o->write_characters(indent_string.c_str(), new_indent); + // variable to hold indentation for recursive calls + const auto new_indent = current_indent + indent_step; + if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent)) + { + indent_string.resize(indent_string.size() * 2, ' '); + } - o->write_characters("\"bytes\": [", 10); + o->write_characters(indent_string.c_str(), new_indent); - if (!val.m_data.m_value.binary->empty()) - { - for (auto i = val.m_data.m_value.binary->cbegin(); - i != val.m_data.m_value.binary->cend() - 1; ++i) + o->write_characters("\"bytes\": [", 10); + + if (!val.m_data.m_value.binary->empty()) { - dump_integer(*i); - o->write_characters(", ", 2); + for (auto i = val.m_data.m_value.binary->cbegin(); + i != val.m_data.m_value.binary->cend() - 1; + ++i) + { + dump_integer(*i); + o->write_characters(", ", 2); + } + dump_integer(val.m_data.m_value.binary->back()); } - dump_integer(val.m_data.m_value.binary->back()); - } - o->write_characters("],\n", 3); - o->write_characters(indent_string.c_str(), new_indent); + o->write_characters("],\n", 3); + o->write_characters(indent_string.c_str(), new_indent); - o->write_characters("\"subtype\": ", 11); - if (val.m_data.m_value.binary->has_subtype()) - { - dump_integer(val.m_data.m_value.binary->subtype()); + o->write_characters("\"subtype\": ", 11); + if (val.m_data.m_value.binary->has_subtype()) + { + dump_integer(val.m_data.m_value.binary->subtype()); + } + else + { + o->write_characters("null", 4); + } + o->write_character('\n'); + o->write_characters(indent_string.c_str(), current_indent); + o->write_character('}'); } else { - o->write_characters("null", 4); - } - o->write_character('\n'); - o->write_characters(indent_string.c_str(), current_indent); - o->write_character('}'); - } - else - { - o->write_characters("{\"bytes\":[", 10); + o->write_characters("{\"bytes\":[", 10); - if (!val.m_data.m_value.binary->empty()) - { - for (auto i = val.m_data.m_value.binary->cbegin(); - i != val.m_data.m_value.binary->cend() - 1; ++i) + if (!val.m_data.m_value.binary->empty()) { - dump_integer(*i); - o->write_character(','); + for (auto i = val.m_data.m_value.binary->cbegin(); + i != val.m_data.m_value.binary->cend() - 1; + ++i) + { + dump_integer(*i); + o->write_character(','); + } + dump_integer(val.m_data.m_value.binary->back()); + } + + o->write_characters("],\"subtype\":", 12); + if (val.m_data.m_value.binary->has_subtype()) + { + dump_integer(val.m_data.m_value.binary->subtype()); + o->write_character('}'); + } + else + { + o->write_characters("null}", 5); } - dump_integer(val.m_data.m_value.binary->back()); } + continue; + } - o->write_characters("],\"subtype\":", 12); - if (val.m_data.m_value.binary->has_subtype()) + case value_t::boolean: + { + if (val.m_data.m_value.boolean) { - dump_integer(val.m_data.m_value.binary->subtype()); - o->write_character('}'); + o->write_characters("true", 4); } else { - o->write_characters("null}", 5); + o->write_characters("false", 5); } + continue; } - return; - } - case value_t::boolean: - { - if (val.m_data.m_value.boolean) + case value_t::number_integer: { - o->write_characters("true", 4); + dump_integer(val.m_data.m_value.number_integer); + continue; } - else + + case value_t::number_unsigned: { - o->write_characters("false", 5); + dump_integer(val.m_data.m_value.number_unsigned); + continue; } - return; - } - - case value_t::number_integer: - { - dump_integer(val.m_data.m_value.number_integer); - return; - } - case value_t::number_unsigned: - { - dump_integer(val.m_data.m_value.number_unsigned); - return; - } + case value_t::number_float: + { + dump_float(val.m_data.m_value.number_float); + continue; + } - case value_t::number_float: - { - dump_float(val.m_data.m_value.number_float); - return; - } + case value_t::discarded: + { + o->write_characters("", 11); + continue; + } - case value_t::discarded: - { - o->write_characters("", 11); - return; - } + case value_t::null: + { + o->write_characters("null", 4); + continue; + } - case value_t::null: - { - o->write_characters("null", 4); - return; + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE } - - default: // LCOV_EXCL_LINE - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE } } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index a858728c4c..8da6293133 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -18113,272 +18113,320 @@ class serializer @param[in] indent_step the indent level @param[in] current_indent the current indent level (only used internally) */ - void dump(const BasicJsonType& val, + void dump(const BasicJsonType& start_val, const bool pretty_print, const bool ensure_ascii, const unsigned int indent_step, - const unsigned int current_indent = 0) + const unsigned int start_indent = 0) { - switch (val.m_data.m_type) + struct dump_state { - case value_t::object: - { - if (val.m_data.m_value.object->empty()) - { - o->write_characters("{}", 2); - return; - } + const BasicJsonType& val; + const unsigned int new_indent; + const unsigned int offset; + const decltype(start_val.m_data.m_value.object->cbegin()) iterator; + }; + std::vector stack; + stack.push_back({start_val, start_indent, 0}); - if (pretty_print) - { - o->write_characters("{\n", 2); + while (!stack.empty()) + { + const dump_state& state = stack.back(); + const BasicJsonType& val = state.val; + const unsigned int current_indent = state.new_indent; + const unsigned int offset = state.offset; + auto iterator = state.iterator; + stack.pop_back(); - // variable to hold indentation for recursive calls - const auto new_indent = current_indent + indent_step; - if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent)) + switch (val.m_data.m_type) + { + case value_t::object: + { + if (val.m_data.m_value.object->empty()) { - indent_string.resize(indent_string.size() * 2, ' '); + o->write_characters("{}", 2); + continue; } - // first n-1 elements - auto i = val.m_data.m_value.object->cbegin(); - for (std::size_t cnt = 0; cnt < val.m_data.m_value.object->size() - 1; ++cnt, ++i) + if (pretty_print) { - o->write_characters(indent_string.c_str(), new_indent); - o->write_character('\"'); - dump_escaped(i->first, ensure_ascii); - o->write_characters("\": ", 3); - dump(i->second, true, ensure_ascii, indent_step, new_indent); - o->write_characters(",\n", 2); - } - - // last element - JSON_ASSERT(i != val.m_data.m_value.object->cend()); - JSON_ASSERT(std::next(i) == val.m_data.m_value.object->cend()); - o->write_characters(indent_string.c_str(), new_indent); - o->write_character('\"'); - dump_escaped(i->first, ensure_ascii); - o->write_characters("\": ", 3); - dump(i->second, true, ensure_ascii, indent_step, new_indent); + // variable to hold indentation for recursive calls + unsigned int new_indent = current_indent; + auto i = val.m_data.m_value.object->cbegin(); + if (offset == 0) + { + o->write_characters("{\n", 2); - o->write_character('\n'); - o->write_characters(indent_string.c_str(), current_indent); - o->write_character('}'); - } - else - { - o->write_character('{'); + new_indent = current_indent + indent_step; + if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent)) + { + indent_string.resize(indent_string.size() * 2, ' '); + } + } + else if (offset < val.m_data.m_value.object->size()) + { + o->write_characters(",\n", 2); + i = iterator; + } - // first n-1 elements - auto i = val.m_data.m_value.object->cbegin(); - for (std::size_t cnt = 0; cnt < val.m_data.m_value.object->size() - 1; ++cnt, ++i) - { - o->write_character('\"'); - dump_escaped(i->first, ensure_ascii); - o->write_characters("\":", 2); - dump(i->second, false, ensure_ascii, indent_step, current_indent); - o->write_character(','); + // first n-1 elements + if (offset < val.m_data.m_value.object->size() - 1) + { + o->write_characters(indent_string.c_str(), new_indent); + o->write_character('\"'); + dump_escaped(i->first, ensure_ascii); + o->write_characters("\": ", 3); + stack.push_back({.val = val, .new_indent = new_indent, .offset = offset + 1, .iterator = std::next(i)}); + stack.push_back({.val = i->second, .new_indent = new_indent, .offset = 0}); + continue; + } + else if (offset < val.m_data.m_value.object->size()) + { + // last element + JSON_ASSERT(i != val.m_data.m_value.object->cend()); + JSON_ASSERT(std::next(i) == val.m_data.m_value.object->cend()); + o->write_characters(indent_string.c_str(), new_indent); + o->write_character('\"'); + dump_escaped(i->first, ensure_ascii); + o->write_characters("\": ", 3); + stack.push_back({.val = val, .new_indent = new_indent, .offset = offset + 1, .iterator = std::next(i)}); + stack.push_back({.val = i->second, .new_indent = new_indent, .offset = 0}); + continue; + } + else + { + o->write_character('\n'); + o->write_characters(indent_string.c_str(), new_indent - indent_step); + o->write_character('}'); + } } + else + { + auto i = val.m_data.m_value.object->cbegin(); + if (offset == 0) + { + o->write_character('{'); + } + else if (offset < val.m_data.m_value.object->size()) + { + i = iterator; + o->write_character(','); + } - // last element - JSON_ASSERT(i != val.m_data.m_value.object->cend()); - JSON_ASSERT(std::next(i) == val.m_data.m_value.object->cend()); - o->write_character('\"'); - dump_escaped(i->first, ensure_ascii); - o->write_characters("\":", 2); - dump(i->second, false, ensure_ascii, indent_step, current_indent); - - o->write_character('}'); - } - - return; - } + if (offset < val.m_data.m_value.object->size()) + { + o->write_character('\"'); + dump_escaped(i->first, ensure_ascii); + o->write_characters("\":", 2); + stack.push_back({.val = val, .new_indent = current_indent, .offset = offset + 1, .iterator = std::next(i)}); + stack.push_back({.val = i->second, .new_indent = current_indent, .offset = 0}); + continue; + } + else + { + o->write_character('}'); + } + } - case value_t::array: - { - if (val.m_data.m_value.array->empty()) - { - o->write_characters("[]", 2); - return; + continue; } - if (pretty_print) + case value_t::array: { - o->write_characters("[\n", 2); - - // variable to hold indentation for recursive calls - const auto new_indent = current_indent + indent_step; - if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent)) + if (val.m_data.m_value.array->empty()) { - indent_string.resize(indent_string.size() * 2, ' '); + o->write_characters("[]", 2); + continue; } - // first n-1 elements - for (auto i = val.m_data.m_value.array->cbegin(); - i != val.m_data.m_value.array->cend() - 1; ++i) + if (pretty_print) { - o->write_characters(indent_string.c_str(), new_indent); - dump(*i, true, ensure_ascii, indent_step, new_indent); - o->write_characters(",\n", 2); - } - - // last element - JSON_ASSERT(!val.m_data.m_value.array->empty()); - o->write_characters(indent_string.c_str(), new_indent); - dump(val.m_data.m_value.array->back(), true, ensure_ascii, indent_step, new_indent); + // variable to hold indentation for recursive calls + unsigned int new_indent = current_indent; + if (offset == 0) + { + o->write_characters("[\n", 2); - o->write_character('\n'); - o->write_characters(indent_string.c_str(), current_indent); - o->write_character(']'); - } - else - { - o->write_character('['); + new_indent = current_indent + indent_step; + if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent)) + { + indent_string.resize(indent_string.size() * 2, ' '); + } + } + else if (offset < val.m_data.m_value.array->size()) + { + o->write_characters(",\n", 2); + } - // first n-1 elements - for (auto i = val.m_data.m_value.array->cbegin(); - i != val.m_data.m_value.array->cend() - 1; ++i) - { - dump(*i, false, ensure_ascii, indent_step, current_indent); - o->write_character(','); + if (offset < val.m_data.m_value.array->size()) + { + o->write_characters(indent_string.c_str(), new_indent); + stack.push_back({.val = val, .new_indent = new_indent, .offset = offset + 1}); + stack.push_back({.val = (*val.m_data.m_value.array)[offset], .new_indent = new_indent, .offset = 0}); + continue; + } + else + { + o->write_character('\n'); + o->write_characters(indent_string.c_str(), new_indent - indent_step); + o->write_character(']'); + } } + else + { + if (offset == 0) + { + o->write_character('['); + } + else if (offset < val.m_data.m_value.array->size()) + { + o->write_character(','); + } + if (offset < val.m_data.m_value.array->size()) + { + stack.push_back({.val = val, .new_indent = current_indent, .offset = offset + 1}); - // last element - JSON_ASSERT(!val.m_data.m_value.array->empty()); - dump(val.m_data.m_value.array->back(), false, ensure_ascii, indent_step, current_indent); + stack.push_back({.val = (*val.m_data.m_value.array)[offset], .new_indent = current_indent, .offset = 0}); + continue; + } + else + { + o->write_character(']'); + } + } - o->write_character(']'); + continue; } - return; - } - - case value_t::string: - { - o->write_character('\"'); - dump_escaped(*val.m_data.m_value.string, ensure_ascii); - o->write_character('\"'); - return; - } - - case value_t::binary: - { - if (pretty_print) + case value_t::string: { - o->write_characters("{\n", 2); + o->write_character('\"'); + dump_escaped(*val.m_data.m_value.string, ensure_ascii); + o->write_character('\"'); + continue; + } - // variable to hold indentation for recursive calls - const auto new_indent = current_indent + indent_step; - if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent)) + case value_t::binary: + { + if (pretty_print) { - indent_string.resize(indent_string.size() * 2, ' '); - } + o->write_characters("{\n", 2); + + // variable to hold indentation for recursive calls + const auto new_indent = current_indent + indent_step; + if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent)) + { + indent_string.resize(indent_string.size() * 2, ' '); + } - o->write_characters(indent_string.c_str(), new_indent); + o->write_characters(indent_string.c_str(), new_indent); - o->write_characters("\"bytes\": [", 10); + o->write_characters("\"bytes\": [", 10); - if (!val.m_data.m_value.binary->empty()) - { - for (auto i = val.m_data.m_value.binary->cbegin(); - i != val.m_data.m_value.binary->cend() - 1; ++i) + if (!val.m_data.m_value.binary->empty()) { - dump_integer(*i); - o->write_characters(", ", 2); + for (auto i = val.m_data.m_value.binary->cbegin(); + i != val.m_data.m_value.binary->cend() - 1; + ++i) + { + dump_integer(*i); + o->write_characters(", ", 2); + } + dump_integer(val.m_data.m_value.binary->back()); } - dump_integer(val.m_data.m_value.binary->back()); - } - o->write_characters("],\n", 3); - o->write_characters(indent_string.c_str(), new_indent); + o->write_characters("],\n", 3); + o->write_characters(indent_string.c_str(), new_indent); - o->write_characters("\"subtype\": ", 11); - if (val.m_data.m_value.binary->has_subtype()) - { - dump_integer(val.m_data.m_value.binary->subtype()); + o->write_characters("\"subtype\": ", 11); + if (val.m_data.m_value.binary->has_subtype()) + { + dump_integer(val.m_data.m_value.binary->subtype()); + } + else + { + o->write_characters("null", 4); + } + o->write_character('\n'); + o->write_characters(indent_string.c_str(), current_indent); + o->write_character('}'); } else { - o->write_characters("null", 4); - } - o->write_character('\n'); - o->write_characters(indent_string.c_str(), current_indent); - o->write_character('}'); - } - else - { - o->write_characters("{\"bytes\":[", 10); + o->write_characters("{\"bytes\":[", 10); - if (!val.m_data.m_value.binary->empty()) - { - for (auto i = val.m_data.m_value.binary->cbegin(); - i != val.m_data.m_value.binary->cend() - 1; ++i) + if (!val.m_data.m_value.binary->empty()) { - dump_integer(*i); - o->write_character(','); + for (auto i = val.m_data.m_value.binary->cbegin(); + i != val.m_data.m_value.binary->cend() - 1; + ++i) + { + dump_integer(*i); + o->write_character(','); + } + dump_integer(val.m_data.m_value.binary->back()); + } + + o->write_characters("],\"subtype\":", 12); + if (val.m_data.m_value.binary->has_subtype()) + { + dump_integer(val.m_data.m_value.binary->subtype()); + o->write_character('}'); + } + else + { + o->write_characters("null}", 5); } - dump_integer(val.m_data.m_value.binary->back()); } + continue; + } - o->write_characters("],\"subtype\":", 12); - if (val.m_data.m_value.binary->has_subtype()) + case value_t::boolean: + { + if (val.m_data.m_value.boolean) { - dump_integer(val.m_data.m_value.binary->subtype()); - o->write_character('}'); + o->write_characters("true", 4); } else { - o->write_characters("null}", 5); + o->write_characters("false", 5); } + continue; } - return; - } - case value_t::boolean: - { - if (val.m_data.m_value.boolean) + case value_t::number_integer: { - o->write_characters("true", 4); + dump_integer(val.m_data.m_value.number_integer); + continue; } - else + + case value_t::number_unsigned: { - o->write_characters("false", 5); + dump_integer(val.m_data.m_value.number_unsigned); + continue; } - return; - } - - case value_t::number_integer: - { - dump_integer(val.m_data.m_value.number_integer); - return; - } - case value_t::number_unsigned: - { - dump_integer(val.m_data.m_value.number_unsigned); - return; - } + case value_t::number_float: + { + dump_float(val.m_data.m_value.number_float); + continue; + } - case value_t::number_float: - { - dump_float(val.m_data.m_value.number_float); - return; - } + case value_t::discarded: + { + o->write_characters("", 11); + continue; + } - case value_t::discarded: - { - o->write_characters("", 11); - return; - } + case value_t::null: + { + o->write_characters("null", 4); + continue; + } - case value_t::null: - { - o->write_characters("null", 4); - return; + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE } - - default: // LCOV_EXCL_LINE - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE } }