...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
A BodyReader provides an online algorithm
to transfer a series of zero or more buffers containing parsed body octets
into a message container. The parser
creates an instance of this
type when needed, and calls into it zero or more times to transfer buffers.
The interface of BodyReader is intended
to allow the conversion of buffers into these scenarios for representation:
Warning | |
---|---|
These requirements may undergo non-backward compatible changes in subsequent versions. |
In this table:
R
denotes a type meeting
the requirements of BodyReader.
B
denotes a Body
where std::is_same<R, B::reader>::value ==
true
.
a
denotes a value of
type R
.
b
is an object whose
type meets the requirements of ConstBufferSequence
h
denotes a value of
type header<isRequest,
Fields>&
.
v
denotes a value of
type Body::value_type&
.
n
is a value of type
boost::optional<std::uint64_t>
.
ec
is a value of type
error_code&
.
Table 1.37. Valid expressions
Expression |
Type |
Semantics, Pre/Post-conditions |
---|---|---|
|
Constructible from |
|
|
Called once to fully initialize the object before any calls to
The function will ensure that |
|
|
|
This function is called to append some or all of the buffers specified
by |
|
This function is called when no more body octets are remaining.
The function will ensure that |
|
|
|
An alias for |
struct BodyReader { /** Construct the reader. @param h The header for the message being parsed @param body The body to store the parsed results into */ template<bool isRequest, class Fields> BodyReader(header<isRequest, Fields>& h, value_type& body); /** Initialize the reader. This is called after construction and before the first call to `put`. The message is valid and complete upon entry. @param ec Set to the error, if any occurred. */ void init( boost::optional<std::uint64_t> const& content_length, error_code& ec) { boost::ignore_unused(content_length); // The specification requires this to indicate "no error" ec = {}; } /** Store buffers. This is called zero or more times with parsed body octets. @param buffers The constant buffer sequence to store. @param ec Set to the error, if any occurred. @return The number of bytes transferred from the input buffers. */ template<class ConstBufferSequence> std::size_t put(ConstBufferSequence const& buffers, error_code& ec) { // The specification requires this to indicate "no error" ec = {}; return buffer_bytes(buffers); } /** Called when the body is complete. @param ec Set to the error, if any occurred. */ void finish(error_code& ec) { // The specification requires this to indicate "no error" ec = {}; } };