summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics/struct_endian.py
blob: 91f5539c15927fa3c9e5cd2a108d6c8117c119b0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# test ustruct and endian specific things

try:
    import ustruct as struct
except:
    try:
        import struct
    except ImportError:
        print("SKIP")
        raise SystemExit

# 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))

# 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)