10 #include "rapidjson/error/en.h"
11 #include "rapidjson/stringbuffer.h"
12 #include "rapidjson/writer.h"
23 const rapidjson::Document& message)
const {
24 rapidjson::StringBuffer buffer;
25 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
29 message.Accept(writer);
30 const char* buffer_start = buffer.GetString();
31 return std::make_unique<std::vector<uint8_t>>(
32 buffer_start, buffer_start + buffer.GetSize());
36 const uint8_t* binary_message,
37 const size_t message_size)
const {
38 auto raw_message =
reinterpret_cast<const char*
>(binary_message);
39 auto json_message = std::make_unique<rapidjson::Document>();
40 rapidjson::ParseResult result =
41 json_message->Parse(raw_message, message_size);
42 if (result.IsError()) {
43 std::cerr <<
"Unable to parse JSON message:" << std::endl
44 << rapidjson::GetParseError_En(result.Code()) << std::endl;