Belle II Software development
BitStream Class Reference
Inheritance diagram for BitStream:
ConstBitStream BitArray Bits Bits

Public Member Functions

def __init__ (self, auto=None, length=None, offset=None, **kwargs)
 
def __new__ (cls, auto=None, length=None, offset=None, **kwargs)
 
def __copy__ (self)
 
def prepend (self, bs)
 

Protected Attributes

 _pos
 

Static Private Attributes

tuple __slots__ = ()
 
None __hash__ = None
 

Detailed Description

A container or stream holding a mutable sequence of bits

Subclass of the ConstBitStream and BitArray classes. Inherits all of
their methods.

Methods:

all() -- Check if all specified bits are set to 1 or 0.
any() -- Check if any of specified bits are set to 1 or 0.
append() -- Append a bitstring.
bytealign() -- Align to next byte boundary.
byteswap() -- Change byte endianness in-place.
count() -- Count the number of bits set to 1 or 0.
cut() -- Create generator of constant sized chunks.
endswith() -- Return whether the bitstring ends with a sub-string.
find() -- Find a sub-bitstring in the current bitstring.
findall() -- Find all occurrences of a sub-bitstring in the current bitstring.
insert() -- Insert a bitstring.
invert() -- Flip bit(s) between one and zero.
join() -- Join bitstrings together using current bitstring.
overwrite() -- Overwrite a section with a new bitstring.
peek() -- Peek at and interpret next bits as a single item.
peeklist() -- Peek at and interpret next bits as a list of items.
prepend() -- Prepend a bitstring.
read() -- Read and interpret next bits as a single item.
readlist() -- Read and interpret next bits as a list of items.
replace() -- Replace occurrences of one bitstring with another.
reverse() -- Reverse bits in-place.
rfind() -- Seek backwards to find a sub-bitstring.
rol() -- Rotate bits to the left.
ror() -- Rotate bits to the right.
set() -- Set bit(s) to 1 or 0.
split() -- Create generator of chunks split by a delimiter.
startswith() -- Return whether the bitstring starts with a sub-bitstring.
tobytes() -- Return bitstring as bytes, padding if needed.
tofile() -- Write bitstring to file, padding if needed.
unpack() -- Interpret bits using format string.

Special methods:

Mutating operators are available: [], <<=, >>=, +=, *=, &=, |= and ^=
in addition to [], ==, !=, +, *, ~, <<, >>, &, | and ^.

Properties:

bin -- The bitstring as a binary string.
bool -- For single bit bitstrings, interpret as True or False.
bytepos -- The current byte position in the bitstring.
bytes -- The bitstring as a bytes object.
float -- Interpret as a floating point number.
floatbe -- Interpret as a big-endian floating point number.
floatle -- Interpret as a little-endian floating point number.
floatne -- Interpret as a native-endian floating point number.
hex -- The bitstring as a hexadecimal string.
int -- Interpret as a two's complement signed integer.
intbe -- Interpret as a big-endian signed integer.
intle -- Interpret as a little-endian signed integer.
intne -- Interpret as a native-endian signed integer.
len -- Length of the bitstring in bits.
oct -- The bitstring as an octal string.
pos -- The current bit position in the bitstring.
se -- Interpret as a signed exponential-Golomb code.
ue -- Interpret as an unsigned exponential-Golomb code.
sie -- Interpret as a signed interleaved exponential-Golomb code.
uie -- Interpret as an unsigned interleaved exponential-Golomb code.
uint -- Interpret as a two's complement unsigned integer.
uintbe -- Interpret as a big-endian unsigned integer.
uintle -- Interpret as a little-endian unsigned integer.
uintne -- Interpret as a native-endian unsigned integer.

Definition at line 4020 of file bitstring.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  auto = None,
  length = None,
  offset = None,
**  kwargs 
)
Either specify an 'auto' initialiser:
auto -- a string of comma separated tokens, an integer, a file object,
        a bytearray, a boolean iterable or another bitstring.

Or initialise via **kwargs with one (and only one) of:
bytes -- raw data as a string, for example read from a binary file.
bin -- binary string representation, e.g. '0b001010'.
hex -- hexadecimal string representation, e.g. '0x2ef'
oct -- octal string representation, e.g. '0o777'.
uint -- an unsigned integer.
int -- a signed integer.
float -- a floating point number.
uintbe -- an unsigned big-endian whole byte integer.
intbe -- a signed big-endian whole byte integer.
floatbe - a big-endian floating point number.
uintle -- an unsigned little-endian whole byte integer.
intle -- a signed little-endian whole byte integer.
floatle -- a little-endian floating point number.
uintne -- an unsigned native-endian whole byte integer.
intne -- a signed native-endian whole byte integer.
floatne -- a native-endian floating point number.
se -- a signed exponential-Golomb code.
ue -- an unsigned exponential-Golomb code.
sie -- a signed interleaved exponential-Golomb code.
uie -- an unsigned interleaved exponential-Golomb code.
bool -- a boolean (True or False).
filename -- a file which will be opened in binary read-only mode.

