Loading...
Searching...
No Matches
pappso::cbor::JsonStreamWriter Class Reference

helper class to write json text using CBOR data structures More...

`#include <jsonstreamwriter.h>`

Inheritance diagram for pappso::cbor::JsonStreamWriter:

## Public Member Functions

| JsonStreamWriter (QIODevice *device)
| build a QTextStream for JSON writer
virtual | ~JsonStreamWriter ()
void | startArray ()
| starts an array in JSON output simply print "["
void | endArray ()
| ends an array in JSON output simply print "]"
void | startMap ()
| start an object in JSON output simply print "{"
void | endMap ()
| ends an object in JSON output simply print "}"
void | writeCborMap (const QCborMap &cbor_map)
| converts a CBOR map (object) into JSON text in output
void | writeCborArray (const QCborArray &cbor_array)
| converts a CBOR array (list) into JSON text in output
void | appendKey (const QString &key)
| writes a key (dictionary entry) to JSON text
void | appendValue (const QString &value)
| writes String value to JSON text
void | appendValue (std::size_t integer_size_value)
| writes an integer value to JSON text
void | writeArray (QStringList &str_list)
| convert a string list to a JSON array

## Protected Member Functions

void | comma ()

## Private Attributes

bool | m_isStart = true
bool | m_nextIsValue = false

## Detailed Description

helper class to write json text using CBOR data structures

Definition at line 42 of file jsonstreamwriter.h.

## Constructor & Destructor Documentation

## JsonStreamWriter()

pappso::cbor::JsonStreamWriter::JsonStreamWriter | ( | QIODevice * | device | ) |

build a QTextStream for JSON writer

Definition at line 35 of file jsonstreamwriter.cpp.

: QTextStream(device)
{
}

## ~JsonStreamWriter()

pappso::cbor::JsonStreamWriter::~JsonStreamWriter | ( |  | ) |

virtual

Destructor

Definition at line 39 of file jsonstreamwriter.cpp.

{
}

## Member Function Documentation

## appendKey()

void pappso::cbor::JsonStreamWriter::appendKey | ( | const QString & | key | ) |

writes a key (dictionary entry) to JSON text

Definition at line 96 of file jsonstreamwriter.cpp.

{
if(!m_isStart)
comma();
*this << "\"" << key << "\":";
m_isStart = false;
m_nextIsValue = true;
}
pappso::cbor::JsonStreamWriter::comma
void comma()
Definition jsonstreamwriter.cpp:127
pappso::cbor::JsonStreamWriter::m_nextIsValue
bool m_nextIsValue
Definition jsonstreamwriter.h:115
pappso::cbor::JsonStreamWriter::m_isStart
bool m_isStart
Definition jsonstreamwriter.h:114

References comma(), m_isStart, and m_nextIsValue.

## appendValue() [1/2]

void pappso::cbor::JsonStreamWriter::appendValue | ( | const QString & | value | ) |

writes String value to JSON text

Warning
  this function does not escapes text correctly, use with caution

Definition at line 106 of file jsonstreamwriter.cpp.

{
*this << "\"" << value << "\"";
m_nextIsValue = false;
}

References m_nextIsValue.

## appendValue() [2/2]

void pappso::cbor::JsonStreamWriter::appendValue | ( | std::size_t | integer_size_value | ) |

writes an integer value to JSON text

Definition at line 113 of file jsonstreamwriter.cpp.

{
*this << integer_size_value;
m_nextIsValue = false;
}

References m_nextIsValue.

## comma()

void pappso::cbor::JsonStreamWriter::comma | ( |  | ) |

protected

Definition at line 127 of file jsonstreamwriter.cpp.

{
*this << "," << Qt::endl;
m_isStart = false;
}

References m_isStart.

Referenced by appendKey(), startArray(), and startMap().

## endArray()

void pappso::cbor::JsonStreamWriter::endArray | ( |  | ) |

ends an array in JSON output simply print "]"

Definition at line 44 of file jsonstreamwriter.cpp.

{
*this << "]" << Qt::endl;
m_isStart = false;
m_nextIsValue = false;
}

References m_isStart, and m_nextIsValue.

## endMap()

void pappso::cbor::JsonStreamWriter::endMap | ( |  | ) |

ends an object in JSON output simply print "}"

Definition at line 52 of file jsonstreamwriter.cpp.

{
*this << "}" << Qt::endl;
m_isStart = false;
m_nextIsValue = false;
}

References m_isStart, and m_nextIsValue.

## startArray()

void pappso::cbor::JsonStreamWriter::startArray | ( |  | ) |

starts an array in JSON output simply print "["

Definition at line 60 of file jsonstreamwriter.cpp.

{
if(!m_nextIsValue)
comma();
*this << Qt::endl << "[";
m_isStart = true;
}

References comma(), m_isStart, and m_nextIsValue.

## startMap()

void pappso::cbor::JsonStreamWriter::startMap | ( |  | ) |

start an object in JSON output simply print "{"

Definition at line 68 of file jsonstreamwriter.cpp.

{
if(!m_nextIsValue)
comma();
*this << Qt::endl << "{";
m_isStart = true;
}

References comma(), m_isStart, and m_nextIsValue.

## writeArray()

void pappso::cbor::JsonStreamWriter::writeArray | ( | QStringList & | str_list | ) |

convert a string list to a JSON array

Warning
  text is not escaped correctly, use with caution

Definition at line 121 of file jsonstreamwriter.cpp.

{
*this << "[\"" << str_list.join("\", \"") << "\"]" << Qt::endl;
}

## writeCborArray()

void pappso::cbor::JsonStreamWriter::writeCborArray | ( | const QCborArray & | cbor_array | ) |

converts a CBOR array (list) into JSON text in output

Parameters

  cbor_array | the map to convert

Definition at line 86 of file jsonstreamwriter.cpp.

{
QJsonDocument doc;
doc.setArray(QCborValue(cbor_array).toJsonValue().toArray());
*this << doc.toJson();
}

## writeCborMap()

void pappso::cbor::JsonStreamWriter::writeCborMap | ( | const QCborMap & | cbor_map | ) |

converts a CBOR map (object) into JSON text in output

Parameters

  cbor_map | the map to convert

Definition at line 77 of file jsonstreamwriter.cpp.

{
QJsonDocument doc;
doc.setObject(QCborValue(cbor_map).toJsonValue().toObject());
*this << doc.toJson();
}

## Member Data Documentation

## m_isStart

bool pappso::cbor::JsonStreamWriter::m_isStart = true

private

Definition at line 114 of file jsonstreamwriter.h.

Referenced by appendKey(), comma(), endArray(), endMap(), startArray(), and startMap().

## m_nextIsValue

bool pappso::cbor::JsonStreamWriter::m_nextIsValue = false

private

Definition at line 115 of file jsonstreamwriter.h.

Referenced by appendKey(), appendValue(), appendValue(), endArray(), endMap(), startArray(), and startMap().

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

- pappsomspp/core/processing/cbor/jsonstreamwriter.h
- pappsomspp/core/processing/cbor/jsonstreamwriter.cpp