Zserio C++ runtime library  1.0.0
Built for Zserio 2.13.0
zserio::BasicJsonWriter< ALLOC > Class Template Reference

#include <JsonWriter.h>

Inheritance diagram for zserio::BasicJsonWriter< ALLOC >:
Collaboration diagram for zserio::BasicJsonWriter< ALLOC >:

Public Types

enum  EnumerableFormat { EnumerableFormat::NUMBER, EnumerableFormat::STRING }
 
- Public Types inherited from zserio::AllocatorHolder< ALLOC >
using allocator_type = ALLOC
 

Public Member Functions

 BasicJsonWriter (std::ostream &out, const ALLOC &allocator=ALLOC())
 
 BasicJsonWriter (std::ostream &out, uint8_t indent, const ALLOC &allocator=ALLOC())
 
 BasicJsonWriter (std::ostream &out, const string< ALLOC > &indent, const ALLOC &allocator=ALLOC())
 
 ~BasicJsonWriter () override=default
 
void setItemSeparator (const string< ALLOC > &itemSeparator)
 
void setKeySeparator (const string< ALLOC > &keySeparator)
 
void setEnumerableFormat (EnumerableFormat enumerableFormat)
 
void beginRoot (const IBasicReflectableConstPtr< ALLOC > &compound) override
 
void endRoot (const IBasicReflectableConstPtr< ALLOC > &compound) override
 
