void injectRefs (Json::Value ¶ms, Json::Value &responses) { if (params.isObject () || params.isArray () ) { for (auto it = params.begin(); it != params.end() ; it++) { injectRefs (*it, responses); } } else if (params.isConvertibleTo (Json::ValueType::stringValue) ) { std::string param = JsonFixes::getString (params); if (param.size() > NEW_REF.size() && param.substr (0, NEW_REF.size() ) == NEW_REF) { std::string ref = param.substr (NEW_REF.size() ); try { int index = stoi (ref); insertResult (params, responses, index); } catch (std::invalid_argument &e) { Json::Value data; KurentoException ke (MALFORMED_TRANSACTION, "Invalid index of newref '" + ref + "'"); data[TYPE] = ke.getType(); throw JsonRpc::CallException (ke.getCode (), ke.getMessage (), data); } } } }
Temperatures::Temperatures(const Json::Value& reply) : beerReading(compact_or_verbose(reply, "bt", "BeerTemp").asDouble()), beerSetting(compact_or_verbose(reply, "bs", "BeerSet").asDouble()), beerAnnotation(compact_or_verbose(reply, "ba", "BeerAnn").asString()), fridgeReading(compact_or_verbose(reply, "ft", "FridgeTemp").asDouble()), fridgeSetting(compact_or_verbose(reply, "fs", "FridgeSet").asDouble()), fridgeAnnotation(compact_or_verbose(reply, "fa", "FridgeAnn").asString()), roomTemp(compact_or_verbose(reply, "rt", "RoomTemp").asDouble()), state(Temperatures::State::Null) { const Json::Value state_value = compact_or_verbose(reply, "s", "State"); if(!state_value.isNull() && state_value.isConvertibleTo(Json::intValue)) { int state_int = state_value.asInt(); if(state_int < 0 || state_int >= static_cast<int>(Temperatures::State::MAX_VALUE)) { state = Temperatures::State::Null; } else { state = static_cast<State>(state_int); } } }
bool k8s_api_handler::handle_component(const Json::Value& json, const msg_data* data) { m_error = false; if(!json.isNull()) { if(json.isArray()) { for(const auto& version : json) { if(version.isConvertibleTo(Json::stringValue)) { m_extensions.push_back(version.asString()); } else { g_logger.log("K8s API handler error: could not extract API versions or extensions from JSON.", sinsp_logger::SEV_ERROR); m_error = true; return false; } } } else if(json.isConvertibleTo(Json::stringValue)) { m_extensions.push_back(json.asString()); } else { g_logger.log("K8s API handler error: could not extract API versions or extensions from JSON.", sinsp_logger::SEV_ERROR); m_error = true; return false; } m_data_received = true; } else { g_logger.log("K8s API handler error: json is null.", sinsp_logger::SEV_ERROR); m_error = true; return false; } return true; }
void _Deserialize(const AuthorizedObject &parent_obj, const Json::Value &json) { if(!json.isConvertibleTo(Json::stringValue)) throw UnexpectedException("!json.isConvertibleTo(Json::stringValue)"); const std::string &str = json.asString(); bool found = false; // Hack: This is nasty, but required to do a complete iteration. Hopefully, we never have to go over the int limit! for(int s = (int)none; s < (int)count; ++s) { if(stricmp(str.c_str(), str_array[s]) == 0) { t_ = (T)s; break; } } if(!found) throw UnexpectedException("!found"); }