| 279 | |
| 280 | template <typename SimdjsonValueType> |
| 281 | Result<SimdjsonValueType> GetJsonAs(simdjson::ondemand::value& value) { |
| 282 | SimdjsonValueType typed_value{}; |
| 283 | simdjson::error_code error_code; |
| 284 | |
| 285 | if constexpr (std::same_as<SimdjsonValueType, SimdjsonNull>) { |
| 286 | // simdjson has no get<>() for null; probe it explicitly |
| 287 | bool is_null; |
| 288 | error_code = value.is_null().get(is_null); |
| 289 | if (error_code == simdjson::SUCCESS && !is_null) { |
| 290 | error_code = simdjson::INCORRECT_TYPE; |
| 291 | } |
| 292 | } else { |
| 293 | error_code = value.get(typed_value); |
| 294 | } |
| 295 | |
| 296 | if (error_code != simdjson::SUCCESS) { |
| 297 | simdjson::ondemand::json_type json_type; |
| 298 | if (value.type().get(json_type) != simdjson::SUCCESS) { |
| 299 | if constexpr (std::same_as<SimdjsonValueType, SimdjsonNull>) { |
| 300 | return Status::Invalid("Expected null, got malformed JSON value"); |
| 301 | } else { |
| 302 | return Status::Invalid("Expected ", JsonTypeName<SimdjsonValueType>(), |
| 303 | ", got malformed JSON value"); |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | if constexpr (std::same_as<SimdjsonValueType, SimdjsonNull>) { |
| 308 | return Status::Invalid("Expected null, got JSON type ", JsonTypeName(json_type)); |
| 309 | } else { |
| 310 | return Status::Invalid("Expected ", JsonTypeName<SimdjsonValueType>(), |
| 311 | ", got JSON type ", JsonTypeName(json_type)); |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | return typed_value; |
| 316 | } |
| 317 | |
| 318 | template <typename T> |
| 319 | Result<T> GetJsonField(simdjson::ondemand::object& object, std::string_view key) { |
nothing calls this directly
no test coverage detected