move bytes decoding to serializer
This commit is contained in:
parent
d526dfb171
commit
38f14349e9
@ -27,12 +27,6 @@ class WebSocketProxy:
|
|||||||
"""
|
"""
|
||||||
Send data on the wrapped websocket
|
Send data on the wrapped websocket
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not isinstance(data, str):
|
|
||||||
# We use HybridJSONWebSocketSerializer, which when serialized returns
|
|
||||||
# bytes because of ORJSON, so we explicitly decode into a string
|
|
||||||
data = str(data, "utf-8")
|
|
||||||
|
|
||||||
if hasattr(self._websocket, "send_text"):
|
if hasattr(self._websocket, "send_text"):
|
||||||
await self._websocket.send_text(data)
|
await self._websocket.send_text(data)
|
||||||
else:
|
else:
|
||||||
|
@ -57,11 +57,10 @@ class RapidJSONWebSocketSerializer(WebSocketSerializer):
|
|||||||
|
|
||||||
|
|
||||||
class HybridJSONWebSocketSerializer(WebSocketSerializer):
|
class HybridJSONWebSocketSerializer(WebSocketSerializer):
|
||||||
def _serialize(self, data):
|
def _serialize(self, data) -> str:
|
||||||
# ORJSON returns bytes
|
return str(orjson.dumps(data, default=_json_default), "utf-8")
|
||||||
return orjson.dumps(data, default=_json_default)
|
|
||||||
|
|
||||||
def _deserialize(self, data):
|
def _deserialize(self, data: str):
|
||||||
# RapidJSON expects strings
|
# RapidJSON expects strings
|
||||||
return rapidjson.loads(data, object_hook=_json_object_hook)
|
return rapidjson.loads(data, object_hook=_json_object_hook)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user