Skip to content

Commit

Permalink
Refactor to use pybase64 for faster encode/decode
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonDaniel committed Dec 23, 2024
1 parent f845c3f commit 01b45b7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions neon_mq_connector/utils/network_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import json
import base64
import socket

from pybase64 import b64encode, b64decode

"""
These utils are duplicated from neon_utils.socket_utils to avoid a circular
dependency.
Expand All @@ -44,7 +45,7 @@ def b64_to_dict(data: bytes, charset: str = "utf-8") -> dict:
@return decoded dictionary
"""
return eval(json.loads(base64.b64decode(data).decode(charset)))
return eval(json.loads(b64decode(data).decode(charset)))


def dict_to_b64(data: dict, charset: str = "utf-8") -> bytes:
Expand All @@ -55,7 +56,7 @@ def dict_to_b64(data: dict, charset: str = "utf-8") -> bytes:
@return base64 encoded string
"""
return base64.b64encode(json.dumps(str(data)).encode(charset))
return b64encode(json.dumps(str(data)).encode(charset))


def check_port_is_open(addr: str, port: int) -> bool:
Expand Down
1 change: 1 addition & 0 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pika==1.2.0
ovos-config~=0.0,>=0.0.8
ovos-utils~=0.0,>=0.0.32
pybase64~=1.4

0 comments on commit 01b45b7

Please sign in to comment.