I use this code pack data,
data = struct.pack("bb3sb4si", 0x11, 3, 'abc', 4, 'kkkk', 0x12345678
and send it to my server.
But my server receive this
why i have the redundant double 0?
1 Answer 1
You are implicity using native alignment; the extra bytes force the final integer to start on a 4-byte boundary. Disabling alignment with the = prefix removes the extra padding.
$ cat pack.py
import struct
import sys
data = struct.pack("=bb3sb4si", 0x11, 3, 'abc', 4, 'kkkk', 0x12345678)
sys.stdout.write(data)
$ python pack.py | xxd
0000000: 1103 6162 6304 6b6b 6b6b 7856 3412 ..abc.kkkkxV4.
Sign up to request clarification or add additional context in comments.
Comments
lang-py