Allow passing in of header

This commit is contained in:
Thomas Jackson 2015-03-07 08:02:28 -08:00
parent 0b035341a5
commit 2336b338c5

View File

@ -49,9 +49,13 @@ log = logging.getLogger(__name__)
import msgpack import msgpack
# TODO: put in some lib? # TODO: put in some lib?
def frame_msg(msg): def frame_msg(msg, header=None):
header = msgpack.dumps({'msgLen': len(msg)}) if header is None:
return '{0} {1}{2}'.format(len(header), header, msg) header = {}
header['msgLen'] = len(msg)
header_packed = msgpack.dumps(header)
return '{0} {1}{2}'.format(len(header_packed), header_packed, msg)
def socket_frame_recv(s, recv_size=4096): def socket_frame_recv(s, recv_size=4096):