Compare commits
2 Commits
aac524dd36
...
cce141423d
| Author | SHA1 | Date | |
|---|---|---|---|
| cce141423d | |||
| 941ab51856 |
@@ -4,6 +4,7 @@ from .bsreadext import make_bsread_sender, pack_bsread_data
|
||||
from .bits import read_bit
|
||||
from .bufjson import BufferedJSON
|
||||
from .filehandler import FileHandler
|
||||
from .jsonext import ExtendedJSONEncoder
|
||||
from .randskip import randskip
|
||||
from .sorter import Sorter
|
||||
from .timestamp import make_bsread_timestamp
|
||||
|
||||
22
dap/utils/jsonext.py
Normal file
22
dap/utils/jsonext.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import json
|
||||
import numpy as np
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class ExtendedJSONEncoder(json.JSONEncoder):
|
||||
|
||||
def default(self, obj):
|
||||
if isinstance(obj, np.ndarray):
|
||||
return obj.tolist()
|
||||
elif isinstance(obj, np.generic): # covers all numpy scalars
|
||||
return obj.item()
|
||||
elif isinstance(obj, complex): # covers builtin complex
|
||||
return {"real": obj.real, "imag": obj.imag}
|
||||
elif isinstance(obj, Path):
|
||||
return str(obj)
|
||||
elif isinstance(obj, set):
|
||||
return sorted(obj)
|
||||
return super().default(obj)
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import numpy as np
|
||||
import zmq
|
||||
|
||||
from .utils import ExtendedJSONEncoder
|
||||
|
||||
|
||||
FLAGS = 0
|
||||
|
||||
@@ -61,10 +63,10 @@ class ZMQSocketsWorker:
|
||||
|
||||
|
||||
def send_accumulator(self, results):
|
||||
self.accumulator_socket.send_json(results, FLAGS)
|
||||
self.accumulator_socket.send_json(results, FLAGS, cls=ExtendedJSONEncoder)
|
||||
|
||||
def send_visualisation(self, results, data):
|
||||
self.visualisation_socket.send_json(results, FLAGS | zmq.SNDMORE)
|
||||
self.visualisation_socket.send_json(results, FLAGS | zmq.SNDMORE, cls=ExtendedJSONEncoder)
|
||||
self.visualisation_socket.send(data, FLAGS, copy=True, track=True)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user