Boost logo

Boost Users :

From: Richard Hodges (hodges.r_at_[hidden])
Date: 2020-12-22 20:34:58


On Tue, 22 Dec 2020 at 21:25, Richard Hodges <hodges.r_at_[hidden]> wrote:

>
>
> On Tue, 22 Dec 2020 at 21:21, Sean Farrow via Boost-users <
> boost-users_at_[hidden]> wrote:
>
>> Hi,
>>
>>
>>
>> Are there any samples of using boost.json to deserialize boost.beast
>> responses?
>>
>
> Not in the documentation of the two libraries as they are treated as
> separate self-contained concerns.
>
> However it’s quite trivial.
>

Here's a simple example:

extern void use_json(boost::json::value const& jv);

void handle_read_text(boost::beast::flat_buffer& buf)
{
    auto range = buf.data();
    auto chars = boost::json::string_view(
        reinterpret_cast<const char*>(range.data()),
        range.size());
    auto dom = boost::json::parse(chars);
    use_json(dom);
}

https://godbolt.org/z/bxcKea

The maintainers of beast and json are always available on the cpplang
slack, in channel #beast.

The data() member of a flat_buffer contains a pointer and a size. Cast the
> pointer to const char * and use it and the size to construct a
> json::string_view.
> From there you can call json::parse to get your json::value.
>
> Thanks,
>>
>> Sean.
>> _______________________________________________
>> Boost-users mailing list
>> Boost-users_at_[hidden]
>> https://lists.boost.org/mailman/listinfo.cgi/boost-users
>>
> --
> Richard Hodges
> hodges.r_at_[hidden]
> office: +442032898513
> home: +376841522
> mobile: +376380212
>
>

-- 
Richard Hodges
hodges.r_at_[hidden]
office: +442032898513
home: +376841522
mobile: +376380212


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net