Apache Arrow (C++)
A columnar in-memory analytics layer designed to accelerate big data.
Public Member Functions | List of all members
arrow::BitWriter Class Reference

Utility class to write bit/byte streams. More...

#include <arrow/util/bit-stream-utils.h>

Public Member Functions

 BitWriter (uint8_t *buffer, int buffer_len)
 buffer: buffer to write bits to. More...
 
void Clear ()
 
int bytes_written () const
 The number of current bytes written, including the current byte (i.e. More...
 
uint8_t * buffer () const
 
int buffer_len () const
 
bool PutValue (uint64_t v, int num_bits)
 Writes a value to buffered_values_, flushing to buffer_ if necessary. More...
 
template<typename T >
bool PutAligned (T v, int num_bytes)
 Writes v to the next aligned byte using num_bytes. More...
 
bool PutVlqInt (uint32_t v)
 Write a Vlq encoded int to the buffer. More...
 
bool PutZigZagVlqInt (int32_t v)
 
uint8_t * GetNextBytePtr (int num_bytes=1)
 Get a pointer to the next aligned byte and advance the underlying buffer by num_bytes. More...
 
void Flush (bool align=false)
 Flushes all buffered values to the buffer. More...
 

Detailed Description

Utility class to write bit/byte streams.

This class can write data to either be bit packed or byte aligned (and a single stream that has a mix of both). This class does not allocate memory.

Constructor & Destructor Documentation

◆ BitWriter()

arrow::BitWriter::BitWriter ( uint8_t *  buffer,
int  buffer_len 
)
inline

buffer: buffer to write bits to.

Buffer should be preallocated with 'buffer_len' bytes.

Member Function Documentation

◆ buffer()

uint8_t* arrow::BitWriter::buffer ( ) const
inline

◆ buffer_len()

int arrow::BitWriter::buffer_len ( ) const
inline

◆ bytes_written()

int arrow::BitWriter::bytes_written ( ) const
inline

The number of current bytes written, including the current byte (i.e.

may include a fraction of a byte). Includes buffered values.

◆ Clear()

void arrow::BitWriter::Clear ( )
inline

◆ Flush()

void arrow::BitWriter::Flush ( bool  align = false)
inline

Flushes all buffered values to the buffer.

Call this when done writing to the buffer. If 'align' is true, buffered_values_ is reset and any future writes will be written to the next byte boundary.

◆ GetNextBytePtr()

uint8_t * arrow::BitWriter::GetNextBytePtr ( int  num_bytes = 1)
inline

Get a pointer to the next aligned byte and advance the underlying buffer by num_bytes.

Returns NULL if there was not enough space.

◆ PutAligned()

template<typename T >
bool arrow::BitWriter::PutAligned ( v,
int  num_bytes 
)
inline

Writes v to the next aligned byte using num_bytes.

If T is larger than num_bytes, the extra high-order bytes will be ignored. Returns false if there was not enough space.

◆ PutValue()

bool arrow::BitWriter::PutValue ( uint64_t  v,
int  num_bits 
)
inline

Writes a value to buffered_values_, flushing to buffer_ if necessary.

This is bit packed. Returns false if there was not enough space. num_bits must be <= 32.

◆ PutVlqInt()

bool arrow::BitWriter::PutVlqInt ( uint32_t  v)
inline

Write a Vlq encoded int to the buffer.

Returns false if there was not enough room. The value is written byte aligned. For more details on vlq: en.wikipedia.org/wiki/Variable-length_quantity

◆ PutZigZagVlqInt()

bool arrow::BitWriter::PutZigZagVlqInt ( int32_t  v)
inline

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