Gnash  0.8.11dev
Public Types | Public Member Functions | List of all members
gnash::BitsReader Class Reference

BitsReader is used to encapsulate bit-packed buffer reads. More...

#include <BitsReader.h>

Public Types

typedef unsigned char byte
 

Public Member Functions

 BitsReader (const byte *input, size_t len)
 Ownership of buffer left to caller. More...
 
 BitsReader (const BitsReader &from, size_t len)
 Create a BitsReader reading a subset of another. More...
 
 ~BitsReader ()
 
size_t size () const
 
void setBuffer (byte *input, size_t len)
 Set a new buffer to work with. More...
 
unsigned read_uint (unsigned short bitcount)
 Reads a bit-packed unsigned integer from the stream and returns it. The given bitcount determines the number of bits to read. More...
 
bool read_bit ()
 Reads a single bit off the stream and returns it. More...
 
std::int32_t read_sint (unsigned short bitcount)
 Reads a bit-packed little-endian signed integer from the stream. The given bitcount determines the number of bits to read. More...
 
std::uint8_t read_u8 ()
 Read a byte as an unsigned int (aligned) More...
 
std::int8_t read_s8 ()
 Read one bytes as a signed int (aligned) More...
 
std::uint16_t read_u16 ()
 Read two bytes as an unsigned int (aligned) More...
 
std::int16_t read_s16 ()
 Read two bytes as a signed int (aligned) More...
 
std::uint32_t read_u32 ()
 Read four bytes as an unsigned int (aligned) More...
 
std::int32_t read_s32 ()
 Read four bytes as an signed int (aligned) More...
 
void align ()
 Discard any unused bit in the current byte and advance to next. More...
 
bool gotBits (std::uint32_t nbits) const
 Checks if the stream contains X bits. More...
 

Detailed Description

BitsReader is used to encapsulate bit-packed buffer reads.

TODO: implement boundary checking, maybe by throwing an exception when attempts are made to read past end of buffer

Member Typedef Documentation

§ byte

typedef unsigned char gnash::BitsReader::byte

Constructor & Destructor Documentation

§ BitsReader() [1/2]

gnash::BitsReader::BitsReader ( const byte input,
size_t  len 
)
inline

Ownership of buffer left to caller.

§ BitsReader() [2/2]

gnash::BitsReader::BitsReader ( const BitsReader from,
size_t  len 
)
inline

Create a BitsReader reading a subset of another.

The starting pointer will be taken from the parent reader cursor, including used bits, use align() if need to discard the left over ones.

length will be given explicitly.

§ ~BitsReader()

gnash::BitsReader::~BitsReader ( )
inline

Member Function Documentation

§ align()

void gnash::BitsReader::align ( )
inline

Discard any unused bit in the current byte and advance to next.

§ gotBits()

bool gnash::BitsReader::gotBits ( std::uint32_t  nbits) const
inline

Checks if the stream contains X bits.

References _, gnash::image::end(), gnash::log_debug(), and start.

§ read_bit()

bool gnash::BitsReader::read_bit ( )

Reads a single bit off the stream and returns it.

§ read_s16()

std::int16_t gnash::BitsReader::read_s16 ( )
inline

Read two bytes as a signed int (aligned)

§ read_s32()

std::int32_t gnash::BitsReader::read_s32 ( )
inline

Read four bytes as an signed int (aligned)

§ read_s8()

std::int8_t gnash::BitsReader::read_s8 ( )
inline

Read one bytes as a signed int (aligned)

§ read_sint()

std::int32_t gnash::BitsReader::read_sint ( unsigned short  bitcount)

Reads a bit-packed little-endian signed integer from the stream. The given bitcount determines the number of bits to read.

References read_uint().

§ read_u16()

std::uint16_t gnash::BitsReader::read_u16 ( )
inline

Read two bytes as an unsigned int (aligned)

References gnash::image::end().

§ read_u32()

std::uint32_t gnash::BitsReader::read_u32 ( )
inline

Read four bytes as an unsigned int (aligned)

References gnash::image::end().

§ read_u8()

std::uint8_t gnash::BitsReader::read_u8 ( )
inline

Read a byte as an unsigned int (aligned)

§ read_uint()

unsigned gnash::BitsReader::read_uint ( unsigned short  bitcount)

Reads a bit-packed unsigned integer from the stream and returns it. The given bitcount determines the number of bits to read.

Referenced by read_sint().

§ setBuffer()

void gnash::BitsReader::setBuffer ( byte input,
size_t  len 
)
inline

Set a new buffer to work with.

References gnash::image::end(), and start.

§ size()

size_t gnash::BitsReader::size ( ) const
inline

References gnash::image::end(), and start.


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