libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
jsonstreamwriter.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/processing/cbor/jsonstreamwriter.cpp
3 * \date 19/07/2025
4 * \author Olivier Langella
5 * \brief PAPPSO JSON stream writer
6 */
7
8/*******************************************************************************
9 * Copyright (c) 2025 Olivier Langella <Olivier.Langella@universite-paris-saclay.fr>.
10 *
11 * This file is part of PAPPSOms-tools.
12 *
13 * PAPPSOms-tools is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * PAPPSOms-tools is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with PAPPSOms-tools. If not, see <http://www.gnu.org/licenses/>.
25 *
26 ******************************************************************************/
27
28#include "jsonstreamwriter.h"
29#include <QJsonDocument>
30#include <QJsonObject>
31#include <QJsonArray>
32#include <qjsonvalue.h>
33
34
35pappso::cbor::JsonStreamWriter::JsonStreamWriter(QIODevice *device) : QTextStream(device)
36{
37}
38
42
43void
45{
46 *this << "]" << Qt::endl;
47 m_isStart = false;
48 m_nextIsValue = false;
49}
50
51void
53{
54 *this << "}" << Qt::endl;
55 m_isStart = false;
56 m_nextIsValue = false;
57}
58
59void
61{
62 if(!m_nextIsValue)
63 comma();
64 *this << Qt::endl << "[";
65 m_isStart = true;
66}
67void
69{
70 if(!m_nextIsValue)
71 comma();
72 *this << Qt::endl << "{";
73 m_isStart = true;
74}
75
76void
78{
79 QJsonDocument doc;
80 doc.setObject(QCborValue(cbor_map).toJsonValue().toObject());
81
82 *this << doc.toJson();
83}
84
85void
87{
88 QJsonDocument doc;
89 doc.setArray(QCborValue(cbor_array).toJsonValue().toArray());
90
91 *this << doc.toJson();
92}
93
94
95void
97{
98 if(!m_isStart)
99 comma();
100 *this << "\"" << key << "\":";
101 m_isStart = false;
102 m_nextIsValue = true;
103}
104
105void
107{
108 *this << "\"" << value << "\"";
109 m_nextIsValue = false;
110}
111
112void
113pappso::cbor::JsonStreamWriter::appendValue(std::size_t integer_size_value)
114{
115 *this << integer_size_value;
116 m_nextIsValue = false;
117}
118
119
120void
122{
123 *this << "[\"" << str_list.join("\", \"") << "\"]" << Qt::endl;
124}
125
126void
128{
129 *this << "," << Qt::endl;
130 m_isStart = false;
131}
void appendValue(const QString &value)
writes String value to JSON text
void endArray()
ends an array in JSON output simply print "]"
void endMap()
ends an object in JSON output simply print "}"
void writeCborArray(const QCborArray &cbor_array)
converts a CBOR array (list) into JSON text in output
JsonStreamWriter(QIODevice *device)
build a QTextStream for JSON writer
void startMap()
start an object in JSON output simply print "{"
void writeArray(QStringList &str_list)
convert a string list to a JSON array
void appendKey(const QString &key)
writes a key (dictionary entry) to JSON text
void writeCborMap(const QCborMap &cbor_map)
converts a CBOR map (object) into JSON text in output
void startArray()
starts an array in JSON output simply print "["