Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
impala::BitReader Class Reference

#include <bit-stream-utils.h>

Collaboration diagram for impala::BitReader:

Public Member Functions

 BitReader (uint8_t *buffer, int buffer_len)
 'buffer' is the buffer to read from. The buffer's length is 'buffer_len'. More...
 
 BitReader ()
 
template<typename T >
bool GetValue (int num_bits, T *v)
 
template<typename T >
bool GetAligned (int num_bytes, T *v)
 
bool GetVlqInt (int32_t *v)
 
int bytes_left ()
 

Static Public Attributes

static const int MAX_VLQ_BYTE_LEN = 5
 Maximum byte length of a vlq encoded int. More...
 

Private Attributes

uint8_t * buffer_
 
int max_bytes_
 
uint64_t buffered_values_
 
int byte_offset_
 
int bit_offset_
 

Detailed Description

Utility class to read bit/byte stream. This class can read bits or bytes that are either byte aligned or not. It also has utilities to read multiple bytes in one read (e.g. encoded int).

Definition at line 92 of file bit-stream-utils.h.

Constructor & Destructor Documentation

impala::BitReader::BitReader ( uint8_t *  buffer,
int  buffer_len 
)
inline

'buffer' is the buffer to read from. The buffer's length is 'buffer_len'.

Definition at line 95 of file bit-stream-utils.h.

References buffer_, buffered_values_, byte_offset_, and max_bytes_.

impala::BitReader::BitReader ( )
inline

Definition at line 104 of file bit-stream-utils.h.

Member Function Documentation

int impala::BitReader::bytes_left ( )
inline

Returns the number of bytes left in the stream, not including the current byte (i.e., there may be an additional fraction of a byte).

Definition at line 124 of file bit-stream-utils.h.

References bit_offset_, byte_offset_, impala::BitUtil::Ceil(), and max_bytes_.

template<typename T >
bool impala::BitReader::GetAligned ( int  num_bytes,
T *  v 
)
inline

Reads a 'num_bytes'-sized value from the buffer and stores it in 'v'. T needs to be a little-endian native type and big enough to store 'num_bytes'. The value is assumed to be byte-aligned so the stream will be advanced to the start of the next byte before 'v' is read. Returns false if there are not enough bytes left.

Definition at line 115 of file bit-stream-utils.inline.h.

References bit_offset_, buffer_, buffered_values_, byte_offset_, impala::BitUtil::Ceil(), LIKELY, max_bytes_, and UNLIKELY.

Referenced by impala::RleDecoder::Get().

template<typename T >
bool impala::BitReader::GetValue ( int  num_bits,
T *  v 
)
inline

Gets the next value from the buffer. Returns true if 'v' could be read or false if there are not enough bytes left. num_bits must be <= 32.

Definition at line 85 of file bit-stream-utils.inline.h.

References bit_offset_, buffer_, buffered_values_, byte_offset_, LIKELY, max_bytes_, impala::BitUtil::TrailingBits(), and UNLIKELY.

Referenced by impala::RleDecoder::Get(), impala::HdfsParquetScanner::BoolColumnReader::ReadSlot(), impala::TEST(), and TestBitWriterDecode().

bool impala::BitReader::GetVlqInt ( int32_t *  v)
inline

Reads a vlq encoded int from the stream. The encoded int must start at the beginning of a byte. Return false if there were not enough bytes in the buffer.

Definition at line 136 of file bit-stream-utils.inline.h.

References MAX_VLQ_BYTE_LEN.

Referenced by impala::RleDecoder::Get().

Member Data Documentation

int impala::BitReader::bit_offset_
private

Definition at line 138 of file bit-stream-utils.h.

Referenced by bytes_left(), GetAligned(), and GetValue().

uint8_t* impala::BitReader::buffer_
private

Definition at line 130 of file bit-stream-utils.h.

Referenced by BitReader(), GetAligned(), and GetValue().

uint64_t impala::BitReader::buffered_values_
private

Bytes are memcpy'd from buffer_ and values are read from this variable. This is faster than reading values byte by byte directly from buffer_.

Definition at line 135 of file bit-stream-utils.h.

Referenced by BitReader(), GetAligned(), and GetValue().

int impala::BitReader::byte_offset_
private

Definition at line 137 of file bit-stream-utils.h.

Referenced by BitReader(), bytes_left(), GetAligned(), and GetValue().

int impala::BitReader::max_bytes_
private

Definition at line 131 of file bit-stream-utils.h.

Referenced by BitReader(), bytes_left(), GetAligned(), and GetValue().

const int impala::BitReader::MAX_VLQ_BYTE_LEN = 5
static

Maximum byte length of a vlq encoded int.

Definition at line 127 of file bit-stream-utils.h.

Referenced by GetVlqInt(), and impala::RleEncoder::MinBufferSize().


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