1
0
mirror of https://github.com/etesync/server synced 2024-12-28 18:28:07 +00:00
etesync-server/django_etebase/drf_msgpack/parsers.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

15 lines
436 B
Python

import msgpack
from rest_framework.parsers import BaseParser
from rest_framework.exceptions import ParseError
class MessagePackParser(BaseParser):
media_type = 'application/msgpack'
def parse(self, stream, media_type=None, parser_context=None):
try:
return msgpack.unpackb(stream.read(), raw=False)
except Exception as exc:
raise ParseError('MessagePack parse error - %s' % str(exc))