code: def pack_msg(method, msg, pickle_protocol=PICKLE_PROTOCOL):
      
      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())
docs: Packs a method and message.