MCPcopy Index your code
hub / github.com/lincolnloop/python-qrcode / BitBuffer

Class BitBuffer

qrcode/util.py:470–495  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

468
469
470class BitBuffer:
471 def __init__(self):
472 self.buffer: list[int] = []
473 self.length = 0
474
475 def __repr__(self):
476 return ".".join([str(n) for n in self.buffer])
477
478 def get(self, index):
479 buf_index = math.floor(index / 8)
480 return ((self.buffer[buf_index] >> (7 - index % 8)) & 1) == 1
481
482 def put(self, num, length):
483 for i in range(length):
484 self.put_bit(((num >> (length - i - 1)) & 1) == 1)
485
486 def __len__(self):
487 return self.length
488
489 def put_bit(self, bit):
490 buf_index = self.length // 8
491 if len(self.buffer) <= buf_index:
492 self.buffer.append(0)
493 if bit:
494 self.buffer[buf_index] |= 0x80 >> (self.length % 8)
495 self.length += 1
496
497
498def create_bytes(buffer: BitBuffer, rs_blocks: list[RSBlock]):

Callers 1

create_dataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected