void JsonRpcPrivate::jsonReaderCallback(std::string const & jsonText) { Json::Value request; Json::Value response; Json::Reader reader; bool const success(reader.parse(jsonText, request)); if (!success) { response = parseError(); } else if (request.isObject()) { response = handleObject(request); } else if (request.isArray()) { response = handleArray(request); } else { Json::Value const null; response = invalidRequest(null); } if (!response.isNull()) { try { serializeAndSendJson(response, m_output); } catch (const std::exception &e) { // NOLINT fprintf( stderr, "exception sending response: %s\n", e.what()); } } }
void ParserImpl::handle() { enum json_type type = json_next(_pJSON); switch (type) { case JSON_DONE: return; case JSON_NULL: _pHandler->null(); break; case JSON_TRUE: if (_pHandler) _pHandler->value(true); break; case JSON_FALSE: if (_pHandler) _pHandler->value(false); break; case JSON_NUMBER: { if (_pHandler) { std::string str(json_get_string(_pJSON, NULL)); if (str.find(_decimalPoint) != str.npos || str.find('e') != str.npos || str.find('E') != str.npos) { _pHandler->value(NumberParser::parseFloat(str)); } else { Poco::Int64 val; if (NumberParser::tryParse64(str, val)) _pHandler->value(val); else _pHandler->value(NumberParser::parseUnsigned64(str)); } } break; } case JSON_STRING: if (_pHandler) _pHandler->value(std::string(json_get_string(_pJSON, NULL))); break; case JSON_OBJECT: if (_pHandler) _pHandler->startObject(); handleObject(); break; case JSON_OBJECT_END: if (_pHandler) _pHandler->endObject(); return; case JSON_ARRAY: if (_pHandler) _pHandler->startArray(); handleArray(); break; case JSON_ARRAY_END: if (_pHandler) _pHandler->endArray(); return; case JSON_ERROR: { const char* pErr = json_get_error(_pJSON); std::string err(pErr ? pErr : "JSON parser error."); throw JSONException(err); } } }