Reputation: 61
So I'm trying to pack a packet header, and things are working fine, except for header flags I need to pack as strings are only unpacking the first character of the string.
For instance,
string = "ahhhhhh"
buffer = pack("s", string.encode('UTF-8'))
list = unpack("s", buffer)
print(list)
gives me (b'a')
What am I doing wrong?
Upvotes: 1
Views: 643
Reputation: 61
Ah, so for my format string, I have to specify the amount of characters in the string I'm packing
string = "ahhhhhh"
buffer = pack("7s", string.encode('UTF-8'))
list = unpack("7s", buffer)
print(list)
would be correct
Upvotes: 1