13#include <rapidjson/reader.h>
14#include <rapidjson/prettywriter.h>
15#include <rapidjson/istreamwrapper.h>
16#include <rapidjson/ostreamwrapper.h>
17#include <rapidjson/error/en.h>
26struct IndexRecordsReader :
public rapidjson::BaseReaderHandler<rapidjson::UTF8<>, IndexRecordsReader> {
27 using Ch = rapidjson::UTF8<>::Ch;
28 using SizeType = rapidjson::SizeType;
40 std::vector<o2::soa::IndexRecord>
records;
49 debug <<
">>> Start" << std::endl;
50 states.push(State::IN_START);
55 debug <<
"StartArray()" << std::endl;
57 states.push(State::IN_LIST);
60 states.push(State::IN_ERROR);
64 bool EndArray(SizeType)
66 debug <<
"EndArray()" << std::endl;
67 if (
states.top() == State::IN_LIST) {
72 states.push(State::IN_ERROR);
76 bool Key(
const Ch*
str, SizeType,
bool)
78 debug <<
"Key(" <<
str <<
")" << std::endl;
80 if (
states.top() == State::IN_START) {
86 if (
states.top() == State::IN_RECORD) {
101 states.push(State::IN_ERROR);
107 debug <<
"StartObject()" << std::endl;
108 if (
states.top() == State::IN_START) {
112 if (
states.top() == State::IN_LIST) {
113 states.push(State::IN_RECORD);
120 states.push(State::IN_ERROR);
124 bool EndObject(SizeType)
126 debug <<
"EndObject()" << std::endl;
127 if (
states.top() == State::IN_RECORD) {
134 if (
states.top() == State::IN_START) {
138 states.push(State::IN_ERROR);
142 bool Uint(
unsigned i)
144 debug <<
"Uint(" <<
i <<
") passed to Int()" << std::endl;
150 debug <<
"Int(" <<
i <<
")" << std::endl;
151 if (
states.top() == State::IN_RECORD) {
162 states.push(State::IN_ERROR);
166 bool String(
const Ch*
str, SizeType,
bool)
168 debug <<
"String(" <<
str <<
")" << std::endl;
169 if (
states.top() == State::IN_RECORD) {
180 states.push(State::IN_ERROR);
188 rapidjson::Reader reader;
189 rapidjson::IStreamWrapper isw(s);
190 IndexRecordsReader irreader;
192 bool ok = reader.Parse(isw, irreader);
195 throw framework::runtime_error_f(
"Cannot parse serialized index records vector, error: %s at offset: %d", rapidjson::GetParseError_En(reader.GetParseErrorCode()), reader.GetErrorOffset());
197 return irreader.records;
202void writeRecords(rapidjson::Writer<rapidjson::OStreamWrapper>&
w, std::vector<o2::soa::IndexRecord>&
records)
207 w.String(
r.label.c_str());
209 w.String(
r.columnLabel.c_str());
221 rapidjson::OStreamWrapper osw(o);
222 rapidjson::Writer<rapidjson::OStreamWrapper>
w(osw);
226 writeRecords(
w, irs);
std::vector< o2::soa::IndexRecord > records
o2::monitoring::tags::Key Key
GLuint GLsizei const GLchar * label
GLubyte GLubyte GLubyte GLubyte w
Defining PrimaryVertex explicitly as messageable.
RuntimeErrorRef runtime_error_f(const char *,...)
static void write(std::ostream &o, std::vector< o2::soa::IndexRecord > &irs)
static std::vector< o2::soa::IndexRecord > read(std::istream &s)