| 221 | } |
| 222 | |
| 223 | static Object::Ptr DeserializeObject(const Object::Ptr& object, const Dictionary::Ptr& input, bool safe_mode, int attributeTypes) |
| 224 | { |
| 225 | if (!object && safe_mode) |
| 226 | BOOST_THROW_EXCEPTION(std::runtime_error("Tried to instantiate object while safe mode is enabled.")); |
| 227 | |
| 228 | Type::Ptr type; |
| 229 | |
| 230 | if (object) |
| 231 | type = object->GetReflectionType(); |
| 232 | else |
| 233 | type = Type::GetByName(input->Get("type")); |
| 234 | |
| 235 | if (!type) |
| 236 | return object; |
| 237 | |
| 238 | Object::Ptr instance; |
| 239 | |
| 240 | if (object) |
| 241 | instance = object; |
| 242 | else |
| 243 | instance = type->Instantiate(std::vector<Value>()); |
| 244 | |
| 245 | ObjectLock olock(input); |
| 246 | for (const Dictionary::Pair& kv : input) { |
| 247 | if (kv.first.IsEmpty()) |
| 248 | continue; |
| 249 | |
| 250 | int fid = type->GetFieldId(kv.first); |
| 251 | |
| 252 | if (fid < 0) |
| 253 | continue; |
| 254 | |
| 255 | Field field = type->GetFieldInfo(fid); |
| 256 | |
| 257 | if ((field.Attributes & attributeTypes) == 0) |
| 258 | continue; |
| 259 | |
| 260 | try { |
| 261 | instance->SetField(fid, Deserialize(kv.second, safe_mode, attributeTypes), true); |
| 262 | } catch (const std::exception&) { |
| 263 | instance->SetField(fid, Empty); |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | return instance; |
| 268 | } |
| 269 | |
| 270 | static Value SerializeInternal(const Value& value, int attributeTypes, SerializeStack& stack, bool dryRun) |
| 271 | { |
no test coverage detected