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
# TODO: put in some lib?
def frame_msg(msg):
header = msgpack.dumps({'msgLen': len(msg)})
return '{0} {1}{2}'.format(len(header), header, msg)
def frame_msg(msg, header=None):
if header is None:
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):