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

Method EncodeObject

lib/base/json.cpp:155–178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153 */
154template<typename Iterable, typename ValExtractor>
155void JsonEncoder::EncodeObject(const Iterable& container, const ValExtractor& extractor, boost::asio::yield_context* yc)
156{
157 static_assert(std::is_same_v<Iterable, Namespace::Ptr> || std::is_same_v<Iterable, Dictionary::Ptr>,
158 "Container must be a Namespace or Dictionary");
159
160 BeginContainer('{');
161 auto olock = container->LockIfRequired();
162 if (olock) {
163 yc = nullptr; // We've acquired an object lock, never allow asynchronous operations.
164 }
165
166 bool isEmpty = true;
167 for (const auto& [key, val] : container) {
168 WriteSeparatorAndIndentStrIfNeeded(!isEmpty);
169 isEmpty = false;
170
171 EncodeNlohmannJson(key);
172 Write(m_Pretty ? ": " : ":");
173
174 Encode(extractor(val), yc);
175 m_Flusher.FlushIfSafe(yc);
176 }
177 EndContainer('}', isEmpty);
178}
179
180/**
181 * Dumps a nlohmann::json object to the output stream using the serializer.

Callers

nothing calls this directly

Calls 2

FlushIfSafeMethod · 0.80
LockIfRequiredMethod · 0.45

Tested by

no test coverage detected