29 const char* cur = s.data();
30 const char* next = cur;
31 enum struct ParserState {
43 char const* lastSpace =
nullptr;
44 char const* previousLastSpace =
nullptr;
45 ParserState
state = ParserState::IN_PREAMBLE;
48 auto previousState =
state;
49 state = ParserState::IN_ERROR;
51 switch (previousState) {
52 case ParserState::IN_PREAMBLE:
53 if (s.data() + s.size() - cur < 9) {
54 }
else if (strncmp(
"[CONFIG] ", cur, 9) == 0) {
56 state = ParserState::IN_KEY;
59 case ParserState::IN_KEY:
60 next = strpbrk(cur,
"= ");
62 if (next ==
nullptr || *next ==
' ' || (next == cur)) {
63 }
else if (*next ==
'=') {
66 match.beginValue = next + 1;
67 state = ParserState::IN_VALUE;
70 case ParserState::IN_VALUE:
71 next = (
char*)memchr(cur,
' ', s.data() + s.size() - cur);
72 if (next ==
nullptr) {
73 if (previousLastSpace ==
nullptr || lastSpace ==
nullptr) {
78 match.endValue = previousLastSpace;
79 next = previousLastSpace;
80 state = ParserState::IN_TIMESTAMP;
82 previousLastSpace = lastSpace;
84 state = ParserState::IN_VALUE;
87 case ParserState::IN_TIMESTAMP:
88 match.timestamp = strtoll(cur, &err, 10);
91 state = ParserState::IN_PROVENANCE;
94 case ParserState::IN_PROVENANCE:
95 match.beginProvenance = cur;
96 next = (
char*)memchr(cur,
'\n', s.data() + s.size() - cur);
97 if (next !=
nullptr) {
98 match.endProvenance = next;
99 state = ParserState::DONE;
101 match.endProvenance = s.data() + s.size();
102 state = ParserState::DONE;
105 case ParserState::IN_ERROR:
107 case ParserState::DONE:
117 if (
match.beginKey ==
nullptr ||
match.endKey ==
nullptr ||
118 match.beginValue ==
nullptr ||
match.endValue ==
nullptr ||
119 match.beginProvenance ==
nullptr ||
match.endProvenance ==
nullptr) {
122 auto keyString = std::string(
match.beginKey,
match.endKey -
match.beginKey);
123 auto valueString = std::string(
match.beginValue,
match.endValue -
match.beginValue);
124 auto provenanceString = std::string(
match.beginProvenance,
match.endProvenance -
match.beginProvenance);
125 boost::property_tree::ptree branch;
126 std::stringstream ss{valueString};
128 boost::property_tree::json_parser::read_json(ss, branch);
130 }
catch (boost::exception&) {