libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
BaseLib::BitReaderWriter Class Reference

#include <BitReaderWriter.h>

Public Member Functions

virtual ~BitReaderWriter ()
 

Static Public Member Functions

static std::vector< uint8_t > getPosition (const std::vector< uint8_t > &data, uint32_t position, uint32_t size)
 Reads any number of bits at any position from a byte array. More...
 
static std::vector< uint8_t > getPosition (const std::vector< char > &data, uint32_t position, uint32_t size)
 Reads any number of bits at any position from a byte array. More...
 
static uint8_t getPosition8 (const std::vector< uint8_t > &data, uint32_t position, uint32_t size)
 Reads up to 8 bits at any position from a byte array and returns it as an uint8_t. More...
 
static uint16_t getPosition16 (const std::vector< uint8_t > &data, uint32_t position, uint32_t size)
 Reads up to 16 bits at any position from a byte array and returns it as an uint16_t. More...
 
static uint32_t getPosition32 (const std::vector< uint8_t > &data, uint32_t position, uint32_t size)
 Reads up to 32 bits at any position from a byte array and returns it as an uint32_t. More...
 
static uint64_t getPosition64 (const std::vector< uint8_t > &data, uint32_t position, uint32_t size)
 Reads up to 64 bits at any position from a byte array and returns it as an uint64_t. More...
 
static void setPositionLE (uint32_t position, uint32_t size, std::vector< uint8_t > &target, const std::vector< uint8_t > &source)
 Sets any number of bits at any position in a byte array. More...
 
static void setPositionLE (uint32_t position, uint32_t size, std::vector< char > &target, const std::vector< uint8_t > &source)
 Sets any number of bits at any position in a byte array. More...
 
static void setPositionBE (uint32_t position, uint32_t size, std::vector< uint8_t > &target, const std::vector< uint8_t > &source)
 Sets any number of bits at any position in a byte array. More...
 
static void setPositionBE (uint32_t position, uint32_t size, std::vector< char > &target, const std::vector< uint8_t > &source)
 Sets any number of bits at any position in a byte array. More...
 

Constructor & Destructor Documentation

§ ~BitReaderWriter()

virtual BaseLib::BitReaderWriter::~BitReaderWriter ( )
virtual

Member Function Documentation

§ getPosition() [1/2]

std::vector< uint8_t > BaseLib::BitReaderWriter::getPosition ( const std::vector< uint8_t > &  data,
uint32_t  position,
uint32_t  size 
)
static

Reads any number of bits at any position from a byte array.

It is ok for position + size to exceed the array boundaries.

Parameters
dataThe byte array to read from. Index 0 must be the most significant byte.
positionThe position in bits starting with bit 7 of index 0 (position 1 is bit 6 of index 0 and so on). Example: If data is 00101000 00001000, position is 2 and size is 3 then the result is 00000101.
sizeThe size in bits of the data to read.
Returns
The data is returned right aligned.

§ getPosition() [2/2]

std::vector< uint8_t > BaseLib::BitReaderWriter::getPosition ( const std::vector< char > &  data,
uint32_t  position,
uint32_t  size 
)
static

Reads any number of bits at any position from a byte array.

It is ok for position + size to exceed the array boundaries.

Parameters
dataThe byte array to read from. Index 0 must be the most significant byte.
positionThe position in bits starting with bit 7 of index 0 (position 1 is bit 6 of index 0 and so on). Example: If data is 00101000 00001000, position is 2 and size is 3 then the result is 00000101.
sizeThe size in bits of the data to read.
Returns
The data is returned right aligned.

§ getPosition16()

uint16_t BaseLib::BitReaderWriter::getPosition16 ( const std::vector< uint8_t > &  data,
uint32_t  position,
uint32_t  size 
)
static

Reads up to 16 bits at any position from a byte array and returns it as an uint16_t.

Parameters
dataThe byte array to read from. Index 0 must be the most significant byte.
positionThe position in bits starting with bit 7 of index 0 (position 1 is bit 6 of index 0 and so on). Example: If data is 00101000 00001000, position is 2 and size is 3 then the result is 00000101.
sizeThe size in bits of the data to read.
Returns
The data is returned right aligned.

§ getPosition32()

uint32_t BaseLib::BitReaderWriter::getPosition32 ( const std::vector< uint8_t > &  data,
uint32_t  position,
uint32_t  size 
)
static

Reads up to 32 bits at any position from a byte array and returns it as an uint32_t.

Parameters
dataThe byte array to read from. Index 0 must be the most significant byte.
positionThe position in bits starting with bit 7 of index 0 (position 1 is bit 6 of index 0 and so on). Example: If data is 00101000 00001000, position is 2 and size is 3 then the result is 00000101.
sizeThe size in bits of the data to read.
Returns
The data is returned right aligned.

§ getPosition64()

uint64_t BaseLib::BitReaderWriter::getPosition64 ( const std::vector< uint8_t > &  data,
uint32_t  position,
uint32_t  size 
)
static

