Zserio C++ runtime library  1.1.0
Built for Zserio 2.15.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 class  EnumerableFormat { NUMBER , STRING }
 
- Public Types inherited from zserio::AllocatorHolder< std::allocator< uint8_t > >
using allocator_type = std::allocator< uint8_t >
 

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< std::allocator< uint8_t > >
virtual ~IBasicWalkObserver ()=default
 
virtual void beginRoot (const IBasicReflectableConstPtr< std::allocator< uint8_t > > &compound)=0
 
virtual void endRoot (const IBasicReflectableConstPtr< std::allocator< uint8_t > > &compound)=0
 
virtual void beginArray (const IBasicReflectableConstPtr< std::allocator< uint8_t > > &array, const BasicFieldInfo< std::allocator< uint8_t > > &fieldInfo)=0
 
virtual void endArray (const IBasicReflectableConstPtr< std::allocator< uint8_t > > &array, const BasicFieldInfo< std::allocator< uint8_t > > &fieldInfo)=0
 
virtual void beginCompound (const IBasicReflectableConstPtr< std::allocator< uint8_t > > &compound, const BasicFieldInfo< std::allocator< uint8_t > > &fieldInfo, size_t elementIndex)=0
 
virtual void endCompound (const IBasicReflectableConstPtr< std::allocator< uint8_t > > &compound, const BasicFieldInfo< std::allocator< uint8_t > > &fieldInfo, size_t elementIndex)=0
 
virtual void visitValue (const IBasicReflectableConstPtr< std::allocator< uint8_t > > &value, const BasicFieldInfo< std::allocator< uint8_t > > &fieldInfo, size_t elementIndex)=0
 
- Public Member Functions inherited from zserio::AllocatorHolder< std::allocator< uint8_t > >
 AllocatorHolder ()
 
 AllocatorHolder (const allocator_type &allocator)
 
 AllocatorHolder (allocator_type &&allocator)
 
allocator_type get_allocator () const
 
 AllocatorHolder (const AllocatorHolder &other)=default
 
 AllocatorHolder (AllocatorHolder &&other)=default
 
 ~AllocatorHolder ()=default
 
AllocatorHolderoperator= (const 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< std::allocator< uint8_t > >
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

◆ EnumerableFormat

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

◆ BasicJsonWriter() [1/5]

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.

◆ BasicJsonWriter() [2/5]

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.

◆ BasicJsonWriter() [3/5]

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.

◆ ~BasicJsonWriter()

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

Method generated by default.

◆ BasicJsonWriter() [4/5]

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

Copying and moving is disallowed!

◆ BasicJsonWriter() [5/5]

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

Copying and moving is disallowed!

Member Function Documentation

◆ beginArray()

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

Definition at line 247 of file JsonWriter.h.

◆ beginCompound()

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

Definition at line 266 of file JsonWriter.h.

◆ beginRoot()

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

Definition at line 234 of file JsonWriter.h.

◆ endArray()

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

Definition at line 258 of file JsonWriter.h.

◆ endCompound()

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

Definition at line 280 of file JsonWriter.h.

◆ endRoot()

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

Definition at line 240 of file JsonWriter.h.

◆ operator=() [1/2]

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

Copying and moving is disallowed!

◆ operator=() [2/2]

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

Copying and moving is disallowed!

◆ setEnumerableFormat()

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

Sets preferred formatting for enumerable types.

Parameters
enumerableFormatEnumerable format to use.

Definition at line 228 of file JsonWriter.h.

◆ setItemSeparator()

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 216 of file JsonWriter.h.

◆ setKeySeparator()

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 222 of file JsonWriter.h.

◆ visitValue()

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

Definition at line 289 of file JsonWriter.h.

Member Data Documentation

◆ DEFAULT_ENUMERABLE_FORMAT

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

Default configuration for enumerable types.

Definition at line 67 of file JsonWriter.h.

◆ DEFAULT_ITEM_SEPARATOR

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

Default item separator used when indent is not set.

Definition at line 27 of file JsonWriter.h.

◆ DEFAULT_ITEM_SEPARATOR_WITH_INDENT

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

Default item separator used when indent is set.

Definition at line 32 of file JsonWriter.h.

◆ DEFAULT_KEY_SEPARATOR

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

Default key separator.

Definition at line 37 of file JsonWriter.h.


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