MCPcopy Create free account
hub / github.com/boostorg/cobalt / json_reader

Function json_reader

example/ticker.cpp:72–90  ·  view source on GitHub ↗

tag::json_reader[]

Source from the content-addressed store, hash-verified

70
71// tag::json_reader[]
72cobalt::generator<json::object> json_reader(websocket_type & ws)
73try
74{
75 beast::flat_buffer buf;
76 while (ws.is_open()) // <1>
77 {
78 auto sz = co_await ws.async_read(buf); // <2>
79 json::string_view data{static_cast<const char*>(buf.cdata().data()), sz};
80 auto obj = json::parse(data);
81 co_yield obj.as_object(); // <3>
82 buf.consume(sz);
83 }
84 co_return {};
85}
86catch (std::exception & e)
87{
88 std::cerr << "Error reading: " << e.what() << std::endl;
89 throw;
90}
91// end::json_reader[]
92
93// tag::subscription_types[]

Callers 1

run_blockchain_infoFunction · 0.85

Calls 3

dataMethod · 0.80
whatMethod · 0.80
is_openMethod · 0.45

Tested by

no test coverage detected