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;
50 debug <<
">>> Start" << std::endl;
51 states.push(State::IN_START);
56 debug <<
"StartArray()" << std::endl;
58 states.push(State::IN_LIST);
61 states.push(State::IN_ERROR);
65 bool EndArray(SizeType)
67 debug <<
"EndArray()" << std::endl;
68 if (
states.top() == State::IN_LIST) {
73 states.push(State::IN_ERROR);
77 bool Key(
const Ch*
str, SizeType,
bool)
79 debug <<
"Key(" <<
str <<
")" << std::endl;
81 if (
states.top() == State::IN_START) {
87 if (
states.top() == State::IN_RECORD) {
105 states.push(State::IN_ERROR);
111 debug <<
"StartObject()" << std::endl;
112 if (
states.top() == State::IN_START) {
116 if (
states.top() == State::IN_LIST) {
117 states.push(State::IN_RECORD);
124 states.push(State::IN_ERROR);
128 bool EndObject(SizeType)
130 debug <<
"EndObject()" << std::endl;
131 if (
states.top() == State::IN_RECORD) {
138 if (
states.top() == State::IN_START) {
142 states.push(State::IN_ERROR);
146 bool Uint(
unsigned i)
148 debug <<
"Uint(" <<
i <<
") passed to Int()" << std::endl;
154 debug <<
"Int(" <<
i <<
")" << std::endl;
155 if (
states.top() == State::IN_RECORD) {
166 states.push(State::IN_ERROR);
170 bool String(
const Ch*
str, SizeType,
bool)
172 debug <<
"String(" <<
str <<
")" << std::endl;
173 if (
states.top() == State::IN_RECORD) {
188 states.push(State::IN_ERROR);
196 rapidjson::Reader reader;
197 rapidjson::IStreamWrapper isw(s);
198 IndexRecordsReader irreader;
200 bool ok = reader.Parse(isw, irreader);
203 throw framework::runtime_error_f(
"Cannot parse serialized index records vector, error: %s at offset: %d", rapidjson::GetParseError_En(reader.GetParseErrorCode()), reader.GetErrorOffset());
205 return irreader.records;
210void writeRecords(rapidjson::Writer<rapidjson::OStreamWrapper>&
w, std::vector<o2::soa::IndexRecord>&
records)
215 w.String(
r.label.c_str());
219 w.String(
r.columnLabel.c_str());
231 rapidjson::OStreamWrapper osw(o);
232 rapidjson::Writer<rapidjson::OStreamWrapper>
w(osw);
236 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 std::string describe(InputSpec const &spec)
static ConcreteDataMatcher fromString(std::string s)
Create a concrete data matcher from serialized string.
static void write(std::ostream &o, std::vector< o2::soa::IndexRecord > &irs)
static std::vector< o2::soa::IndexRecord > read(std::istream &s)