def pack_msg(method, msg, pickle_protocol=PICKLE_PROTOCOL):
    """Packs a method and message."""
    dump = io.BytesIO()
    pickle.dump(msg, dump, pickle_protocol)
    size = dump.tell()
    return (struct.pack(METHOD_STRUCT_FORMAT, method) +
            struct.pack(SIZE_STRUCT_FORMAT, size) + dump.getvalue())
Packs a method and message.