1

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?

decheftw
  • 69
  • 6

1 Answers1

1

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

decheftw
  • 69
  • 6