Skip to content

Commit 9e194b3

Browse files
committed
Add endianness support to struct module.
1 parent c96680a commit 9e194b3

2 files changed

Lines changed: 250 additions & 89 deletions

File tree

tests/snippets/test_struct.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,17 @@
88
assert v1 == 14
99
assert v2 == 12
1010

11+
data = struct.pack('<IH', 14, 12)
12+
assert data == bytes([14, 0, 0, 0, 12, 0])
13+
14+
v1, v2 = struct.unpack('<IH', data)
15+
assert v1 == 14
16+
assert v2 == 12
17+
18+
data = struct.pack('>IH', 14, 12)
19+
assert data == bytes([0, 0, 0, 14, 0, 12])
20+
21+
v1, v2 = struct.unpack('>IH', data)
22+
assert v1 == 14
23+
assert v2 == 12
24+

0 commit comments

Comments
 (0)