xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
xrpld
rpc
json_body.h
1
#pragma once
2
3
#include <xrpl/json/json_value.h>
4
#include <xrpl/json/to_string.h>
5
6
#include <boost/beast/core/multi_buffer.hpp>
7
#include <boost/beast/http/message.hpp>
8
9
#include <
cstddef
>
10
#include <
string
>
11
#include <
type_traits
>
12
#include <
utility
>
13
14
namespace
xrpl
{
15
19
struct
JsonBody
20
{
21
explicit
JsonBody
() =
default
;
22
23
using
value_type
=
json::Value
;
24
25
// NOLINTNEXTLINE(readability-identifier-naming) -- Boost.Beast body concept name
26
class
reader
27
{
28
using
DynamicBufferType
= boost::beast::multi_buffer;
29
30
DynamicBufferType
buffer_
;
31
32
public
:
33
// NOLINTNEXTLINE(readability-identifier-naming) -- Boost.Beast body concept name
34
using
const_buffers_type
= DynamicBufferType::const_buffers_type;
35
36
// NOLINTNEXTLINE(readability-identifier-naming) -- Boost.Beast body concept name
37
using
is_deferred
=
std::false_type
;
38
39
template
<
bool
IsRequest,
class
Fields>
40
explicit
reader
(boost::beast::http::message<IsRequest, JsonBody, Fields>
const
& m)
41
{
42
stream(m.body, [&](
void
const
* data,
std::size_t
n) {
43
buffer_.commit(
44
boost::asio::buffer_copy(buffer_.prepare(n), boost::asio::buffer(data, n)));
45
});
46
}
47
48
void
49
init
(boost::beast::error_code&)
noexcept
50
{
51
}
52
53
// get() must return a boost::optional (not a std::optional) to meet
54
// requirements of a boost::beast::BodyReader.
55
boost::optional<std::pair<const_buffers_type, bool>>
56
get
(boost::beast::error_code& ec)
57
{
58
return
{{
buffer_
.data(),
false
}};
59
}
60
61
void
62
finish
(boost::beast::error_code&)
63
{
64
}
65
};
66
67
// NOLINTNEXTLINE(readability-identifier-naming) -- Boost.Beast body concept name
68
class
writer
69
{
70
std::string
bodyString_
;
71
72
public
:
73
// NOLINTNEXTLINE(readability-identifier-naming) -- Boost.Beast body concept name
74
using
const_buffers_type
= boost::asio::const_buffer;
75
76
template
<
bool
IsRequest,
class
Fields>
77
explicit
writer
(
78
boost::beast::http::header<IsRequest, Fields>
const
& fields,
79
value_type
const
& value)
80
:
bodyString_
(
to_string
(value))
81
{
82
}
83
84
static
void
85
init
(boost::beast::error_code& ec)
86
{
87
ec.assign(0, ec.category());
88
}
89
90
// get() must return a boost::optional (not a std::optional) to meet
91
// requirements of a boost::beast::BodyWriter.
92
boost::optional<std::pair<const_buffers_type, bool>>
93
get
(boost::beast::error_code& ec)
94
{
95
ec.assign(0, ec.category());
96
return
{{
const_buffers_type
{
bodyString_
.data(),
bodyString_
.size()},
false
}};
97
}
98
};
99
};
100
101
}
// namespace xrpl
std::string
json::Value
Represents a JSON value.
Definition
json_value.h:117
xrpl::JsonBody::reader::const_buffers_type
DynamicBufferType::const_buffers_type const_buffers_type
Definition
json_body.h:34
xrpl::JsonBody::reader::is_deferred
std::false_type is_deferred
Definition
json_body.h:37
xrpl::JsonBody::reader::get
boost::optional< std::pair< const_buffers_type, bool > > get(boost::beast::error_code &ec)
Definition
json_body.h:56
xrpl::JsonBody::reader::buffer_
DynamicBufferType buffer_
Definition
json_body.h:30
xrpl::JsonBody::reader::init
void init(boost::beast::error_code &) noexcept
Definition
json_body.h:49
xrpl::JsonBody::reader::finish
void finish(boost::beast::error_code &)
Definition
json_body.h:62
xrpl::JsonBody::reader::reader
reader(boost::beast::http::message< IsRequest, JsonBody, Fields > const &m)
Definition
json_body.h:40
xrpl::JsonBody::reader::DynamicBufferType
boost::beast::multi_buffer DynamicBufferType
Definition
json_body.h:28
xrpl::JsonBody::writer::init
static void init(boost::beast::error_code &ec)
Definition
json_body.h:85
xrpl::JsonBody::writer::writer
writer(boost::beast::http::header< IsRequest, Fields > const &fields, value_type const &value)
Definition
json_body.h:77
xrpl::JsonBody::writer::const_buffers_type
boost::asio::const_buffer const_buffers_type
Definition
json_body.h:74
xrpl::JsonBody::writer::bodyString_
std::string bodyString_
Definition
json_body.h:70
xrpl::JsonBody::writer::get
boost::optional< std::pair< const_buffers_type, bool > > get(boost::beast::error_code &ec)
Definition
json_body.h:93
cstddef
std::false_type
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::to_string
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition
base_uint.h:657
std::size_t
string
xrpl::JsonBody::JsonBody
JsonBody()=default
xrpl::JsonBody::value_type
json::Value value_type
Definition
json_body.h:23
type_traits
utility
Generated by
1.17.0