I'm trying to pack an epoch with a string & I can't figure out why the number of bytes depends on the order I do the packing in. Unfortunately I'm not getting any replies on the relevant microcontroller forum https://forum.pycom.io/topic/6761/struct
If I convert a character to bytes I get 1 byte:
>>> bytes=struct.pack('s', 'F'); print(bytes, len(bytes))
b'F' 1
If I convert an epoch to bytes I get 4 bytes:
>>> bytes=struct.pack('I', 1611017052); print(bytes, len(bytes))
b'\+x06`' 4
How come when I do both together I get 8 instead of 4+1=5 ??
>>> bytes=struct.pack('sI', 'F', 1611017052); print(bytes, len(bytes))
b'Fx00x00x00\+x06`' 8
but this way I get the 5 I expect?
>>> bytes=struct.pack('Is', 1611017052, 'F'); print(bytes, len(bytes))
b'\+x06`F' 5
why is a different packing sequence giving different numbers of bytes?
question from:
https://stackoverflow.com/questions/65836735/why-does-the-output-of-struct-pack-depend-on-the-order-of-the-items 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…