Bit Buffer

class gen_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.

add_length(size)

add to the buffer the length with the draft coding:

The size (using the unit defined in the FL) is encoded as follows:

o If the size is between 0 and 14, it is sent as a 4-bits unsigned

integer.

o For values between 15 and 254, 0b1111 is transmitted and then the

size is sent as an 8 bits unsigned integer.

o For larger values of the size, 0xfff is transmitted and then the

next two bytes contain the size value as a 16 bits unsigned integer.

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.

display(format=None, file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)

Display the content, if format is set to “bin” the buffer is in binary, underline shows its size.

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.

save_to_file(file_descriptor, format=None)

Save the content to file descriptor, if format is set to “bin” the buffer is in binary, underline shows its size.

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.