This is a draft cheat sheet. It is a work in progress and is not finished yet.
Basic
struct.pack(format, v1, v2, ...) |
struct.unpack(format, string) |
struct.pack_into(format, buffer, offset, v1, v2, ...) |
struct.unpack_from(fmt, buffer[,offset = 0]) |
Examples
pack('hhl', 1, 2, 3) |
b'\x00\x01\x00\x02\x00\x00\x00\x03' |
unpack('hhl', b'\x00\x01\x00\x02\x00\x00\x00\x03') |
(1, 2, 3) |
|
|
Byte Order
@ |
native |
= |
native |
< |
little-endian |
> |
big-endian |
! |
network (= big-endian) |
Format Characters
c |
char |
1 |
b/B |
signed/unsigned char |
1 |
? |
bool |
1 |
h/H |
signed/unsigned short |
2 |
i/I |
signed/unsigned int |
4 |
l/L |
signed/unsigned long |
4 |
q/Q |
signed/unsigned long long |
8 |
f |
float |
4 |
d |
double |
8 |
s |
bytes |
|