1 #ifndef ZSERIO_JSON_WRITER_H_INC 2 #define ZSERIO_JSON_WRITER_H_INC 18 template <
typename ALLOC = std::allocator<u
int8_t>>
75 explicit BasicJsonWriter(std::ostream& out,
const ALLOC& allocator = ALLOC());
84 BasicJsonWriter(std::ostream& out, uint8_t indent,
const ALLOC& allocator = ALLOC());
156 const ALLOC& allocator = ALLOC());
179 bool m_isFirst =
true;
188 template <
typename ALLOC>
193 template <
typename ALLOC>
198 template <
typename ALLOC>
200 const ALLOC& allocator) :
204 template <
typename ALLOC>
208 m_out(out), m_indent(optionalIndent),
211 m_keySeparator(DEFAULT_KEY_SEPARATOR, allocator)
214 template <
typename ALLOC>
217 m_itemSeparator = itemSeparator;
220 template <
typename ALLOC>
223 m_keySeparator = keySeparator;
226 template <
typename ALLOC>
229 m_enumerableFormat = enumerableFormat;
232 template <
typename ALLOC>
238 template <
typename ALLOC>
245 template <
typename ALLOC>
256 template <
typename ALLOC>
264 template <
typename ALLOC>
270 if (elementIndex == WALKER_NOT_ELEMENT)
276 template <
typename ALLOC>
285 template <
typename ALLOC>
291 if (elementIndex == WALKER_NOT_ELEMENT)
299 template <
typename ALLOC>
303 m_out.write(m_itemSeparator.data(),
static_cast<std::streamsize
>(m_itemSeparator.size()));
305 if (m_indent.hasValue())
311 template <
typename ALLOC>
317 template <
typename ALLOC>
326 template <
typename ALLOC>
329 if (m_indent.hasValue())
339 template <
typename ALLOC>
348 template <
typename ALLOC>
351 if (m_indent.hasValue())
361 template <
typename ALLOC>
364 if (m_indent.hasValue())
366 const auto& indent = m_indent.value();
369 for (
size_t i = 0; i < m_level; ++i)
370 m_out.write(indent.data(),
static_cast<std::streamsize
>(indent.size()));
375 template <
typename ALLOC>
379 m_out.write(m_keySeparator.data(),
static_cast<std::streamsize
>(m_keySeparator.size()));
383 template <
typename ALLOC>
417 writeBytes(reflectable->getBytes());
423 writeBitBuffer(reflectable->getBitBuffer());
427 writeStringifiedEnum(reflectable);
435 writeStringifiedBitmask(reflectable);
447 template <
typename ALLOC>
452 writeKey(
"buffer"_sv);
455 for (uint8_t element : buffer)
464 writeKey(
"bitSize"_sv);
470 template <
typename ALLOC>
475 writeKey(
"buffer"_sv);
477 for (uint8_t byte : value)
488 template <
typename ALLOC>
491 const auto& typeInfo = reflectable->getTypeInfo();
493 static_cast<uint64_t>(reflectable->toInt()) : reflectable->toUInt();
494 for (
const auto& itemInfo : typeInfo.getEnumItems())
496 if (itemInfo.value == enumValue)
508 stringValue.append(
" /* no match */");
512 template <
typename ALLOC>
516 const auto& typeInfo = reflectable->getTypeInfo();
517 const uint64_t bitmaskValue = reflectable->toUInt();
518 uint64_t valueCheck = 0;
519 for (
const auto& itemInfo : typeInfo.getBitmaskValues())
521 if ((itemInfo.value != 0 && (bitmaskValue & itemInfo.value) == itemInfo.value) ||
522 (itemInfo.value == 0 && bitmaskValue == 0))
524 valueCheck |= itemInfo.value;
525 if (!stringValue.empty())
526 stringValue +=
" | ";
531 if (stringValue.empty())
535 stringValue.append(
" /* no match */");
537 else if (bitmaskValue != valueCheck)
541 .append(
" /* partial match: ")
552 #endif // ZSERIO_JSON_WRITER_H_INC typename IBasicReflectable< ALLOC >::ConstPtr IBasicReflectableConstPtr
static void encodeString(std::ostream &os, StringView value)
string< ALLOC > toString(T value, const ALLOC &allocator=ALLOC())
void setEnumerableFormat(EnumerableFormat enumerableFormat)
virtual CppType getCppType() const =0
void endArray(const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
static void encodeIntegral(std::ostream &os, T value)
static void encodeBool(std::ostream &os, bool value)
void endCompound(const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
void endRoot(const IBasicReflectableConstPtr< ALLOC > &compound) override
virtual const IBasicTypeInfo< ALLOC > & getUnderlyingType() const =0
static constexpr const char * DEFAULT_KEY_SEPARATOR
static constexpr const char * DEFAULT_ITEM_SEPARATOR_WITH_INDENT
~BasicJsonWriter() override=default
void beginCompound(const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
void setKeySeparator(const string< ALLOC > &keySeparator)
static bool isSigned(SchemaType schemaType)
detail::inplace_optional_holder< T > InplaceOptionalHolder
virtual StringView getSchemaName() const =0
BasicJsonWriter & operator=(const BasicJsonWriter &other)=delete
constexpr NullOptType NullOpt
allocator_type get_allocator() const
static void encodeFloatingPoint(std::ostream &os, double value)
BasicJsonWriter(std::ostream &out, const ALLOC &allocator=ALLOC())
void beginArray(const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
size_t getBitSize() const
static constexpr EnumerableFormat DEFAULT_ENUMERABLE_FORMAT
std::basic_string< char, std::char_traits< char >, RebindAlloc< ALLOC, char >> string
static void encodeNull(std::ostream &os)
Span< const uint8_t > getData() const
static constexpr const char * DEFAULT_ITEM_SEPARATOR
void beginRoot(const IBasicReflectableConstPtr< ALLOC > &compound) override
void setItemSeparator(const string< ALLOC > &itemSeparator)
void visitValue(const IBasicReflectableConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override