| 1 |
#include <json/json.h> |
| 2 |
|
| 3 |
void |
| 4 |
command_parser::on_msg (std::istream &args) |
| 5 |
{ |
| 6 |
if (args.peek () == '[') |
| 7 |
{ |
| 8 |
Json::Reader reader; |
| 9 |
Json::Value msg; |
| 10 |
if (!reader.parse (args, msg, false)) |
| 11 |
throw std::runtime_error ("error parsing input: " + reader.getFormatedErrorMessages ()); |
| 12 |
PARSE_END; |
| 13 |
|
| 14 |
assert (msg.type () == Json::arrayValue); |
| 15 |
emit msg (msg[0u].asUInt (), msg[1u].asString (), msg[2u].asString ()); |
| 16 |
} |
| 17 |
else |
| 18 |
{ |
| 19 |
int level; |
| 20 |
std::string channel; |
| 21 |
std::string msg; |
| 22 |
|
| 23 |
args >> level >> channel; |
| 24 |
while (args.peek () == ' ') |
| 25 |
args.ignore (); |
| 26 |
std::getline (args, msg); |
| 27 |
PARSE_END; |
| 28 |
|
| 29 |
emit msg (level, channel, msg); |
| 30 |
} |
| 31 |
} |