ACF $AcfVersion:0$
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
iser::CJsonWriteArchiveBase Class Reference

Implementation of an ACF Archive serializing to JSON string. More...

#include <CJsonWriteArchiveBase.h>

Inheritance diagram for iser::CJsonWriteArchiveBase:
iser::CTextWriteArchiveBase iser::CWriteArchiveBase iser::CArchiveBase iser::IArchive istd::ILogger istd::IPolymorphic istd::IPolymorphic ifile::CJsonFileWriteArchive iser::CJsonMemWriteArchive

Classes

struct  TagsStackItem
 

Public Types

typedef iser::CTextWriteArchiveBase BaseClass
 
- Public Types inherited from iser::CTextWriteArchiveBase
typedef CWriteArchiveBase BaseClass
 
- Public Types inherited from iser::IArchive
enum  MessageId { MI_TAG_ERROR = 0x3f320a0 , MI_TAG_SKIPPED }
 

Public Member Functions

 ~CJsonWriteArchiveBase ()
 
void SetFormat (QJsonDocument::JsonFormat jsonFormat)
 
virtual bool IsTagSkippingSupported () const override
 Checks if skipping to the end of a tag on EndTag() is supported.
 
virtual bool BeginTag (const iser::CArchiveTag &tag) override
 Begins a tagged section in the archive.
 
virtual bool BeginMultiTag (const iser::CArchiveTag &tag, const iser::CArchiveTag &subTag, int &count) override
 Begins a tagged section containing multiple elements of the same type.
 
virtual bool EndTag (const iser::CArchiveTag &tag) override
 Ends a tagged section in the archive.
 
virtual bool Process (QString &value) override
 Process primitive type.
 
virtual bool Process (QByteArray &value) override
 Process primitive type.
 
virtual bool ProcessData (void *dataPtr, int size) override
 Process binary data block.
 
virtual bool Process (bool &value) override
 Processes (reads or writes) a boolean value.
 
virtual bool Process (char &value) override
 Process primitive type.
 
virtual bool Process (quint8 &value) override
 Process primitive type.
 
virtual bool Process (qint8 &value) override
 Process primitive type.
 
virtual bool Process (quint16 &value) override
 Process primitive type.
 
virtual bool Process (qint16 &value) override
 Process primitive type.
 
virtual bool Process (quint32 &value) override
 Process primitive type.
 
virtual bool Process (qint32 &value) override
 Process primitive type.
 
virtual bool Process (quint64 &value) override
 Process primitive type.
 
virtual bool Process (qint64 &value) override
 Process primitive type.
 
virtual bool Process (float &value) override
 Process primitive type.
 
virtual bool Process (double &value) override
 Process primitive type.
 
virtual bool Process (QByteArray &value) override
 Process primitive type.
 
- Public Member Functions inherited from iser::CWriteArchiveBase
virtual bool IsStoring () const override
 Checks if this archive is in storing (writing) or loading (reading) mode.
 
virtual const IVersionInfoGetVersionInfo () const override
 Gets version information for the archived stream.
 
virtual bool ProcessBits (void *dataPtr, int bitsCount, int bytesCount) override
 Process binary data block.
 
- Public Member Functions inherited from iser::IArchive
template<typename Primitive >
bool TagAndProcess (const CArchiveTag &tag, Primitive &value)
 
- Public Member Functions inherited from istd::IPolymorphic
virtual ~IPolymorphic ()
 

Protected Member Functions

 CJsonWriteArchiveBase (const iser::IVersionInfo *versionInfoPtr, bool serializeHeader, const iser::CArchiveTag &rootTag)
 
bool InitStream (bool serializeHeader)
 
bool InitArchive (QIODevice *devicePtr)
 
bool InitArchive (QByteArray &inputString)
 
bool WriteTag (const iser::CArchiveTag &tag, QString separator)
 
bool WriteJsonHeader ()
 
bool Flush ()
 
virtual bool WriteTextNode (const QByteArray &text) override
 Write single unformatted text node.
 
- Protected Member Functions inherited from iser::CTextWriteArchiveBase
 CTextWriteArchiveBase (const IVersionInfo *versionInfoPtr)
 
- Protected Member Functions inherited from iser::CWriteArchiveBase
 CWriteArchiveBase (const IVersionInfo *versionInfoPtr)
 Constructor.
 
