Thrill  0.1
BufferReader Class Reference

Detailed Description

BufferReader represents a BufferRef with an additional cursor with which the memory can be read incrementally.

Definition at line 34 of file buffer_reader.hpp.

+ Inheritance diagram for BufferReader:
+ Collaboration diagram for BufferReader:

#include <buffer_reader.hpp>

Public Member Functions

Construction
 BufferReader (const BufferRef &br)
 Constructor, assign memory area from BinaryBuilder. More...
 
 BufferReader (const void *data, size_t n)
 Constructor, assign memory area from pointer and length. More...
 
 BufferReader (const std::string &str)
 Constructor, assign memory area from string, does NOT copy. More...
 
Size Accessors
size_t cursor () const
 Return the current read cursor. More...
 
bool available (size_t size) const
 Return the number of bytes still available at the cursor. More...
 
bool empty () const
 Return true if the cursor is at the end of the buffer. More...
 
size_t Size () const
 
bool IsNull () const
 Indicates if the reader was initialized with a nullptr and size 0. More...
 
Cursor Movement and Checks
BufferReaderRewind ()
 Reset the read cursor. More...
 
void CheckAvailable (size_t n) const
 
BufferReaderSkip (size_t n)
 Advance the cursor given number of bytes without reading them. More...
 
Cursor Reading Methods
BufferReaderRead (void *outdata, size_t datalen)
 
std::string Read (size_t datalen)
 
template<typename Type >
Type Get ()
 
Byte GetByte ()
 Fetch a single byte from the buffer, advancing the cursor. More...
 
template<typename Type >
Type GetRaw ()
 
BufferRef GetBufferRef ()
 
- Public Member Functions inherited from BufferRef
 BufferRef (const BufferBuilder &bb)
 Constructor, assign memory area from BufferBuilder. More...
 
 BufferRef (const void *data, size_t size)
 Constructor, assign memory area from pointer and length. More...
 
 BufferRef (const std::string &str)
 Constructor, assign memory area from string, does NOT copy. More...
 
 BufferRef (const Buffer &b)
 Constructor, assign memory area from net::Buffer, does NOT copy! More...
 
const void * data () const
 Return a pointer to the currently kept memory area. More...
 
bool operator!= (const BufferRef &br) const noexcept
 Compare contents of two BufferRefs. More...
 
bool operator== (const BufferRef &br) const noexcept
 Compare contents of two BufferRefs. More...
 
size_t size () const
 Return the currently valid length in bytes. More...
 
Buffer ToBuffer ()
 Explicit conversion to Buffer MOVING the memory ownership. More...
 
std::string ToString () const
 Explicit conversion to std::string (copies memory of course). More...
 
- Public Member Functions inherited from ItemReaderToolsBase< BufferReader >
std::string GetString ()
 Fetch a string which was Put via Put_string(). More...
 
uint64_t GetVarint ()
 Fetch a 64-bit varint from the reader at the cursor. More...
 
uint32_t GetVarint32 ()
 Fetch a varint with up to 32-bit from the reader at the cursor. More...
 
uint32_t PeekVarint32 () const
 Fetch a varint with up to 32-bit from the reader at the cursor. More...
 

Private Attributes

size_t cursor_ = 0
 Current read cursor. More...
 

Additional Inherited Members

- Protected Types inherited from BufferRef
using Byte = unsigned char
 type used to store the bytes More...
 
- Protected Attributes inherited from BufferRef
const Bytedata_
 Allocated buffer pointer. More...
 
size_t size_
 Size of valid data. More...
 

Constructor & Destructor Documentation

◆ BufferReader() [1/3]

BufferReader ( const BufferRef br)
inline

Constructor, assign memory area from BinaryBuilder.

Definition at line 47 of file buffer_reader.hpp.

◆ BufferReader() [2/3]

BufferReader ( const void *  data,
size_t  n 
)
inline

Constructor, assign memory area from pointer and length.

