Belle II Software development
ConstByteStore Class Reference
Inheritance diagram for ConstByteStore:
ByteStore

Public Member Functions

def __init__ (self, data, bitlength=None, offset=None)
 
def getbit (self, pos)
 
def getbyte (self, pos)
 
def getbyteslice (self, start, end)
 
def bytelength (self)
 
def __copy__ (self)
 
def byteoffset (self)
 
def rawbytes (self)
 

Public Attributes

 offset
 
 bitlength
 

Protected Member Functions

def _appendstore (self, store)
 
def _prependstore (self, store)
 

Protected Attributes

 _rawarray
 

Static Private Attributes

tuple __slots__ = ('offset', '_rawarray', 'bitlength')
 

Detailed Description

Stores raw bytes together with a bit offset and length.

Used internally - not part of public interface.

Definition at line 132 of file bitstring.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  data,
  bitlength = None,
  offset = None 
)
data is either a bytearray or a MmapByteArray

Definition at line 140 of file bitstring.py.

140 def __init__(self, data, bitlength=None, offset=None):
141 """data is either a bytearray or a MmapByteArray"""
142 self._rawarray = data
143 if offset is None:
144 offset = 0
145 if bitlength is None:
146 bitlength = 8 * len(data) - offset
147 self.offset = offset
148 self.bitlength = bitlength
149

Member Function Documentation

◆ __copy__()

def __copy__ (   self)

Definition at line 172 of file bitstring.py.

172 def __copy__(self):
173 return ByteStore(self._rawarray[:], self.bitlength, self.offset)
174

◆ _appendstore()

def _appendstore (   self,
  store 
)
protected
Join another store on to the end of this one.

Definition at line 175 of file bitstring.py.

175 def _appendstore(self, store):
176 """Join another store on to the end of this one."""
177 if not store.bitlength:
178 return
179 # Set new array offset to the number of bits in the final byte of current array.
180 store = offsetcopy(store, (self.offset + self.bitlength) % 8)
181 if store.offset:
182 # first do the byte with the join.
183 joinval = (self._rawarray.pop() & (255 ^ (255 >> store.offset)) |
184 (store.getbyte(0) & (255 >> store.offset)))
185 self._rawarray.append(joinval)
186 self._rawarray.extend(store._rawarray[1:])
187 else:
188 self._rawarray.extend(store._rawarray)
189 self.bitlength += store.bitlength
190

◆ _prependstore()

def _prependstore (   self,
  store 
)
protected
Join another store on to the start of this one.

Definition at line 191 of file bitstring.py.

191 def _prependstore(self, store):
192 """Join another store on to the start of this one."""
193 if not store.bitlength:
194 return
195 # Set the offset of copy of store so that it's final byte
196 # ends in a position that matches the offset of self,
197 # then join self on to the end of it.
198 store = offsetcopy(store, (self.offset - store.bitlength) % 8)
199 assert (store.offset + store.bitlength) % 8 == self.offset % 8
200 bit_offset = self.offset % 8
201 if bit_offset:
202 # first do the byte with the join.
203 store.setbyte(-1, (store.getbyte(-1) & (255 ^ (255 >> bit_offset)) |
204 (self._rawarray[self.byteoffset] & (255 >> bit_offset))))
205 store._rawarray.extend(self._rawarray[self.byteoffset + 1: self.byteoffset + self.bytelength])
206 else:
207 store._rawarray.extend(self._rawarray[self.byteoffset: self.byteoffset + self.bytelength])
208 self._rawarray = store._rawarray
209 self.offset = store.offset
210 self.bitlength += store.bitlength
211

◆ bytelength()

def bytelength (   self)

Definition at line 165 of file bitstring.py.

165 def bytelength(self):
166 if not self.bitlength:
167 return 0
168 sb = self.offset // 8
169 eb = (self.offset + self.bitlength - 1) // 8
170 return eb - sb + 1
171

◆ byteoffset()

def byteoffset (   self)

Definition at line 213 of file bitstring.py.

213 def byteoffset(self):
214 return self.offset // 8
215

◆ getbit()

def getbit (   self,
  pos 
)

Definition at line 150 of file bitstring.py.

150 def getbit(self, pos):
151 assert 0 <= pos < self.bitlength
152 byte, bit = divmod(self.offset + pos, 8)
153 return bool(self._rawarray[byte] & (128 >> bit))
154

◆ getbyte()

def getbyte (   self,
  pos 
)
Direct access to byte data.

Definition at line 155 of file bitstring.py.

155 def getbyte(self, pos):
156 """Direct access to byte data."""
157 return self._rawarray[pos]
158

◆ getbyteslice()

def getbyteslice (   self,
  start,
  end 
)
Direct access to byte data.

Definition at line 159 of file bitstring.py.

159 def getbyteslice(self, start, end):
160 """Direct access to byte data."""
161 c = self._rawarray[start:end]
162 return c
163

◆ rawbytes()

def rawbytes (   self)

Definition at line 217 of file bitstring.py.

217 def rawbytes(self):
218 return self._rawarray
219
220

Member Data Documentation

◆ __slots__

tuple __slots__ = ('offset', '_rawarray', 'bitlength')
staticprivate

Definition at line 138 of file bitstring.py.

◆ _rawarray

_rawarray
protected

Definition at line 142 of file bitstring.py.

◆ bitlength

bitlength

Definition at line 148 of file bitstring.py.

◆ offset

offset

Definition at line 147 of file bitstring.py.


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