2020-06-29 10:01:40 +00:00
|
|
|
import msgpack
|
|
|
|
|
|
|
|
from rest_framework.renderers import BaseRenderer
|
|
|
|
|
|
|
|
|
|
|
|
class MessagePackRenderer(BaseRenderer):
|
2020-11-14 15:04:41 +00:00
|
|
|
media_type = "application/msgpack"
|
|
|
|
format = "msgpack"
|
|
|
|
render_style = "binary"
|
2020-06-29 10:01:40 +00:00
|
|
|
charset = None
|
|
|
|
|
|
|
|
def render(self, data, media_type=None, renderer_context=None):
|
|
|
|
if data is None:
|
2020-11-14 15:04:41 +00:00
|
|
|
return b""
|
2020-06-29 10:01:40 +00:00
|
|
|
return msgpack.packb(data, use_bin_type=True)
|