bool SerializeAcfHeader ()
 Serialize standard header.
 
- Protected Member Functions inherited from iser::CArchiveBase
 CArchiveBase ()
 
- Protected Member Functions inherited from istd::ILogger
virtual void DecorateMessage (IInformationProvider::InformationCategory category, int id, int flags, QString &message, QString &messageSource) const
 Decorate message parts before outputting.
 
virtual bool IsLogConsumed (const IInformationProvider::InformationCategory *categoryPtr=NULL, const int *flagsPtr=NULL) const
 Check if any log message is consumed.
 
virtual bool SendLogMessage (IInformationProvider::InformationCategory category, int id, const QString &message, const QString &messageSource, int flags=0) const
 Send any message to log.
 

Protected Attributes

QTextStream m_stream
 
QBuffer m_buffer
 
bool m_firstTag
 
QJsonDocument::JsonFormat m_jsonFormat
 
bool m_serializeHeader
 
iser::CArchiveTag m_rootTag
 
bool m_isSeparatorNeeded
 
bool m_allowAttribute
 
bool m_quotationMarksRequired = false
 
QList< TagsStackItemm_tagsStack
 

Additional Inherited Members

- Static Public Member Functions inherited from iser::CArchiveBase
static const CArchiveTagGetAcfRootTag ()
 
- Static Protected Attributes inherited from iser::CArchiveBase
static CArchiveTag s_acfRootTag
 

Detailed Description

Implementation of an ACF Archive serializing to JSON string.

Definition at line 25 of file CJsonWriteArchiveBase.h.

Member Typedef Documentation

◆ BaseClass

Definition at line 28 of file CJsonWriteArchiveBase.h.

Constructor & Destructor Documentation

◆ ~CJsonWriteArchiveBase()

iser::CJsonWriteArchiveBase::~CJsonWriteArchiveBase ( )

◆ CJsonWriteArchiveBase()

iser::CJsonWriteArchiveBase::CJsonWriteArchiveBase ( const iser::IVersionInfo versionInfoPtr,
bool  serializeHeader,
const iser::CArchiveTag rootTag 
)
protected

Member Function Documentation

◆ BeginMultiTag()

virtual bool iser::CJsonWriteArchiveBase::BeginMultiTag ( const iser::CArchiveTag tag,
const iser::CArchiveTag subTag,
int &  count 
)
overridevirtual

Begins a tagged section containing multiple elements of the same type.

BeginMultiTag is used for serializing collections, arrays, or lists where you have multiple items of the same structure. The count parameter works differently for reading vs. writing:

  • Writing: Pass the number of elements you will serialize
  • Reading: The archive sets count to the number of elements stored
Parameters
tagMain container tag for the entire collection
subTagTag type for each individual element in the collection
count[in/out] For writing: number of elements to serialize For reading: set by archive to number of stored elements
Returns
true if successful, false on error
// Writing a list
if (archive.IsStoring()) {
int count = m_items.count();
archive.BeginMultiTag(listTag, itemTag, count);
for (const Item& item : m_items) {
archive.BeginTag(itemTag);
item.Serialize(archive);
archive.EndTag(itemTag);
}
archive.EndTag(listTag);
}
// Reading a list
else {
int count;
archive.BeginMultiTag(listTag, itemTag, count);
m_items.clear();
for (int i = 0; i < count; ++i) {
archive.BeginTag(itemTag);
Item item;
item.Serialize(archive);
m_items.append(item);
archive.EndTag(itemTag);
}
archive.EndTag(listTag);
}
See also
BeginTag(), EndTag()

Reimplemented from iser::CArchiveBase.

◆ BeginTag()

virtual bool iser::CJsonWriteArchiveBase::BeginTag ( const iser::CArchiveTag tag)
overridevirtual

Begins a tagged section in the archive.

Tags organize data into logical units with names and descriptions. Every BeginTag() must be matched with an EndTag() call. Tags can be nested to create hierarchical data structures.

Parameters
tagThe tag object describing this section. Use static CArchiveTag instances to avoid repeated construction overhead.
Returns
true if the tag was successfully opened, false on error
Note
Always match BeginTag() with EndTag()
Check the return value and propagate errors
For collections, use BeginMultiTag() instead
static iser::CArchiveTag personTag("Person", "Person data");
if (archive.BeginTag(personTag)) {
archive.Process(name);
archive.Process(age);
archive.EndTag(personTag);
}
Process tag used to group data in archive stream.
Definition CArchiveTag.h:22
See also
EndTag(), BeginMultiTag(), CArchiveTag

