8 #include <jsonrpc-lean/server.h> 15 template <
typename Cb>
19 rapidjson::MemoryStream
stream{
nullptr, 0};
23 bool parse(std::string_view request) {
24 stream = {request.data(), request.size()};
25 rapidjson::Reader reader;
26 return reader.Parse(
stream, *
this);
56 bool String(
const char *,
size_t,
bool) {
59 bool Key(
const char *,
size_t,
bool) {
86 const size_t end =
stream.Tell();
87 std::string_view request(
stream.begin_ + begin, end - begin);
95 std::string_view request) {
96 std::string request_string;
97 if (!request.empty() && request[0] ==
'[') {
98 const auto cb = [&](std::string_view request) {
99 request_string = request;
100 auto formatted = handler.HandleRequest(request_string);
101 if (formatted->GetSize() == 0) {
104 if (batch_.empty()) {
105 batch_.push_back(
'[');
107 batch_.push_back(
',');
109 batch_.append(formatted->GetData(), formatted->GetSize());
112 if (parser.parse(request)) {
113 if (!batch_.empty()) {
114 batch_.push_back(
']');
119 request_string = request;
120 formatted_ = handler.HandleRequest(request_string);
124 if (formatted_ ==
nullptr) {
127 return {formatted_->GetData(), formatted_->GetSize()};
bool Key(const char *, size_t, bool)
bool RawNumber(const char *, size_t, bool)
std::string_view response() const
bool parse(std::string_view request)
bool String(const char *, size_t, bool)
rapidjson::MemoryStream stream
JrpcHandleBatch(jsonrpc::Server &handler, std::string_view request)