Add byte_stream for zero-copy serialization, and add support in ZMQ-JSON.

This commit is contained in:
Lee Clagett
2020-03-18 23:22:39 +00:00
parent 8185054db7
commit c26c93019a
14 changed files with 806 additions and 171 deletions

View File

@@ -62,7 +62,7 @@ const rapidjson::Value& get_method_field(const rapidjson::Value& src)
}
}
void Message::toJson(rapidjson::Writer<rapidjson::StringBuffer>& dest) const
void Message::toJson(rapidjson::Writer<epee::byte_stream>& dest) const
{
dest.StartObject();
INSERT_INTO_JSON_OBJECT(dest, status, status);
@@ -151,9 +151,9 @@ cryptonote::rpc::error FullMessage::getError()
epee::byte_slice FullMessage::getRequest(const std::string& request, const Message& message, const unsigned id)
{
rapidjson::StringBuffer buffer;
epee::byte_stream buffer;
{
rapidjson::Writer<rapidjson::StringBuffer> dest{buffer};
rapidjson::Writer<epee::byte_stream> dest{buffer};
dest.StartObject();
INSERT_INTO_JSON_OBJECT(dest, jsonrpc, (boost::string_ref{"2.0", 3}));
@@ -172,15 +172,15 @@ epee::byte_slice FullMessage::getRequest(const std::string& request, const Messa
if (!dest.IsComplete())
throw std::logic_error{"Invalid JSON tree generated"};
}
return epee::byte_slice{{buffer.GetString(), buffer.GetSize()}};
return epee::byte_slice{std::move(buffer)};
}
epee::byte_slice FullMessage::getResponse(const Message& message, const rapidjson::Value& id)
{
rapidjson::StringBuffer buffer;
epee::byte_stream buffer;
{
rapidjson::Writer<rapidjson::StringBuffer> dest{buffer};
rapidjson::Writer<epee::byte_stream> dest{buffer};
dest.StartObject();
INSERT_INTO_JSON_OBJECT(dest, jsonrpc, (boost::string_ref{"2.0", 3}));
@@ -207,7 +207,7 @@ epee::byte_slice FullMessage::getResponse(const Message& message, const rapidjso
if (!dest.IsComplete())
throw std::logic_error{"Invalid JSON tree generated"};
}
return epee::byte_slice{{buffer.GetString(), buffer.GetSize()}};
return epee::byte_slice{std::move(buffer)};
}
// convenience functions for bad input