Implements iser::IArchive.

◆ EndTag()

virtual bool iser::CJsonWriteArchiveBase::EndTag ( const iser::CArchiveTag tag)
overridevirtual

Ends a tagged section in the archive.

Must be called after BeginTag() or BeginMultiTag() to close the section. If tag skipping is supported and not all data was read, this will skip to the end of the tag section, enabling forward compatibility.

Parameters
tagThe same tag object passed to BeginTag() or BeginMultiTag()
Returns
true if successful, false on error
Note
Always call EndTag() even if errors occurred within the tag
The tag parameter must match the one used in BeginTag()
If IsTagSkippingSupported() returns false, you must read all data before calling EndTag()
static iser::CArchiveTag dataTag("Data", "My data");
if (archive.BeginTag(dataTag)) {
bool success = archive.Process(myData);
archive.EndTag(dataTag); // Always call, even if Process failed
if (!success) return false;
}
See also
BeginTag(), BeginMultiTag(), IsTagSkippingSupported()

Implements iser::IArchive.

◆ Flush()

bool iser::CJsonWriteArchiveBase::Flush ( )
protected

◆ InitArchive() [1/2]

bool iser::CJsonWriteArchiveBase::InitArchive ( QByteArray &  inputString)
protected

◆ InitArchive() [2/2]

bool iser::CJsonWriteArchiveBase::InitArchive ( QIODevice *  devicePtr)
protected

◆ InitStream()

bool iser::CJsonWriteArchiveBase::InitStream ( bool  serializeHeader)
protected

◆ IsTagSkippingSupported()

virtual bool iser::CJsonWriteArchiveBase::IsTagSkippingSupported ( ) const
overridevirtual

Checks if skipping to the end of a tag on EndTag() is supported.

Some archive types (like XML) support skipping unread content within a tag, allowing forward compatibility. When reading an archive created by a newer version that added fields, this feature lets you skip unknown data.

Returns
true if the archive supports tag skipping, false otherwise
Note
Binary archives typically don't support skipping, requiring all data to be read sequentially.
XML and JSON archives usually support skipping.
if (archive.IsTagSkippingSupported()) {
// Can safely skip new fields added in future versions
} else {
// Must read all data in exact order
}
See also
EndTag()

Reimplemented from iser::CArchiveBase.

◆ Process() [1/15]

virtual bool iser::CTextWriteArchiveBase::Process ( bool &  value)
overridevirtual

Processes (reads or writes) a boolean value.

Parameters
value[in/out] For writing: the value to store For reading: receives the loaded value
Returns
true if successful, false on error
See also
IsStoring(), Process() overloads for other types

Reimplemented from iser::CTextWriteArchiveBase.

◆ Process() [2/15]

virtual bool iser::CTextWriteArchiveBase::Process ( char &  value)
overridevirtual

Process primitive type.

Reimplemented from iser::CTextWriteArchiveBase.

◆ Process() [3/15]

virtual bool iser::CTextWriteArchiveBase::Process ( double &  value)
overridevirtual

Process primitive type.

Reimplemented from iser::CTextWriteArchiveBase.

◆ Process() [4/15]

virtual bool iser::CTextWriteArchiveBase::Process ( float &  value)
overridevirtual

Process primitive type.

Reimplemented from iser::CTextWriteArchiveBase.

◆ Process() [5/15]

virtual bool iser::CJsonWriteArchiveBase::Process ( QByteArray &  value)
overridevirtual

Process primitive type.

Reimplemented from iser::CTextWriteArchiveBase.

◆ Process() [6/15]

virtual bool iser::CTextWriteArchiveBase::Process ( QByteArray &  value)
overridevirtual

Process primitive type.

Reimplemented from iser::CTextWriteArchiveBase.

◆ Process() [7/15]

virtual bool iser::CTextWriteArchiveBase::Process ( qint16 &  value)
overridevirtual

Process primitive type.

Reimplemented from iser::CTextWriteArchiveBase.

◆ Process() [8/15]

virtual bool iser::CTextWriteArchiveBase::Process ( qint32 &  value)
overridevirtual

Process primitive type.

Reimplemented from iser::CTextWriteArchiveBase.

