| 153 | */ |
| 154 | template<typename Iterable, typename ValExtractor> |
| 155 | void 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. |
nothing calls this directly
no test coverage detected