#!/usr/bin/env python3 from struct import unpack class BinaryReader(object): def __init__(self, data): self.data = data self.cursor = 0 def _check_eof(self, size): if self.cursor + size > len(self.data): raise EOFError('Attempted to read past the end of internal data buffer') def _read_internal(self, fmt, size): self._check_eof(size) data_to_unpack = self.data[self.cursor:self.cursor + size] self.cursor += size return unpack(fmt, data_to_unpack)[0] def read_uint8(self): return self._read_internal('