Ejemplo n.º 1
0
def test_unpackers():
    b = bytes(range(256))
    assert util.unpack_int32_from(b, 0) == (50462976,)
    assert util.unpack_int32_from(b, 42) == (757869354,)
    assert util.unpack_int64_from(b, 0) == (506097522914230528,)
    assert util.unpack_int64_from(b, 42) == (3544384782113450794,)

    assert util.unpack_uint16_from(b, 0) == (256,)
    assert util.unpack_uint16_from(b, 42) == (11050,)
    assert util.unpack_uint32_from(b, 0) == (50462976,)
    assert util.unpack_uint32_from(b, 42) == (757869354,)
    assert util.unpack_uint64_from(b, 0) == (506097522914230528,)
    assert util.unpack_uint64_from(b, 42) == (3544384782113450794,)
Ejemplo n.º 2
0
 def _read_le_int32(self):
     result, = unpack_int32_from(self.binary, self.cursor)
     self.cursor += 4
     return result
Ejemplo n.º 3
0
 def _get_version(self):
     result, = unpack_int32_from(self.binary, self.cursor)
     return result
Ejemplo n.º 4
0
 def _read_le_int32(self):  #unpack_uint32_from方法(buffer,offset)解析数据[4]
     result, = unpack_int32_from(self.binary, self.cursor)  #解析数据
     self.cursor += 4  #解析完成后,对应记录数据解析的位置
     return result