Unverified Commit 220fc43d authored by Martin Prudek's avatar Martin Prudek
Browse files

dump: Use two classes - 1. for write, 2. for read

parent 35344012
......@@ -4,10 +4,8 @@ import msgpack
class Dump:
def __init__(self, path):
self.file = open(path, "a+b")
self.file = open(path, "ab")
self.unpacker = msgpack.Unpacker(self.file, raw=False)
self.read_position = 0
self.write_position = self.file.tell()
def dump_message(self, msg_type, payload):
msg = {
......@@ -17,11 +15,12 @@ class Dump:
j = json.dumps(msg)
self.file.write(msgpack.packb(j, use_bin_type=True))
self.file.flush()
self.write_position = self.file.tell()
class Replay:
def __init__(self, path):
self.file = open(path, "rb")
self.unpacker = msgpack.Unpacker(self.file, raw=False)
def load_message(self):
self.file.seek(self.read_position)
msg = json.loads(self.unpacker.unpack())
self.read_position = self.file.tell()
self.file.seek(self.write_position)
return msg
return json.loads(self.unpacker.unpack())
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment