|
@@ -15,6 +15,10 @@ con_handler::con_handler(
|
|
|
: sock(io_service) {
|
|
|
// disable indentation for json
|
|
|
this->jsonStringBuilder.settings_["indentation"] = "";
|
|
|
+
|
|
|
+ // init reader to parse json
|
|
|
+ Json::CharReaderBuilder builder;
|
|
|
+ jsonReader = std::unique_ptr<Json::CharReader>(builder.newCharReader());
|
|
|
}
|
|
|
|
|
|
con_handler::~con_handler() {}
|
|
@@ -34,11 +38,9 @@ void con_handler::handle_read_version(const boost::system::error_code &err,
|
|
|
// set up json stuff
|
|
|
JSONCPP_STRING err;
|
|
|
Json::Value root;
|
|
|
- Json::CharReaderBuilder builder;
|
|
|
- const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
|
|
|
|
|
|
// parse data
|
|
|
- if (!reader->parse(this->data, this->data + bytes_transferred, &root,
|
|
|
+ if (!this->jsonReader->parse(this->data, this->data + bytes_transferred, &root,
|
|
|
&err)) {
|
|
|
std::cerr << "Json error: " << err << std::endl << "data: " << this->data;
|
|
|
sock.close();
|
|
@@ -79,11 +81,9 @@ void con_handler::handle_read_login(const boost::system::error_code &err,
|
|
|
// set up json stuff
|
|
|
JSONCPP_STRING err;
|
|
|
Json::Value root;
|
|
|
- Json::CharReaderBuilder builder;
|
|
|
- const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
|
|
|
|
|
|
// parse data
|
|
|
- if (!reader->parse(this->data, this->data + bytes_transferred, &root,
|
|
|
+ if (!this->jsonReader->parse(this->data, this->data + bytes_transferred, &root,
|
|
|
&err)) {
|
|
|
std::cerr << "Json error: " << err << std::endl << "data: " << this->data;
|
|
|
sock.close();
|
|
@@ -123,11 +123,9 @@ void con_handler::handle_read_command(const boost::system::error_code &err,
|
|
|
// set up json stuff
|
|
|
JSONCPP_STRING err;
|
|
|
Json::Value root;
|
|
|
- Json::CharReaderBuilder builder;
|
|
|
- const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
|
|
|
|
|
|
// parse data
|
|
|
- if (!reader->parse(this->data, this->data + bytes_transferred, &root,
|
|
|
+ if (!this->jsonReader->parse(this->data, this->data + bytes_transferred, &root,
|
|
|
&err)) {
|
|
|
std::cerr << "Json error: " << err << std::endl << "data: " << this->data;
|
|
|
sock.close();
|