From 77d2ac466b969e17d478d6cd762dd931ea98f354 Mon Sep 17 00:00:00 2001 From: Vincent Petithory Date: Tue, 4 Jun 2013 20:46:08 +0200 Subject: [PATCH] Fix: i3.command fails if payload's length > 127: * the msg_length byte string from struct.pack was truncated --- i3.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/i3.py b/i3.py index 48555d2..45bd219 100644 --- a/i3.py +++ b/i3.py @@ -229,12 +229,15 @@ def pack(self, msg_type, payload): msg_length = len(payload.encode('utf-8')) msg_type = parse_msg_type(msg_type) # "struct.pack" returns byte string, decoding it for concatenation - msg_length = struct.pack('I', msg_length).decode('utf-8') - msg_type = struct.pack('I', msg_type).decode('utf-8') - message = '%s%s%s%s' % (msg_magic, msg_length, msg_type, payload) - # Encoding the message back to byte string - return message.encode('utf-8') + msg_length = struct.pack('I', msg_length) + msg_type = struct.pack('I', msg_type) + message = '%s%s%s%s' % (msg_magic, + msg_length, + msg_type.encode('utf-8'), + payload.encode('utf-8')) + # Encoding the message back to byte string + return message def unpack(self, data): """ Unpacks the given byte string and parses the result from JSON.