Other keyword arguments:
length -- length of the bitstring in bits, if needed and appropriate.
          It must be supplied for all integer and float initialisers.
offset -- bit offset to the data. These offset bits are
          ignored and this is intended for use when
          initialising using 'bytes' or 'filename'.

Reimplemented from BitArray.

Definition at line 4098 of file bitstring.py.

4098 def __init__(self, auto=None, length=None, offset=None, **kwargs):
4099 """Either specify an 'auto' initialiser:
4100 auto -- a string of comma separated tokens, an integer, a file object,
4101 a bytearray, a boolean iterable or another bitstring.
4102
4103 Or initialise via **kwargs with one (and only one) of:
4104 bytes -- raw data as a string, for example read from a binary file.
4105 bin -- binary string representation, e.g. '0b001010'.
4106 hex -- hexadecimal string representation, e.g. '0x2ef'
4107 oct -- octal string representation, e.g. '0o777'.
4108 uint -- an unsigned integer.
4109 int -- a signed integer.
4110 float -- a floating point number.
4111 uintbe -- an unsigned big-endian whole byte integer.
4112 intbe -- a signed big-endian whole byte integer.
4113 floatbe - a big-endian floating point number.
4114 uintle -- an unsigned little-endian whole byte integer.
4115 intle -- a signed little-endian whole byte integer.
4116 floatle -- a little-endian floating point number.
4117 uintne -- an unsigned native-endian whole byte integer.
4118 intne -- a signed native-endian whole byte integer.
4119 floatne -- a native-endian floating point number.
4120 se -- a signed exponential-Golomb code.
4121 ue -- an unsigned exponential-Golomb code.
4122 sie -- a signed interleaved exponential-Golomb code.
4123 uie -- an unsigned interleaved exponential-Golomb code.
4124 bool -- a boolean (True or False).
4125 filename -- a file which will be opened in binary read-only mode.
4126
4127 Other keyword arguments:
4128 length -- length of the bitstring in bits, if needed and appropriate.
4129 It must be supplied for all integer and float initialisers.
4130 offset -- bit offset to the data. These offset bits are
4131 ignored and this is intended for use when
4132 initialising using 'bytes' or 'filename'.
4133
4134 """
4135 self._pos = 0
4136 # For mutable BitStreams we always read in files to memory:
4137 if not isinstance(self._datastore, ByteStore):
4138 self._ensureinmemory()
4139

Member Function Documentation

◆ __copy__()

def __copy__ (   self)
Return a new copy of the BitStream.

Reimplemented from BitArray.

Definition at line 4145 of file bitstring.py.

4145 def __copy__(self):
4146 """Return a new copy of the BitStream."""
4147 s_copy = BitStream()
4148 s_copy._pos = 0
4149 if not isinstance(self._datastore, ByteStore):
4150 # Let them both point to the same (invariant) array.
4151 # If either gets modified then at that point they'll be read into memory.
4152 s_copy._datastore = self._datastore
4153 else:
4154 s_copy._datastore = ByteStore(self._datastore._rawarray[:],
4155 self._datastore.bitlength,
4156 self._datastore.offset)
4157 return s_copy
4158

◆ __new__()

def __new__ (   cls,
  auto = None,
  length = None,
  offset = None,
**  kwargs 
)

Reimplemented from BitArray.

Definition at line 4140 of file bitstring.py.

4140 def __new__(cls, auto=None, length=None, offset=None, **kwargs):
4141 x = super(BitStream, cls).__new__(cls)
4142 x._initialise(auto, length, offset, **kwargs)
4143 return x
4144

◆ prepend()

def prepend (   self,
  bs 
)
Prepend a bitstring to the current bitstring.

bs -- The bitstring to prepend.

Reimplemented from BitArray.

Definition at line 4159 of file bitstring.py.

4159 def prepend(self, bs):
4160 """Prepend a bitstring to the current bitstring.
4161
4162 bs -- The bitstring to prepend.
4163
4164 """
4165 bs = self._converttobitstring(bs)
4166 self._prepend(bs)
4167 self._pos += bs.len
4168
4169

Member Data Documentation

◆ __hash__

None __hash__ = None
staticprivate

Definition at line 4096 of file bitstring.py.

◆ __slots__

tuple __slots__ = ()
staticprivate

Definition at line 4093 of file bitstring.py.

◆ _pos

_pos
protected

Definition at line 4135 of file bitstring.py.


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