Reads up to 64 bits at any position from a byte array and returns it as an uint64_t.

Parameters
dataThe byte array to read from. Index 0 must be the most significant byte.
positionThe position in bits starting with bit 7 of index 0 (position 1 is bit 6 of index 0 and so on). Example: If data is 00101000 00001000, position is 2 and size is 3 then the result is 00000101.
sizeThe size in bits of the data to read.
Returns
The data is returned right aligned.

§ getPosition8()

uint8_t BaseLib::BitReaderWriter::getPosition8 ( const std::vector< uint8_t > &  data,
uint32_t  position,
uint32_t  size 
)
static

Reads up to 8 bits at any position from a byte array and returns it as an uint8_t.

Parameters
dataThe byte array to read from. Index 0 must be the most significant byte.
positionThe position in bits starting with bit 7 of index 0 (position 1 is bit 6 of index 0 and so on). Example: If data is 00101000, position is 2 and size is 3 then the result is 00000101.
sizeThe size in bits of the data to read.
Returns
The data is returned right aligned.

§ setPositionBE() [1/2]

void BaseLib::BitReaderWriter::setPositionBE ( uint32_t  position,
uint32_t  size,
std::vector< uint8_t > &  target,
const std::vector< uint8_t > &  source 
)
static

Sets any number of bits at any position in a byte array.

The source bytes are read MSB first (i. e. most significant byte at the smallest index). For example 0xABCD in source stays 0xABCD in target.

Parameters
positionThe position in bits starting with bit 7 of index 0 (position 1 is bit 6 of index 0 and so on). Example: If source is 00000101, position is 2, size is 3 and target.size() is 2 then the result is 00101000 00000000.
sizeThe size in bits of the data to set.
targetThe byte array to write to. Index 0 is the most significant byte. When target is larger than ceil(size / 8.0) bytes, the last (bytes with higher index) ceil(size / 8.0) bytes are used.
sourceThe right aligned byte array of the data to set. Bytes are read LSB first by default and set at position in target (counted from the most significant bit of the most significant byte).

§ setPositionBE() [2/2]

void BaseLib::BitReaderWriter::setPositionBE ( uint32_t  position,
uint32_t  size,
std::vector< char > &  target,
const std::vector< uint8_t > &  source 
)
static

Sets any number of bits at any position in a byte array.

The source bytes are read MSB first (i. e. most significant byte at the smallest index). For example 0xABCD in source stays 0xABCD in target.

Parameters
positionThe position in bits starting with bit 7 of index 0 (position 1 is bit 6 of index 0 and so on). Example: If source is 00000101, position is 2, size is 3 and target.size() is 2 then the result is 00101000 00000000.
sizeThe size in bits of the data to set.
targetThe byte array to write to. Index 0 is the most significant byte. When target is larger than ceil(size / 8.0) bytes, the last (bytes with higher index) ceil(size / 8.0) bytes are used.
sourceThe right aligned byte array of the data to set. Bytes are read LSB first by default and set at position in target (counted from the most significant bit of the most significant byte).

§ setPositionLE() [1/2]

void BaseLib::BitReaderWriter::setPositionLE ( uint32_t  position,
uint32_t  size,
std::vector< uint8_t > &  target,
const std::vector< uint8_t > &  source 
)
static

Sets any number of bits at any position in a byte array.

The source bytes are read LSB first (i. e. least significant byte at the smallest index). For example 0xABCD in source becomes 0xCDAB in target.

Parameters
positionThe position in bits starting with bit 7 of index 0 (position 1 is bit 6 of index 0 and so on). Example: If source is 00000101, position is 2, size is 3 and target.size() is 2 then the result is 00101000 00000000.
sizeThe size in bits of the data to set.
targetThe byte array to write to. Index 0 is the most significant byte.
sourceThe right aligned byte array of the data to set. Bytes are read MSB first by default and set at position in target (counted from the most significant bit of the most significant byte).

§ setPositionLE() [2/2]

void BaseLib::BitReaderWriter::setPositionLE ( uint32_t  position,
uint32_t  size,
std::vector< char > &  target,
const std::vector< uint8_t > &  source 
)
static

Sets any number of bits at any position in a byte array.

The source bytes are read LSB first (i. e. least significant byte at the smallest index). For example 0xABCD in source becomes 0xCDAB in target.

Parameters
positionThe position in bits starting with bit 7 of index 0 (position 1 is bit 6 of index 0 and so on). Example: If source is 00000101, position is 2, size is 3 and target.size() is 2 then the result is 00101000 00000000. Example 2: If source is 0xABCD, position is 0 and size is 16, the result is 0xCDAB.
sizeThe size in bits of the data to set.
targetThe byte array to write to. Index 0 is the most significant byte.
sourceThe right aligned byte array of the data to set. Bytes are read LSB first by default and set at position in target (counted from the most significant bit of the most significant byte).

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