use ujson for serializing responses

This commit is contained in:
Jack Robison 2022-03-15 23:57:24 -04:00
parent 0daf205cb0
commit 5b92706065
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
2 changed files with 4 additions and 2 deletions

View file

@ -1,5 +1,6 @@
import itertools import itertools
import json import json
import ujson
import typing import typing
import asyncio import asyncio
from asyncio import Event from asyncio import Event
@ -186,7 +187,7 @@ class JSONRPC:
def encode_payload(cls, payload): def encode_payload(cls, payload):
"""Encode a Python object as JSON and convert it to bytes.""" """Encode a Python object as JSON and convert it to bytes."""
try: try:
return json.dumps(payload).encode() return ujson.dumps(payload).encode()
except TypeError: except TypeError:
msg = f'JSON payload encoding error: {payload}' msg = f'JSON payload encoding error: {payload}'
raise ProtocolError(cls.INTERNAL_ERROR, msg) from None raise ProtocolError(cls.INTERNAL_ERROR, msg) from None

View file

@ -42,7 +42,8 @@ setup(
'hachoir==3.1.2', 'hachoir==3.1.2',
'filetype==1.0.9', 'filetype==1.0.9',
'grpcio==1.38.0', 'grpcio==1.38.0',
'lbry-rocksdb==0.8.2' 'lbry-rocksdb==0.8.2',
'ujson==5.1.0'
], ],
extras_require={ extras_require={
'lint': ['pylint==2.10.0'], 'lint': ['pylint==2.10.0'],