2022-08-18 07:57:45 +01:00
|
|
|
# test struct and endian specific things
|
2019-08-05 06:15:28 +01:00
|
|
|
|
|
|
|
try:
|
2022-08-18 07:57:45 +01:00
|
|
|
import struct
|
|
|
|
except ImportError:
|
|
|
|
print("SKIP")
|
|
|
|
raise SystemExit
|
2019-08-05 06:15:28 +01:00
|
|
|
|
|
|
|
# unpack/unpack_from with unaligned native type
|
|
|
|
buf = b'0123456789'
|
|
|
|
print(struct.unpack('h', memoryview(buf)[1:3]))
|
|
|
|
print(struct.unpack_from('i', buf, 1))
|
|
|
|
print(struct.unpack_from('@i', buf, 1))
|
|
|
|
print(struct.unpack_from('@ii', buf, 1))
|
2019-09-02 03:57:51 +01:00
|
|
|
|
|
|
|
# pack_into with unaligned native type
|
|
|
|
buf = bytearray(b'>----<<<<<<<')
|
|
|
|
struct.pack_into('i', buf, 1, 0x30313233)
|
|
|
|
print(buf)
|
|
|
|
struct.pack_into('@ii', buf, 3, 0x34353637, 0x41424344)
|
|
|
|
print(buf)
|