I
InsightNexus

serializer< BasicJsonType > Class Template Reference

Author

David Craig

Published Feb 16, 2026

This function is called by the public member function dump and organizes the serialization internally. The indentation level is propagated as additional parameter. In case of arrays and objects, the function is called recursively.

15004  {

15005  switch (val.m_type)

15006  {

15008  {

15009  if (val.m_value.object->empty())

15010  {

15011  o->write_characters("{}", 2);

15012  return;

15013  }

15014 

15015  if (pretty_print)

15016  {

15017  o->write_characters("{\n", 2);

15018 

15019 

15020  const auto new_indent = current_indent + indent_step;

15021  if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))

15022  {

15023  indent_string.resize(indent_string.size() * 2, ' ');

15024  }

15025 

15026 

15027  auto i = val.m_value.object->cbegin();

15028  for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)

15029  {

15030  o->write_characters(indent_string.c_str(), new_indent);

15031  o->write_character('\"');

15032  dump_escaped(i->first, ensure_ascii);

15033  o->write_characters("\": ", 3);

15034  dump(i->second, true, ensure_ascii, indent_step, new_indent);

15035  o->write_characters(",\n", 2);

15036  }

15037 

15038 

15039  assert(i != val.m_value.object->cend());

15040  assert(std::next(i) == val.m_value.object->cend());

15041  o->write_characters(indent_string.c_str(), new_indent);

15042  o->write_character('\"');

15043  dump_escaped(i->first, ensure_ascii);

15044  o->write_characters("\": ", 3);

15045  dump(i->second, true, ensure_ascii, indent_step, new_indent);

15046 

15047  o->write_character('\n');

15048  o->write_characters(indent_string.c_str(), current_indent);

15049  o->write_character('}');

15050  }

15051  else

15052  {

15053  o->write_character('{');

15054 

15055 

15056  auto i = val.m_value.object->cbegin();

15057  for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)

15058  {

15059  o->write_character('\"');

15060  dump_escaped(i->first, ensure_ascii);

15061  o->write_characters("\":", 2);

15062  dump(i->second, false, ensure_ascii, indent_step, current_indent);

15063  o->write_character(',');

15064  }

15065 

15066 

15067  assert(i != val.m_value.object->cend());

15068  assert(std::next(i) == val.m_value.object->cend());

15069  o->write_character('\"');

15070  dump_escaped(i->first, ensure_ascii);

15071  o->write_characters("\":", 2);

15072  dump(i->second, false, ensure_ascii, indent_step, current_indent);

15073 

15074  o->write_character('}');

15075  }

15076 

15077  return;

15078  }

15079 

15081  {

15082  if (val.m_value.array->empty())

15083  {

15084  o->write_characters("[]", 2);

15085  return;

15086  }

15087 

15088  if (pretty_print)

15089  {

15090  o->write_characters("[\n", 2);

15091 

15092 

15093  const auto new_indent = current_indent + indent_step;

15094  if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))

15095  {

15096  indent_string.resize(indent_string.size() * 2, ' ');

15097  }

15098 

15099 

15100  for (auto i = val.m_value.array->cbegin();

15101  i != val.m_value.array->cend() - 1; ++i)

15102  {

15103  o->write_characters(indent_string.c_str(), new_indent);

15104  dump(*i, true, ensure_ascii, indent_step, new_indent);

15105  o->write_characters(",\n", 2);

15106  }

15107 

15108 

15109  assert(not val.m_value.array->empty());

15110  o->write_characters(indent_string.c_str(), new_indent);

15111  dump(val.m_value.array->back(), true, ensure_ascii, indent_step, new_indent);

15112 

15113  o->write_character('\n');

15114  o->write_characters(indent_string.c_str(), current_indent);

15115  o->write_character(']');

15116  }

15117  else

15118  {

15119  o->write_character('[');

15120 

15121 

15122  for (auto i = val.m_value.array->cbegin();

15123  i != val.m_value.array->cend() - 1; ++i)

15124  {

15125  dump(*i, false, ensure_ascii, indent_step, current_indent);

15126  o->write_character(',');

15127  }

15128 

15129 

15130  assert(not val.m_value.array->empty());

15131  dump(val.m_value.array->back(), false, ensure_ascii, indent_step, current_indent);

15132 

15133  o->write_character(']');

15134  }

15135 

15136  return;

15137  }

15138 

15140  {

15141  o->write_character('\"');

15142  dump_escaped(*val.m_value.string, ensure_ascii);

15143  o->write_character('\"');

15144  return;

15145  }

15146 

15148  {

15149  if (pretty_print)

15150  {

15151  o->write_characters("{\n", 2);

15152 

15153 

15154  const auto new_indent = current_indent + indent_step;

15155  if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))

15156  {

15157  indent_string.resize(indent_string.size() * 2, ' ');

15158  }

15159 

15160  o->write_characters(indent_string.c_str(), new_indent);

15161 

15162  o->write_characters("\"bytes\": [", 10);

15163 

15164  if (not val.m_value.binary->empty())

15165  {

15166  for (auto i = val.m_value.binary->cbegin();

15167  i != val.m_value.binary->cend() - 1; ++i)

15168  {

15169  dump_integer(*i);

15170  o->write_characters(", ", 2);

15171  }

15172  dump_integer(val.m_value.binary->back());

15173  }

15174 

15175  o->write_characters("],\n", 3);

15176  o->write_characters(indent_string.c_str(), new_indent);

15177 

15178  o->write_characters("\"subtype\": ", 11);

15179  if (val.m_value.binary->has_subtype())

15180  {

15181  dump_integer(val.m_value.binary->subtype());

15182  }

15183  else

15184  {

15185  o->write_characters("null", 4);

15186  }

15187  o->write_character('\n');

15188  o->write_characters(indent_string.c_str(), current_indent);

15189  o->write_character('}');

15190  }

15191  else

15192  {

15193  o->write_characters("{\"bytes\":[", 10);

15194 

15195  if (not val.m_value.binary->empty())

15196  {

15197  for (auto i = val.m_value.binary->cbegin();

15198  i != val.m_value.binary->cend() - 1; ++i)

15199  {

15200  dump_integer(*i);

15201  o->write_character(',');

15202  }

15203  dump_integer(val.m_value.binary->back());

15204  }

15205 

15206  o->write_characters("],\"subtype\":", 12);

15207  if (val.m_value.binary->has_subtype())

15208  {

15209  dump_integer(val.m_value.binary->subtype());

15210  o->write_character('}');

15211  }

15212  else

15213  {

15214  o->write_characters("null}", 5);

15215  }

15216  }

15217  return;

15218  }

15219 

15221  {

15222  if (val.m_value.boolean)

15223  {

15224  o->write_characters("true", 4);

15225  }

15226  else

15227  {

15228  o->write_characters("false", 5);

15229  }

15230  return;

15231  }

15232 

15234  {

15235  dump_integer(val.m_value.number_integer);

15236  return;

15237  }

15238 

15240  {

15241  dump_integer(val.m_value.number_unsigned);

15242  return;

15243  }

15244 

15246  {

15247  dump_float(val.m_value.number_float);

15248  return;

15249  }

15250 

15252  {

15253  o->write_characters("<discarded>", 11);

15254  return;

15255  }

15256 

15258  {

15259  o->write_characters("null", 4);

15260  return;

15261  }

15262 

15263  default:

15264  assert(false);

15265  }

15266  }