MCPcopy Create free account
hub / github.com/Icinga/icinga2 / DeserializeObject

Function DeserializeObject

lib/base/serializer.cpp:223–268  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

221}
222
223static 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
270static Value SerializeInternal(const Value& value, int attributeTypes, SerializeStack& stack, bool dryRun)
271{

Callers 1

DeserializeMethod · 0.85

Calls 7

InstantiateMethod · 0.80
GetReflectionTypeMethod · 0.45
GetMethod · 0.45
IsEmptyMethod · 0.45
GetFieldIdMethod · 0.45
GetFieldInfoMethod · 0.45
SetFieldMethod · 0.45

Tested by

no test coverage detected