Skip to content

Commit

Permalink
Merge pull request #170 from pescadores/msgpack
Browse files Browse the repository at this point in the history
JSON->Msgpack
  • Loading branch information
bmcfee authored Jan 31, 2024
2 parents fa31904 + f3e4f12 commit 9ad3511
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/environment-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies:
- pip
- pyzmq>=18.0
- decorator>=4.0
- msgpack-python>=1.0

# optional, but required for testing
- pytest
Expand Down
1 change: 1 addition & 0 deletions .github/environment-minimal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies:
- pip
- pyzmq~=18.0
- decorator~=4.0
- msgpack-python~=1.0

# optional, but required for testing
- pytest
Expand Down
10 changes: 3 additions & 7 deletions pescador/zmq_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
import multiprocessing as mp
import zmq
import numpy as np

try:
import ujson as json
except ImportError:
import json
import msgpack

from .core import Streamer
from .exceptions import DataError
Expand Down Expand Up @@ -51,7 +47,7 @@ def zmq_send_data(socket, data, flags=0, copy=True, track=False):
payload.append(arr)

# Send the header
msg = [json.dumps(header).encode("ascii")]
msg = [msgpack.packb(header)]
msg.extend(payload)

return socket.send_multipart(msg, flags, copy=copy, track=track)
Expand All @@ -63,7 +59,7 @@ def zmq_recv_data(socket, flags=0, copy=True, track=False):

msg = socket.recv_multipart(flags=flags, copy=copy, track=track)

headers = json.loads(msg[0].decode("ascii"))
headers = msgpack.unpackb(msg[0], raw=False)

if len(headers) == 0:
raise StopIteration
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ install_requires =
pyzmq >= 18.0
numpy >= 1.9
decorator >= 4.0
msgpack >= 1.0

[options.extras_require]
docs =
Expand Down

0 comments on commit 9ad3511

Please sign in to comment.