Пример #1
0
void JsonVariant::writeTo(JsonWriter &writer) const {
  if (_type == JSON_ARRAY)
    _content.asArray->writeTo(writer);

  else if (_type == JSON_OBJECT)
    _content.asObject->writeTo(writer);

  else if (_type == JSON_STRING)
    writer.writeString(_content.asString);

  else if (_type == JSON_UNPARSED)
    writer.writeRaw(_content.asString);

  else if (_type == JSON_INTEGER)
    writer.writeInteger(_content.asInteger);

  else if (_type == JSON_BOOLEAN)
    writer.writeBoolean(_content.asInteger != 0);

  else if (_type >= JSON_FLOAT_0_DECIMALS) {
    uint8_t decimals = static_cast<uint8_t>(_type - JSON_FLOAT_0_DECIMALS);
    writer.writeFloat(_content.asFloat, decimals);
  }
}
Пример #2
0
void JsonVariant::writeTo(JsonWriter &writer) const {
  switch (_type) {
    case JSON_UNDEFINED:
      return;

    case JSON_ARRAY:
      _content.asArray->writeTo(writer);
      return;

    case JSON_OBJECT:
      _content.asObject->writeTo(writer);
      return;

    case JSON_STRING:
      writer.writeString(_content.asString);
      return;

    case JSON_UNPARSED:
      writer.writeRaw(_content.asString);
      return;

    case JSON_NEGATIVE_INTEGER:
      writer.writeRaw('-');
    case JSON_POSITIVE_INTEGER:
      writer.writeInteger(_content.asInteger);
      return;

    case JSON_BOOLEAN:
      writer.writeBoolean(_content.asInteger != 0);
      return;

    default:
      uint8_t decimals = static_cast<uint8_t>(_type - JSON_FLOAT_0_DECIMALS);
      writer.writeFloat(_content.asFloat, decimals);
  }
}