def test_unpack_from(self): ''' TODO: just a sanity test for now. Needs far more testing. ''' import array _struct.unpack_from("", array.array("c")) self.assertEqual(_struct.unpack_from("", array.array("c")), ())
def test_unpack_from(): ''' TODO: just a sanity test for now. Needs far more testing. ''' import array _struct.unpack_from("", array.array("c")) AreEqual(_struct.unpack_from("", array.array("c")), ())
def get_ref_block_params(self): props = self.get_dynamic_global_properties() ref_block_num = props['head_block_number'] - 1 & 0xFFFF ref_block = self.get_block(props['head_block_number']) ref_block_prefix = _struct.unpack_from( "<I", unhexlify(ref_block["previous"]), 4)[0] return ref_block_num, ref_block_prefix
def getUInt8A(data, offset, size): end = int(offset + size) assert end <= len( data), "Trying to read UInt8 array beyond data end (%d, %X > %X)" % ( size, end, len(data)) val = unpack_from('<' + 'B' * int(size), data, offset) val = list(val) return val, end
def getSInt32A(data, offset, size): val = unpack_from('<' + 'l' * int(size), data, offset) val = list(val) return val, int(offset + 4 * size)
def getUInt16A(data, offset, size): val = unpack_from('<' + 'H' * int(size), data, offset) val = list(val) return val, int(offset + 2 * size)
def getFloat64A(data, offset, size): val = unpack_from('<' + 'd' * int(size), data, offset) val = list(val) return val, int(offset + 8 * size)
def getFloat32A(data, offset, size): singles = unpack_from('<' + 'f' * int(size), data, offset) val = [float(s) for s in singles] return val, int(offset + 4 * size)