| 46 | // If 'map_key' is false, 'stringify_map_keys_' has no effect. |
| 47 | template <class JsonStream> |
| 48 | void ComplexValueWriter<JsonStream>::PrimitiveValueToJSON(void* value, |
| 49 | const ColumnType& type, bool map_key) { |
| 50 | if (type.IsBooleanType() && !map_key) { |
| 51 | writer_->Bool( *(reinterpret_cast<bool*>(value)) ); |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | string tmp; |
| 56 | // Passing -1 as 'scale' means we do not modify the precision setting of the stream |
| 57 | // (used when printing floating point values). |
| 58 | constexpr int scale = -1; |
| 59 | RawValue::PrintValue(value, type, scale, &tmp); |
| 60 | const bool should_convert_to_string = map_key && stringify_map_keys_; |
| 61 | if (IsPrimitiveTypePrintedAsString(type) || should_convert_to_string) { |
| 62 | if (type.IsBinaryType()) { |
| 63 | int64_t base64_max_len; |
| 64 | bool succ = Base64EncodeBufLen(tmp.size(), &base64_max_len); |
| 65 | DCHECK(succ); |
| 66 | |
| 67 | // 'base64_max_len' includes the null terminator. |
| 68 | string buf(base64_max_len - 1, '\0'); |
| 69 | unsigned base64_len = 0; |
| 70 | succ = Base64Encode(tmp.c_str(), tmp.size(), base64_max_len, buf.data(), |
| 71 | &base64_len); |
| 72 | DCHECK(succ); |
| 73 | |
| 74 | tmp = std::move(buf); |
| 75 | } |
| 76 | writer_->String(tmp.c_str()); |
| 77 | } else { |
| 78 | writer_->RawValue(tmp.c_str(), tmp.size(), |
| 79 | map_key ? rapidjson::kStringType : rapidjson::kNumberType); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | template <class JsonStream> |
| 84 | void ComplexValueWriter<JsonStream>::WriteNull(bool map_key) { |
nothing calls this directly
no test coverage detected