So I am using boost::beast as a WebSocket server. I would like to receive a binary message and parse it using nlohmann::json. However I get an error message:
none of the 3 overloads can convert parameter "nlohmann::detail::input_adapter"
Here is some code:
boost::beast::flat_buffer buffer;
ws.read(buffer);
if (!ws.got_text()) {
ws.text(false);
json request = json::from_msgpack(msgpack);
ws.write( json::to_msgpack(request) ); // echo request back
}
If I try to static cast into a std::vector I get: E0312 / no suitable user-defined conversion
boost::beast::flat_buffer buffer;
ws.read(buffer);
if (!ws.got_text()) {
ws.text(false);
boost::asio::mutable_buffer req = buffer.data();
//unsigned char* req2 = static_cast<unsigned char*>(req); // does not work
//std::vector<std::uint8_t> req2 = static_cast<std::vector<std::uint8_t>>(req); // does not work
json request = json::from_msgpack(buffer.data());
ws.write(boost::asio::buffer(json::to_msgpack(request)));
}
How can I get the binary data out of the buffer so that nkohman::json can parse it?
json::parse((char*)req.data(), (chjar*)req.data+req.size())
? – Selfpossession