etesync-server/django_etebase/drf_msgpack/renderers.py
Tom Hacohen 2880673e27 drf_msgpack: add code to parse/serialise msgpack
It's not actually used by clients but it's there and can be used. It
works for receiving msgpack messages, but doesn't yet work for sending
because some of the types will be converted to base64.
2020-06-29 14:21:43 +03:00

16 lines
389 B
Python

import msgpack
from rest_framework.renderers import BaseRenderer
class MessagePackRenderer(BaseRenderer):
media_type = 'application/msgpack'
format = 'msgpack'
render_style = 'binary'
charset = None
def render(self, data, media_type=None, renderer_context=None):
if data is None:
return b''
return msgpack.packb(data, use_bin_type=True)