#include <bit/buffer.h>
to the base Data class which is octet oriented. Although this class manages bit oriented buffers, it attempts to optimize for octet (byte) based buffers.
The methods pack(), unpack() and clear() provide a means of extracting and setting bit segments in the underlying buffer.
Public Member Functions | |
Buffer (size_t initial_size=0, size_t sizemax=0) throw (std::bad_alloc) | |
Construct a buffer of a given size that is allowed to dynamically grown as pack/unpack requests are made. | |
Buffer (void *data, size_t size, size_t sizemax=0, DataMode mode=COPY) throw (std::bad_alloc) | |
Constructor initializes buffer with a copy of specific data. | |
Buffer (const Data &other) | |
Constructor initializes buffer to use the specified underlying data chunk. | |
Buffer (const Buffer &other) | |
Copy constructor. | |
~Buffer () | |
bool | unpack (void *mem, size_t mem_octets, Location mem_loc, size_t buf_offset_bits, size_t extract_bits) |
Transfer data from the buffer area into the low order bits of a memory location. | |
Data | unpack (size_t buf_offset_bits, size_t extract_bits, Location mem_loc=END) |
template<typename T> | |
bool | unpack (T &val, Location mem_loc, size_t buf_offset_bits, size_t extract_bits) |
bool | pack (const void *mem, size_t mem_octets, Location mem_loc, size_t buf_offset, size_t buf_tgtsize, size_t n) |
Transfer data from the low order bits of a memory location into the low order bits of a segment of the buffer area. | |
bool | pack (Data d, size_t buf_offset, size_t buf_tgtsize, size_t n, Location mem_loc=END) |
template<typename T> | |
bool | pack (const T &val, Location mem_loc, size_t offset, size_t destsize, size_t n) |
bool | clear_bits (size_t offset, size_t bits) |
bit::Buffer::Buffer | ( | size_t | initial_size = 0 , |
|
size_t | sizemax = 0 | |||
) | throw (std::bad_alloc) |
Construct a buffer of a given size that is allowed to dynamically grown as pack/unpack requests are made.
bit::Buffer::Buffer | ( | void * | data, | |
size_t | size, | |||
size_t | sizemax = 0 , |
|||
DataMode | mode = COPY | |||
) | throw (std::bad_alloc) |
Constructor initializes buffer with a copy of specific data.
bit::Buffer::Buffer | ( | const Data & | other | ) |
Constructor initializes buffer to use the specified underlying data chunk.
bit::Buffer::Buffer | ( | const Buffer & | other | ) |
Copy constructor.
bit::Buffer::~Buffer | ( | ) |
bool bit::Buffer::unpack | ( | void * | mem, | |
size_t | mem_octets, | |||
Location | mem_loc, | |||
size_t | buf_offset_bits, | |||
size_t | extract_bits | |||
) |
Transfer data from the buffer area into the low order bits of a memory location.
mem | The memory location to transfer buffer data into | |
mem_octets | The size of the memory location in octets | |
mem_loc | The memory location relative position (END or START) | |
buf_offset_bits | The offset from the beginning of the buffer in bits to begin extraction from | |
extract_bits | The size of the data to extract in bits |
Memory Buffer ================================================== |000000000011111111112222222222333333333344444444| |012345678901234567890123456789012345678901234567| ================================================== ^ mem = start of memory address ^ mem_octets = 6 ^ ^ Resulting data ^ when mem_loc = END ^ Resulting data ^ when mem_loc = START
References bit::Data::data(), bit::last_octet_lower_bits(), bit::left_shift(), bit::masks, bit::octet_ceiling(), bit::Data::resize(), bit::Data::size(), and bit::START.
Referenced by bit::FieldBuffer::unpack(), unpack(), and bit::FieldBuffer::unpack_uint64().
References bit::Data::clear(), bit::Data::data(), bit::octet_ceiling(), bit::Data::size(), and unpack().
bool bit::Buffer::unpack | ( | T & | val, | |
Location | mem_loc, | |||
size_t | buf_offset_bits, | |||
size_t | extract_bits | |||
) | [inline] |
References unpack().
bool bit::Buffer::pack | ( | const void * | mem, | |
size_t | mem_octets, | |||
Location | mem_loc, | |||
size_t | buf_offset, | |||
size_t | buf_tgtsize, | |||
size_t | n | |||
) |
Transfer data from the low order bits of a memory location into the low order bits of a segment of the buffer area.
mem | The memory location to transfer from | |
mem_octets | The size of the memory location in octets | |
buf_offset | The offset from the start of the data buffer in bits | |
buf_tgtsize | The size of the target area in the buffer in bits | |
n | The size of the data to extract in bits |
offset | + | |
destsize | are greater than the size of the buffer and the buffer cannot be expanded to accommodate the request zero is returned. |
Bit Buffer ================================================== |000000000011111111112222222222333333333344444444| |012345678901234567890123456789012345678901234567| ================================================== ^ buf_offset_bits = 14 ^ buf_tgtsize = 20 ^ ^ n = 10 ^ ^ cpy in ^
References clear_bits(), bit::Data::data(), bit::last_octet_lower_bits(), bit::last_octet_upper_bits(), bit::masks, bit::octet_ceiling(), bit::Data::resize(), bit::right_shift(), bit::Data::size(), and bit::START.
Referenced by bit::FieldBuffer::pack(), pack(), and bit::FieldBuffer::pack_uint64().
bool bit::Buffer::pack | ( | Data | d, | |
size_t | buf_offset, | |||
size_t | buf_tgtsize, | |||
size_t | n, | |||
Location | mem_loc = END | |||
) |
References bit::Data::data(), pack(), and bit::Data::size().
bool bit::Buffer::pack | ( | const T & | val, | |
Location | mem_loc, | |||
size_t | offset, | |||
size_t | destsize, | |||
size_t | n | |||
) | [inline] |
References pack().
bool bit::Buffer::clear_bits | ( | size_t | offset, | |
size_t | bits | |||
) |
References bit::Data::data(), bit::ending_octet(), bit::last_octet_lower_bits(), bit::last_octet_upper_bits(), bit::masks, bit::octet_ceiling(), bit::Data::size(), and bit::starting_octet().
Referenced by pack().