MPD  0.20.15
Public Member Functions
DecoderBuffer Class Reference

This objects handles buffered reads in decoder plugins easily. More...

#include <DecoderBuffer.hxx>

Public Member Functions

 DecoderBuffer (DecoderClient *_client, InputStream &_is, size_t _size)
 Creates a new buffer. More...
 
const InputStreamGetStream () const noexcept
 
void Clear () noexcept
 
bool Fill ()
 Read data from the InputStream and append it to the buffer. More...
 
gcc_pure size_t GetAvailable () const noexcept
 How many bytes are stored in the buffer? More...
 
ConstBuffer< void > Read () const noexcept
 Reads data from the buffer. More...
 
ConstBuffer< void > Need (size_t min_size)
 Wait until this number of bytes are available. More...
 
void Consume (size_t nbytes) noexcept
 Consume (delete, invalidate) a part of the buffer. More...
 
bool Skip (size_t nbytes)
 Skips the specified number of bytes, discarding its data. More...
 

Detailed Description

This objects handles buffered reads in decoder plugins easily.

You create a buffer object, and use its high-level methods to fill and read it. It will automatically handle shifting the buffer.

Definition at line 38 of file DecoderBuffer.hxx.

Constructor & Destructor Documentation

◆ DecoderBuffer()

DecoderBuffer::DecoderBuffer ( DecoderClient _client,
InputStream _is,
size_t  _size 
)
inline

Creates a new buffer.

Parameters
_clientthe decoder client, used for decoder_read(), may be nullptr
_isthe input stream object where we should read from
_sizethe maximum size of the buffer

Definition at line 53 of file DecoderBuffer.hxx.

Member Function Documentation

◆ Clear()

void DecoderBuffer::Clear ( )
inlinenoexcept

Definition at line 61 of file DecoderBuffer.hxx.

◆ Consume()

void DecoderBuffer::Consume ( size_t  nbytes)
inlinenoexcept

Consume (delete, invalidate) a part of the buffer.

The "nbytes" parameter must not be larger than the length returned by Read().

Parameters
nbytesthe number of bytes to consume

Definition at line 105 of file DecoderBuffer.hxx.

◆ Fill()

bool DecoderBuffer::Fill ( )

Read data from the InputStream and append it to the buffer.

Returns
true if data was appended; false if there is no data available (yet), end of file, I/O error or a decoder command was received

◆ GetAvailable()

gcc_pure size_t DecoderBuffer::GetAvailable ( ) const
inlinenoexcept

How many bytes are stored in the buffer?

Definition at line 78 of file DecoderBuffer.hxx.

◆ GetStream()

const InputStream& DecoderBuffer::GetStream ( ) const
inlinenoexcept

Definition at line 57 of file DecoderBuffer.hxx.

◆ Need()

ConstBuffer<void> DecoderBuffer::Need ( size_t  min_size)

Wait until this number of bytes are available.

Returns nullptr on error.

◆ Read()

ConstBuffer<void> DecoderBuffer::Read ( ) const
inlinenoexcept

Reads data from the buffer.

This data is not yet consumed, you have to call Consume() to do that. The returned buffer becomes invalid after a Fill() or a Consume() call.

Definition at line 87 of file DecoderBuffer.hxx.

◆ Skip()

bool DecoderBuffer::Skip ( size_t  nbytes)

Skips the specified number of bytes, discarding its data.

Parameters
nbytesthe number of bytes to skip
Returns
true on success, false on error

The documentation for this class was generated from the following file: