| 230 | }; |
| 231 | } |
| 232 | |
| 233 | std::string json_option_string(const engine::io::json::Value & value) { |
| 234 | if (value.is_string()) { |
| 235 | return value.as_string(); |
| 236 | } |
| 237 | if (value.is_bool()) { |
| 238 | return value.as_bool() ? "true" : "false"; |
| 239 | } |
| 240 | if (value.is_number()) { |
| 241 | const double number = value.as_number(); |
| 242 | constexpr double kMaxExactJsonInteger = 9007199254740992.0; // 2^53 |
| 243 | if (std::isfinite(number) && std::trunc(number) == number && std::fabs(number) < kMaxExactJsonInteger) { |
| 244 | std::ostringstream out; |
| 245 | out << std::fixed << std::setprecision(0) << number; |
| 246 | return out.str(); |
| 247 | } |
| 248 | return engine::io::json::stringify_number(number); |
| 249 | } |
| 250 | return engine::io::json::stringify(value); |
| 251 | } |
| 252 | |
| 253 | std::unordered_map<std::string, std::string> json_options_map(const engine::io::json::Value * value) { |
| 254 | std::unordered_map<std::string, std::string> options; |
| 255 | if (value == nullptr || value->is_null()) { |
| 256 | return options; |
| 257 | } |
| 258 | for (const auto & [key, child] : value->as_object()) { |
| 259 | options[key] = json_option_string(child); |
| 260 | } |
| 261 | return options; |
| 262 | } |
| 263 | |
| 264 | std::optional<std::string> json_optional_string( |
| 265 | const engine::io::json::Value & object, |
| 266 | const std::string & key) { |
| 267 | const auto * value = object.find(key); |
| 268 | if (value == nullptr || value->is_null()) { |
| 269 | return std::nullopt; |
| 270 | } |
| 271 | return value->as_string(); |
| 272 | } |
| 273 | |
| 274 | std::optional<float> json_optional_float( |
| 275 | const engine::io::json::Value & object, |
| 276 | const std::string & key) { |
| 277 | const auto * value = object.find(key); |
| 278 | if (value == nullptr || value->is_null()) { |
| 279 | return std::nullopt; |
| 280 | } |
| 281 | return value->as_f32(); |
| 282 | } |
| 283 | |
| 284 | std::vector<engine::runtime::VoiceArtifact> json_request_artifacts( |
| 285 | const engine::io::json::Value * value, |
| 286 | const std::filesystem::path & base_dir) { |
| 287 | std::vector<engine::runtime::VoiceArtifact> artifacts; |
| 288 | if (value == nullptr || value->is_null()) { |
| 289 | return artifacts; |
no test coverage detected