struct pack return is too long

前端 未结 3 857
有刺的猬
有刺的猬 2020-12-10 16:18

I\'m trying to use the struct.pack function

import struct
values = (0, 44)
s = struct.Struct(\'HI\')
b = s.pack(*values)
print(b)
print(str(len(         


        
3条回答
  •  半阙折子戏
    2020-12-10 16:51

    pack will add pad bytes so that the second integer is 4 byte aligned. From the documentation:

    By default, the result of packing a given C struct includes pad bytes in order to maintain proper alignment for the C types involved; To ... omit implicit pad bytes, use standard size and alignment instead of native size and alignment: see Byte Order, Size, and Alignment for details

提交回复
热议问题