I want to pack a byte followed by a long. My buffer can only contain 9 elements. Why can't I pack them into the buffer?
>>> from struct import *
>>> calcsize('qB')
9
>>> calcsize('Bq')
12
It returns differently. Why is this?
I'm using Python 2.7.3 by the way.
In your second example, struct.calcsize
assumes 3 bytes of padding after the byte so that the long long can begin on a 4-byte boundary.
If you specify no padding, you'll see they are equivalent:
>>> calcsize ('Bq')
12
>>> calcsize('=Bq')
9
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.