def send_message(self, msg_type, fields=None, flush=True):
"""
Send a message of the given type with the given fields.
Optionally, flush the data to the socket.
This method will flush the buffer if it grows too large in any
case.
:param msg_type: one of the MSG_TYPE_* constants.
:param dict fields: dict mapping MSG_KEY_* constants to values.
:param flush: True to force the data to be written immediately.
"""
msg = {MSG_KEY_TYPE: msg_type}
if fields:
msg.update(fields)
self._buf.write(msgpack.dumps(msg))
if flush:
self.flush()
else:
self._maybe_flush()
评论列表
文章目录