Convert Enum to IntValue.

This commit is contained in:
Yuxin Wang 2018-10-06 22:39:33 -04:00
parent ae937aa48b
commit 1d2cdfb01e

View file

@ -70,6 +70,8 @@ class MessageServer:
async def _write_message(self, writer, message): async def _write_message(self, writer, message):
assert isinstance(writer, asyncio.StreamWriter) assert isinstance(writer, asyncio.StreamWriter)
logger.debug('Writing {}'.format(self.__message_log(message))) logger.debug('Writing {}'.format(self.__message_log(message)))
# use value of enum since Enum is not JSON serializable
message['type'] = message['type'].value
# json string (str) -> encode to utf8 (bytes) -> compress (bytes) -> add length header (bytes) # json string (str) -> encode to utf8 (bytes) -> compress (bytes) -> add length header (bytes)
raw_msg = json.dumps(message).encode('utf-8') raw_msg = json.dumps(message).encode('utf-8')
compressed = self._compressor.compress(raw_msg) compressed = self._compressor.compress(raw_msg)