◆ Process() [9/15]

virtual bool iser::CTextWriteArchiveBase::Process ( qint64 &  value)
overridevirtual

Process primitive type.

Reimplemented from iser::CTextWriteArchiveBase.

◆ Process() [10/15]

virtual bool iser::CTextWriteArchiveBase::Process ( qint8 &  value)
overridevirtual

Process primitive type.

Reimplemented from iser::CTextWriteArchiveBase.

◆ Process() [11/15]

virtual bool iser::CJsonWriteArchiveBase::Process ( QString &  value)
overridevirtual

Process primitive type.

Implements iser::IArchive.

◆ Process() [12/15]

virtual bool iser::CTextWriteArchiveBase::Process ( quint16 &  value)
overridevirtual

Process primitive type.

Reimplemented from iser::CTextWriteArchiveBase.

◆ Process() [13/15]

virtual bool iser::CTextWriteArchiveBase::Process ( quint32 &  value)
overridevirtual

Process primitive type.

Reimplemented from iser::CTextWriteArchiveBase.

◆ Process() [14/15]

virtual bool iser::CTextWriteArchiveBase::Process ( quint64 &  value)
overridevirtual

Process primitive type.

Reimplemented from iser::CTextWriteArchiveBase.

◆ Process() [15/15]

virtual bool iser::CTextWriteArchiveBase::Process ( quint8 &  value)
overridevirtual

Process primitive type.

Reimplemented from iser::CTextWriteArchiveBase.

◆ ProcessData()

virtual bool iser::CJsonWriteArchiveBase::ProcessData ( void *  dataPtr,
int  size 
)
overridevirtual

Process binary data block.

Parameters
dataPtrpointer to memory block.
sizesize of memory block in bytes.

Reimplemented from iser::CTextWriteArchiveBase.

◆ SetFormat()

void iser::CJsonWriteArchiveBase::SetFormat ( QJsonDocument::JsonFormat  jsonFormat)

◆ WriteJsonHeader()

bool iser::CJsonWriteArchiveBase::WriteJsonHeader ( )
protected

◆ WriteTag()

bool iser::CJsonWriteArchiveBase::WriteTag ( const iser::CArchiveTag tag,
QString  separator 
)
protected

◆ WriteTextNode()

virtual bool iser::CJsonWriteArchiveBase::WriteTextNode ( const QByteArray &  text)
overrideprotectedvirtual

Write single unformatted text node.

Implements iser::CTextWriteArchiveBase.

Member Data Documentation

◆ m_allowAttribute

bool iser::CJsonWriteArchiveBase::m_allowAttribute
protected

Definition at line 70 of file CJsonWriteArchiveBase.h.

◆ m_buffer

QBuffer iser::CJsonWriteArchiveBase::m_buffer
protected

Definition at line 63 of file CJsonWriteArchiveBase.h.

◆ m_firstTag

bool iser::CJsonWriteArchiveBase::m_firstTag
protected

Definition at line 64 of file CJsonWriteArchiveBase.h.

◆ m_isSeparatorNeeded

bool iser::CJsonWriteArchiveBase::m_isSeparatorNeeded
protected

Definition at line 69 of file CJsonWriteArchiveBase.h.

◆ m_jsonFormat

QJsonDocument::JsonFormat iser::CJsonWriteArchiveBase::m_jsonFormat
protected

Definition at line 65 of file CJsonWriteArchiveBase.h.

◆ m_quotationMarksRequired

bool iser::CJsonWriteArchiveBase::m_quotationMarksRequired = false
protected

Definition at line 78 of file CJsonWriteArchiveBase.h.

◆ m_rootTag

iser::CArchiveTag iser::CJsonWriteArchiveBase::m_rootTag
protected

Definition at line 67 of file CJsonWriteArchiveBase.h.

◆ m_serializeHeader

bool iser::CJsonWriteArchiveBase::m_serializeHeader
protected

Definition at line 66 of file CJsonWriteArchiveBase.h.

◆ m_stream

QTextStream iser::CJsonWriteArchiveBase::m_stream
protected

Definition at line 62 of file CJsonWriteArchiveBase.h.

◆ m_tagsStack

QList<TagsStackItem> iser::CJsonWriteArchiveBase::m_tagsStack
protected

Definition at line 80 of file CJsonWriteArchiveBase.h.


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