Definition at line 52 of file buffer_reader.hpp.

◆ BufferReader() [3/3]

BufferReader ( const std::string &  str)
inlineexplicit

Constructor, assign memory area from string, does NOT copy.

Definition at line 57 of file buffer_reader.hpp.

Member Function Documentation

◆ available()

bool available ( size_t  size) const
inline

Return the number of bytes still available at the cursor.

Definition at line 72 of file buffer_reader.hpp.

References BufferRef::size_.

Referenced by BufferReader::CheckAvailable().

◆ CheckAvailable()

void CheckAvailable ( size_t  n) const
inline

Throws a std::underflow_error unless n bytes are available at the cursor.

Definition at line 103 of file buffer_reader.hpp.

References BufferReader::available().

Referenced by BufferReader::Get(), BufferReader::Read(), and BufferReader::Skip().

◆ cursor()

size_t cursor ( ) const
inline

Return the current read cursor.

Definition at line 67 of file buffer_reader.hpp.

References BufferReader::cursor_.

◆ empty()

bool empty ( ) const
inline

Return true if the cursor is at the end of the buffer.

Definition at line 77 of file buffer_reader.hpp.

References BufferRef::size_.

◆ Get()

Type Get ( )
inline

Fetch a single item of the template type Type from the buffer, advancing the cursor. Be careful with implicit type conversions!

Definition at line 146 of file buffer_reader.hpp.

References BufferReader::CheckAvailable(), BufferReader::cursor_, and BufferRef::data_.

Referenced by StreamMultiplexerHeader::Parse(), and PartitionMultiplexerHeader::Parse().

◆ GetBufferRef()

BufferRef GetBufferRef ( )
inline

Fetch a BufferRef to a binary string or blob which was Put via Put_string(). Does NOT copy the data.

Definition at line 173 of file buffer_reader.hpp.

References BufferRef::data_, ItemReaderToolsBase< BufferReader >::GetVarint(), and BufferReader::Skip().

◆ GetByte()

Byte GetByte ( )
inline

Fetch a single byte from the buffer, advancing the cursor.

Definition at line 160 of file buffer_reader.hpp.

◆ GetRaw()

Type GetRaw ( )
inline

Fetch a single item of the template type Type from the buffer, advancing the cursor. Be careful with implicit type conversions!

Definition at line 167 of file buffer_reader.hpp.

◆ IsNull()

bool IsNull ( ) const
inline

Indicates if the reader was initialized with a nullptr and size 0.

Definition at line 86 of file buffer_reader.hpp.

References BufferRef::data_.

◆ Read() [1/2]

BufferReader& Read ( void *  outdata,
size_t  datalen 
)
inline

Fetch a number of unstructured bytes from the buffer, advancing the cursor.

Definition at line 123 of file buffer_reader.hpp.

References BufferReader::CheckAvailable(), and BufferRef::data_.

◆ Read() [2/2]

std::string Read ( size_t  datalen)
inline

Fetch a number of unstructured bytes from the buffer as std::string, advancing the cursor.

Definition at line 135 of file buffer_reader.hpp.

References BufferReader::CheckAvailable(), and BufferRef::data_.

◆ Rewind()

BufferReader& Rewind ( )
inline

Reset the read cursor.

Definition at line 96 of file buffer_reader.hpp.

◆ Size()

size_t Size ( ) const
inline

Definition at line 81 of file buffer_reader.hpp.

References BufferRef::size_.

◆ Skip()

BufferReader& Skip ( size_t  n)
inline

Advance the cursor given number of bytes without reading them.

Definition at line 109 of file buffer_reader.hpp.

References BufferReader::CheckAvailable().

Referenced by BufferReader::GetBufferRef().

Member Data Documentation

◆ cursor_

size_t cursor_ = 0
private

Current read cursor.

Definition at line 40 of file buffer_reader.hpp.

Referenced by BufferReader::cursor(), and BufferReader::Get().


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