Skip to content

Commit 57de0eb

Browse files
Merge pull request RustPython#1061 from RustPython/xdrlib
Add endianness support to struct module.
2 parents 212522a + 9e194b3 commit 57de0eb

File tree

2 files changed

+250
-89
lines changed

2 files changed

+250
-89
lines changed

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)