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

Method EncodeArray

lib/base/json.cpp:103–119  ·  view source on GitHub ↗

* Encodes an Array object into JSON and writes it to the output stream. * * @param array The Array object to be serialized into JSON. * @param yc The optional yield context for asynchronous operations. If provided, it allows the encoder * to flush the output stream safely when it has not acquired any object lock. */

Source from the content-addressed store, hash-verified

101 * to flush the output stream safely when it has not acquired any object lock.
102 */
103void JsonEncoder::EncodeArray(const Array::Ptr& array, boost::asio::yield_context* yc)
104{
105 BeginContainer('[');
106 auto olock = array->LockIfRequired();
107 if (olock) {
108 yc = nullptr; // We've acquired an object lock, never allow asynchronous operations.
109 }
110
111 bool isEmpty = true;
112 for (const auto& item : array) {
113 WriteSeparatorAndIndentStrIfNeeded(!isEmpty);
114 isEmpty = false;
115 Encode(item, yc);
116 m_Flusher.FlushIfSafe(yc);
117 }
118 EndContainer(']', isEmpty);
119}
120
121/**
122 * Encodes a ValueGenerator object into JSON and writes it to the output stream.

Callers

nothing calls this directly

Calls 2

FlushIfSafeMethod · 0.80
LockIfRequiredMethod · 0.45

Tested by

no test coverage detected