OpenSCHC Bit Buffer Management Module

class bitarray.BitBuffer(content=b'')
add_bits(bits_as_long, nb_bits, position=None)

write a nb_bits less significant bits of an integer in the buffer. if position is not specified, the nb_bits are added at the end of the buffer. if position is specified the nb_bits are set at the buffer position. Position defines the position if the most significant bit.

add_bytes(bytes_data, position=None)

write bytes_data as a bytearray into the buffer.

allones(position=None)

check whether the bits from the position set all 1 or not. if they are all ones, return True. Otherwise, return False. if the position is not set, it will checks from _rpos.

copy(position=None)

return BitBuffer like get_bits_as_buffer(), but _rpos doesn’t change.

count_added_bits()

return the number of significant bits from the most left bit.

count_remaining_bits()

return the number of the remaining bits from the position of self._rpos to _wpos.

get_bits(nb_bits=1, position=None)

return an integer containinng nb_bits from the position. The most left bit is 0. if position is not specified, _rpos is incremented so that next calling get_bits() without position automatically takes the next bit.

get_bits_as_buffer(nb_bits=None)

_rpos does change. If nb_bits is None, return all remaining bits.

get_content()

return a bytearray containing the remaining bits in _content aligned to the byte boundary. Note that the number of remaining bits will be lost.

set_bit(bit, position=None)

if bit is not 0, set a bit on at the specified position. Otherwise, set a bit off. if position is not specified, the target bit is the bit specified by _wpos, i.e. at the end of buffer, and as the result, _wpos is incremented.

to_bit_list(position=None)

return the content in a list of bits.