mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
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
|
||||
"""
|
||||
|
||||
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"):
|
||||
await self._websocket.send_text(data)
|
||||
else:
|
||||
|
|
|
@ -57,11 +57,10 @@ class RapidJSONWebSocketSerializer(WebSocketSerializer):
|
|||
|
||||
|
||||
class HybridJSONWebSocketSerializer(WebSocketSerializer):
|
||||
def _serialize(self, data):
|
||||
# ORJSON returns bytes
|
||||
return orjson.dumps(data, default=_json_default)
|
||||
def _serialize(self, data) -> str:
|
||||
return str(orjson.dumps(data, default=_json_default), "utf-8")
|
||||
|
||||
def _deserialize(self, data):
|
||||
def _deserialize(self, data: str):
|
||||
# RapidJSON expects strings
|
||||
return rapidjson.loads(data, object_hook=_json_object_hook)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user