2020-06-29 10:01:40 +00:00
|
|
|
import msgpack
|
|
|
|
|
|
|
|
from rest_framework.parsers import BaseParser
|
|
|
|
from rest_framework.exceptions import ParseError
|
|
|
|
|
|
|
|
|
|
|
|
class MessagePackParser(BaseParser):
|
2020-11-14 15:04:41 +00:00
|
|
|
media_type = "application/msgpack"
|
2020-06-29 10:01:40 +00:00
|
|
|
|
|
|
|
def parse(self, stream, media_type=None, parser_context=None):
|
|
|
|
try:
|
|
|
|
return msgpack.unpackb(stream.read(), raw=False)
|
|
|
|
except Exception as exc:
|
2020-11-14 15:04:41 +00:00
|
|
|
raise ParseError("MessagePack parse error - %s" % str(exc))
|