...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
A BuffersGenerator provides a generalized interface for generating serialized data for sequential processing.
The generator will be asked to produce buffers. The consuming code will signal how much of the data has been consumed, and repeatedly query for buffers until no more data is available, or the generator indicates an error condition.
In this way, serializers can be adapted as BuffersGenerator,
for example http::message_generator
which provides
a type-erased interface for a variety of concrete http message types.
Overloads of write
and async_write
operations are provided
as free functions. These operations will consume the output of a BuffersGenerator and process the data by writing them
to a SyncWriteStream
or AsyncWriteStream
respectively.
In this table:
G
denotes a type meeting
the requirements of BuffersGenerator.
g
denotes a value of
type G
.
c
denotes a possibly-const
value of type G
.
n
is a value of type
std::size_t
.
ec
is a value of type
error_code&
.
Table 1.41. Valid expressions
Expression |
Type |
Semantics, Pre/Post-conditions |
---|---|---|
|
A type which meets the requirements of ConstBufferSequence.
This is the type of buffer returned by |
|
|
|
Called to ask the generator for its completion status. A generator has completed when no new buffer will be produced and previously produced buffers have been fully consumed.
Note: The result of invoking
|
|
|
Called to ask the generator to produce buffers containing data for processing. The returned value is the ConstBufferSequence representing unconsumed data.
The function will ensure that If no unconsumed data is available, this operation shall make progress to eventually reach completion.
The result of invoking The capacity of the buffer returned is defined by the generator implementation.
Note: Any buffers obtained by
previous calls to |
|
This function is called to signal that the consumer (caller) of
the generator has processed part of the data returned by the previous
call to
The value of
When
Remaining unconsumed data will be returned from subsequent calls
to
Note: Any buffers obtained by
previous calls to |
|
|
|
An alias for |
// A buffer sequence generator struct BuffersGenerator { using const_buffers_type = net::const_buffer; bool is_done() const; const_buffers_type prepare( error_code& ec ); void consume( std::size_t n ); }; static_assert( is_buffers_generator<BuffersGenerator>::value, "");