def pack_fstring(self, n, s): if n < 0: raise ValueError('fstring size must be nonnegative') data = s[:n] n = ((n+3)//4)*4 data = data + (n - len(data)) * b'\0' self.__buf.write(data)
pack_fopaque = pack_fstring
def pack_string(self, s): n = len(s) self.pack_uint(n) self.pack_fstring(n, s)
def unpack_uhyper(self): hi = self.unpack_uint() lo = self.unpack_uint() return int(hi)<<32 | lo
def unpack_hyper(self): x = self.unpack_uhyper() if x >= 0x8000000000000000: x = x - 0x10000000000000000 return x
def unpack_float(self): i = self.__pos self.__pos = j = i+4 data = self.__buf[i:j] if len(data) < 4: raise EOFError return struct.unpack('>f', data)[0]
def unpack_double(self): i = self.__pos self.__pos = j = i+8 data = self.__buf[i:j] if len(data) < 8: raise EOFError return struct.unpack('>d', data)[0]
def unpack_fstring(self, n): if n < 0: raise ValueError('fstring size must be nonnegative') i = self.__pos j = i + (n+3)//4*4 if j > len(self.__buf): raise EOFError self.__pos = j return self.__buf[i:i+n]
unpack_fopaque = unpack_fstring
def unpack_string(self): n = self.unpack_uint() return self.unpack_fstring(n)
def unpack_list(self, unpack_item): list = [] while 1: x = self.unpack_uint() if x == 0: break if x != 1: raise ConversionError('0 or 1 expected, got %r' % (x,)) item = unpack_item() list.append(item) return list
def unpack_farray(self, n, unpack_item): list = [] for i in range(n): list.append(unpack_item()) return list
def unpack_array(self, unpack_item): n = self.unpack_uint() return self.unpack_farray(n, unpack_item)