1

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

enter image description here

why i have the redundant double 0?

asked Feb 5, 2016 at 2:05

1 Answer 1

3

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.
chepner
539k77 gold badges596 silver badges748 bronze badges
answered Feb 5, 2016 at 2:27
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.