15from .
import log_reader
20class NpEncoder(json.JSONEncoder):
21 def default(self, obj):
22 if isinstance(obj, ctypes.c_long):
24 if isinstance(obj, ctypes.c_double):
26 return super(NpEncoder, self).default(obj)
57 hdr = datastream.read(8)
58 size = int.from_bytes(hdr,
"little")
59 data = datastream.read(size)
60 return json.loads(data)
68 hdr = datastream.read(8)
74 raise NotImplementedError
82 msg = json.dumps({
"out": data}, cls=NpEncoder).encode(
"utf-8")
83 hdr = len(msg).to_bytes(8,
"little")
89 if isinstance(data, int):
90 return struct.pack(
"i", data)
91 elif isinstance(data, float):
92 return struct.pack(
"f", data)
93 elif isinstance(data, str)
and len(data) == 1:
94 return struct.pack(
"c", data)
95 elif isinstance(data, ctypes.c_double):
96 return struct.pack(
"d", data.value)
97 elif isinstance(data, ctypes.c_long):
98 return struct.pack(
"l", data.value)
99 elif isinstance(data, list):
100 return b
"".join([_pack(x)
for x
in data])
103 hdr = len(msg).to_bytes(8,
"little")
Class for serialization and deserialization in various formats for communication.
serializeProtobuf(self, data)
getOutputBuffer(self)
Returns value in buffer and empties it.
deserializeBytes(self, datastream)
Deserializes and returns bitstream data.
deserializeJson(self, datastream)
Deserializes and returns JSON data.
deserializeProtobuf(self, datastream)
deserializeData(self, rawdata)
Deserializes data for specified data format.
serializeBytes(self, data)
Serializes data to bitstream.
serializeData(self, data)
Serializes data and places it in a buffer.
__init__(self, data_format)
Contructor for SerDes object.
serializeJson(self, data)
Serializes data to JSON.