void beginArray (const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
 
void endArray (const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
 
void beginCompound (const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
 
void endCompound (const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
 
void visitValue (const IBasicReflectableConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
 
 BasicJsonWriter (const BasicJsonWriter &other)=delete
 
BasicJsonWriteroperator= (const BasicJsonWriter &other)=delete
 
 BasicJsonWriter (BasicJsonWriter &&other)=delete
 
BasicJsonWriteroperator= (BasicJsonWriter &&other)=delete
 
- Public Member Functions inherited from zserio::IBasicWalkObserver< ALLOC >
virtual ~IBasicWalkObserver ()=default
 
- Public Member Functions inherited from zserio::AllocatorHolder< ALLOC >
 AllocatorHolder ()
 
 AllocatorHolder (const allocator_type &allocator)
 
 AllocatorHolder (allocator_type &&allocator)
 
allocator_type get_allocator () const
 
 ~AllocatorHolder ()=default
 
 AllocatorHolder (const AllocatorHolder &other)=default
 
AllocatorHolderoperator= (const AllocatorHolder &other)=default
 
 AllocatorHolder (AllocatorHolder &&other)=default
 
AllocatorHolderoperator= (AllocatorHolder &&other)=default
 

Static Public Attributes

static constexpr const char * DEFAULT_ITEM_SEPARATOR = ", "
 
static constexpr const char * DEFAULT_ITEM_SEPARATOR_WITH_INDENT = ","
 
static constexpr const char * DEFAULT_KEY_SEPARATOR = ": "
 
static constexpr EnumerableFormat DEFAULT_ENUMERABLE_FORMAT = EnumerableFormat::STRING
 

Additional Inherited Members

- Protected Member Functions inherited from zserio::AllocatorHolder< ALLOC >
void set_allocator (const allocator_type &allocator)
 
void set_allocator (allocator_type &&allocator)
 
allocator_typeget_allocator_ref ()
 
const allocator_typeget_allocator_ref () const
 

Detailed Description

template<typename ALLOC = std::allocator<uint8_t>>
class zserio::BasicJsonWriter< ALLOC >

Walker observer which dumps zserio objects to JSON format.

Definition at line 19 of file JsonWriter.h.

Member Enumeration Documentation

template<typename ALLOC = std::allocator<uint8_t>>
enum zserio::BasicJsonWriter::EnumerableFormat
strong

Configuration for writing of enumerable types.

Enumerator
NUMBER 

Print as JSON integral value.

STRING 

Print as JSON string according to the following rules:

  1. Enums
    • when an exact match with an enumerable item is found, the item name is used - e.g. "FIRST",
    • when no exact match is found, it's an invalid value, the integral value is converted to string and an appropriate comment is included - e.g. "10 /* no match */".
  2. Bitmasks
    • when an exact mach with or-ed bitmask values is found, it's used - e.g. "READ | WRITE",
    • when no exact match is found, but some or-ed values match, the integral value is converted to string and the or-ed values are included in a comment - e.g. "127 /* READ | CREATE */",
    • when no match is found at all, the integral value is converted to string and an appropriate comment is included - e.g. "13 /* no match */".

Definition at line 42 of file JsonWriter.h.

Constructor & Destructor Documentation

template<typename ALLOC >
zserio::BasicJsonWriter< ALLOC >::BasicJsonWriter ( std::ostream &  out,
const ALLOC &  allocator = ALLOC() 
)
explicit

Constructor.

Parameters
outStream to use for writing.
allocatorAllocator to use.

Definition at line 189 of file JsonWriter.h.

template<typename ALLOC >
zserio::BasicJsonWriter< ALLOC >::BasicJsonWriter ( std::ostream &  out,
uint8_t  indent,
const ALLOC &  allocator = ALLOC() 
)

Constructor.

Parameters
outStream to use for writing.
indentIndent as a number of ' ' to be used for indentation.
allocatorAllocator to use.

Definition at line 194 of file JsonWriter.h.

template<typename ALLOC >
zserio::BasicJsonWriter< ALLOC >::BasicJsonWriter ( std::ostream &  out,
const string< ALLOC > &  indent,
const ALLOC &  allocator = ALLOC() 
)

Constructor.

Parameters
outStream to use for writing.
indentIndent as a string to be used for indentation.
allocatorAllocator to use.

Definition at line 199 of file JsonWriter.h.

template<typename ALLOC = std::allocator<uint8_t>>
zserio::BasicJsonWriter< ALLOC >::~BasicJsonWriter ( )
overridedefault

Method generated by default.

template<typename ALLOC = std::allocator<uint8_t>>
zserio::BasicJsonWriter< ALLOC >::BasicJsonWriter ( const BasicJsonWriter< ALLOC > &  other)
delete

Copying and moving is disallowed!

template<typename ALLOC = std::allocator<uint8_t>>
zserio::BasicJsonWriter< ALLOC >::BasicJsonWriter ( BasicJsonWriter< ALLOC > &&  other)
delete

Copying and moving is disallowed!

Member Function Documentation

template<typename ALLOC >
void zserio::BasicJsonWriter< ALLOC >::beginArray ( const IBasicReflectableConstPtr< ALLOC > &  array,
const BasicFieldInfo< ALLOC > &  fieldInfo 
)
overridevirtual

Called at the beginning of an array.

Note that for unset arrays (i.e. non-present optionals) the visitValue method with nullptr is called instead!

Parameters
arrayReflectable zserio array.
fieldInfoArray field info.

Implements zserio::IBasicWalkObserver< ALLOC >.

Definition at line 246 of file JsonWriter.h.

template<typename ALLOC >
void zserio::BasicJsonWriter< ALLOC >::beginCompound ( const IBasicReflectableConstPtr< ALLOC > &  compound,
const BasicFieldInfo< ALLOC > &  fieldInfo,
size_t  elementIndex 
)
overridevirtual

Called at the beginning of an compound field object.

Note that for unset compounds (i.e. non-present optionals) the visitValue method with nullptr is called instead!

Parameters
compoundReflectable compound zserio object.
fieldInfoCompound field info.
elementIndexElement index in array or WALKER_NOT_ELEMENT if the compound is not in array.

Implements zserio::IBasicWalkObserver< ALLOC >.

Definition at line 265 of file JsonWriter.h.

template<typename ALLOC >
void zserio::BasicJsonWriter< ALLOC >::beginRoot ( const IBasicReflectableConstPtr< ALLOC > &  compound)
overridevirtual

Called for the root compound zserio object which is to be walked-through.

Parameters
compoundReflectable root compound zserio object.

Implements zserio::IBasicWalkObserver< ALLOC >.

Definition at line 233 of file JsonWriter.h.

template<typename ALLOC >
void zserio::BasicJsonWriter< ALLOC >::endArray ( const IBasicReflectableConstPtr< ALLOC > &  array,
const BasicFieldInfo< ALLOC > &  fieldInfo 
)
overridevirtual

Called at the end of an array.

Parameters
arrayReflectable zserio array.
fieldInfoArray field info.

Implements zserio::IBasicWalkObserver< ALLOC >.

Definition at line 257 of file JsonWriter.h.

template<typename ALLOC >
void zserio::BasicJsonWriter< ALLOC >::endCompound ( const IBasicReflectableConstPtr< ALLOC > &  compound,
const BasicFieldInfo< ALLOC > &  fieldInfo,
size_t  elementIndex 
)
overridevirtual

Called at the end of just walked compound object.

Parameters
compoundReflectable compound zserio object.
fieldInfoCompound field info.
elementIndexElement index in array or WALKER_NOT_ELEMENT if the compound is not in array.

Implements zserio::IBasicWalkObserver< ALLOC >.

Definition at line 277 of file JsonWriter.h.

template<typename ALLOC >
void zserio::BasicJsonWriter< ALLOC >::endRoot ( const IBasicReflectableConstPtr< ALLOC > &  compound)
overridevirtual

Called at the end of just walked root compound zserio object.

Parameters
compoundReflectable root compound zserio object.

Implements zserio::IBasicWalkObserver< ALLOC >.

Definition at line 239 of file JsonWriter.h.

template<typename ALLOC = std::allocator<uint8_t>>
BasicJsonWriter& zserio::BasicJsonWriter< ALLOC >::operator= ( const BasicJsonWriter< ALLOC > &  other)
delete

Copying and moving is disallowed!

template<typename ALLOC = std::allocator<uint8_t>>
BasicJsonWriter& zserio::BasicJsonWriter< ALLOC >::operator= ( BasicJsonWriter< ALLOC > &&  other)
delete

Copying and moving is disallowed!

template<typename ALLOC >
void zserio::BasicJsonWriter< ALLOC >::setEnumerableFormat ( EnumerableFormat  enumerableFormat)

Sets preferred formatting for enumerable types.

Parameters
enumerableFormatEnumerable format to use.

Definition at line 227 of file JsonWriter.h.

template<typename ALLOC >
void zserio::BasicJsonWriter< ALLOC >::setItemSeparator ( const string< ALLOC > &  itemSeparator)

Sets custom item separator.

Use with caution since setting of a wrong separator can lead to invalid JSON output.

Parameters
itemSeparatorItem separator to set.

Definition at line 215 of file JsonWriter.h.

template<typename ALLOC >
void zserio::BasicJsonWriter< ALLOC >::setKeySeparator ( const string< ALLOC > &  keySeparator)

Sets custom key separator.

Use with caution since setting of a wrong separator can lead to invalid JSON output.

Parameters
keySeparatorKey separator to set.

Definition at line 221 of file JsonWriter.h.

template<typename ALLOC >
void zserio::BasicJsonWriter< ALLOC >::visitValue ( const IBasicReflectableConstPtr< ALLOC > &  value,
const BasicFieldInfo< ALLOC > &  fieldInfo,
size_t  elementIndex 
)
overridevirtual

Called when a simple (or an unset compound or array - i.e. nullptr) value is reached.

Parameters
valueReflectable simple value.
fieldInfoField info.
elementIndexElement index in array or WALKER_NOT_ELEMENT if the value is not in array.

Implements zserio::IBasicWalkObserver< ALLOC >.

Definition at line 286 of file JsonWriter.h.

Member Data Documentation

template<typename ALLOC = std::allocator<uint8_t>>
constexpr EnumerableFormat zserio::BasicJsonWriter< ALLOC >::DEFAULT_ENUMERABLE_FORMAT = EnumerableFormat::STRING
static

Default configuration for enumerable types.

Definition at line 67 of file JsonWriter.h.

template<typename ALLOC = std::allocator<uint8_t>>
constexpr const char* zserio::BasicJsonWriter< ALLOC >::DEFAULT_ITEM_SEPARATOR = ", "
static

Default item separator used when indent is not set.

Definition at line 27 of file JsonWriter.h.

template<typename ALLOC = std::allocator<uint8_t>>
constexpr const char* zserio::BasicJsonWriter< ALLOC >::DEFAULT_ITEM_SEPARATOR_WITH_INDENT = ","
static

Default item separator used when indent is set.

Definition at line 32 of file JsonWriter.h.

template<typename ALLOC = std::allocator<uint8_t>>
constexpr const char* zserio::BasicJsonWriter< ALLOC >::DEFAULT_KEY_SEPARATOR = ": "
static

Default key separator.

Definition at line 37 of file JsonWriter.h.


The documentation for this class was generated from the following file: