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

Function SerializeObject

lib/base/serializer.cpp:150–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

148}
149
150static Object::Ptr SerializeObject(const Object::Ptr& input, int attributeTypes, SerializeStack& stack, bool dryRun)
151{
152 Type::Ptr type = input->GetReflectionType();
153
154 if (!type)
155 return nullptr;
156
157 DictionaryData fields;
158
159 if (!dryRun) {
160 fields.reserve(type->GetFieldCount() + 1);
161 }
162
163 ObjectLock olock(input);
164
165 for (int i = 0; i < type->GetFieldCount(); i++) {
166 Field field = type->GetFieldInfo(i);
167
168 if (attributeTypes != 0 && (field.Attributes & attributeTypes) == 0)
169 continue;
170
171 if (strcmp(field.Name, "type") == 0)
172 continue;
173
174 Value value = input->GetField(i);
175 stack.Push(field.Name, value);
176
177 auto serialized (SerializeInternal(value, attributeTypes, stack, dryRun));
178
179 if (!dryRun) {
180 fields.emplace_back(field.Name, std::move(serialized));
181 }
182
183 stack.Pop();
184 }
185
186 if (!dryRun) {
187 fields.emplace_back("type", type->GetName());
188 }
189
190 return dryRun ? nullptr : new Dictionary(std::move(fields));
191}
192
193static Array::Ptr DeserializeArray(const Array::Ptr& input, bool safe_mode, int attributeTypes)
194{

Callers 2

SerializeInternalFunction · 0.85

Calls 8

SerializeInternalFunction · 0.85
PopMethod · 0.80
GetReflectionTypeMethod · 0.45
GetFieldCountMethod · 0.45
GetFieldInfoMethod · 0.45
GetFieldMethod · 0.45
PushMethod · 0.45
GetNameMethod · 0.45

Tested by

no test coverage detected