* Reads string containing JSON representation of configuration. * If file can not be parsed, an instance of @c ParseException is thrown. * @param json JSON string. */
| 168 | * @param json JSON string. |
| 169 | */ |
| 170 | void Config::readJsonString(const std::string& json) |
| 171 | { |
| 172 | rapidjson::Document root; |
| 173 | rapidjson::ParseResult ok = root.Parse(json); |
| 174 | if (!ok) |
| 175 | { |
| 176 | std::string errMsg = "Failed to parse configuration!"; |
| 177 | |
| 178 | errMsg = GetParseError_En(ok.Code()); |
| 179 | |
| 180 | auto loc = retdec::utils::getLineAndColumnFromPosition(json, ok.Offset()); |
| 181 | throw ParseException(errMsg, loc.first, loc.second); |
| 182 | } |
| 183 | |
| 184 | *this = Config(); |
| 185 | |
| 186 | auto params = root.FindMember(JSON_parameters); |
| 187 | if (params != root.MemberEnd()) |
| 188 | { |
| 189 | parameters.deserialize(params->value); |
| 190 | } |
| 191 | |
| 192 | serdes::deserialize(root, JSON_architecture, architecture); |
| 193 | serdes::deserialize(root, JSON_fileType, fileType); |
| 194 | serdes::deserialize(root, JSON_fileFormat, fileFormat); |
| 195 | |
| 196 | serdes::deserializeContainer(root, JSON_tools, tools); |
| 197 | serdes::deserializeContainer(root, JSON_languages, languages); |
| 198 | serdes::deserializeContainer(root, JSON_functions, functions); |
| 199 | serdes::deserializeContainer(root, JSON_globals, globals); |
| 200 | serdes::deserializeContainer(root, JSON_registers, registers); |
| 201 | serdes::deserializeContainer(root, JSON_structures, structures); |
| 202 | serdes::deserializeContainer(root, JSON_vtables, vtables); |
| 203 | serdes::deserializeContainer(root, JSON_classes, classes); |
| 204 | serdes::deserializeContainer(root, JSON_patterns, patterns); |
| 205 | } |
| 206 | |
| 207 | } // namespace config |
| 208 | } // namespace retdec |