template<typename Type_>
class byteme::BufferedReader< Type_ >
Buffered wrapper around a Reader.
- Template Parameters
-
| Type_ | Type of the output bytes, usually char for text or unsigned char for binary. |
In some applications, we may need to iterate over many small chunks of bytes or even individual bytes. Naively calling Reader::read() for each request may be inefficient if the underlying implementation attempts to read from some storage device for each call. Instead, we can wrap our Reader in a BufferedReader instance, which calls Reader::read() every now and then to fill a large intermediate buffer. Users can then iterate that buffer to obtain the next byte or chunk of bytes, reducing the number of separate calls to Reader::read().
Check out SerialBufferedReader and ParallelBufferedReader for subclasses.
template<typename Type_ >
| std::pair< std::size_t, bool > byteme::BufferedReader< Type_ >::extract |
( |
std::size_t | number, |
|
|
Type_ * | output ) |
|
inline |
Extract up to number bytes from the buffer and store them in the output. This is equivalent to (but more efficient than) calling get() and then advance() up to number times, only iterating while the return value of advance() is still true. Users should only call this method if valid() is still true.
- Parameters
-
| number | Number of bytes to extract. |
| [out] | output | Pointer to an output buffer of length number. This is filled with up to number bytes from the source. |
- Returns
- Pair containing:
- The number of bytes that were successfully read into
output. This can also be interpreted as the number of successful get()/advance() iterations.
- Wether there are any more bytes available in the source for future
get() or extract() calls. This can also be interpreted as the result of the final advance() (i.e., the result of the valid() after extract() returns).
If the first element is less than number, it can be assumed that no more bytes are available in the source (i.e., the second element must be false). Note that the converse is not true as it is possible to read number bytes and finish the source at the same time.