diff options
author | Daniel Friesel <derf@finalrewind.org> | 2019-02-06 12:00:51 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2019-02-06 12:00:51 +0100 |
commit | 4f744632aff50723979f03fba66f968a6d194dd6 (patch) | |
tree | 572bbc5c4acb2faba605ebfac572648b0b1a489f /lib/protocol_benchmarks.py | |
parent | ff6dcd2c4c2439e7f5da558a75da758a7eb07629 (diff) |
protocol benchmarks: Accessors for serialized data size availability
Diffstat (limited to 'lib/protocol_benchmarks.py')
-rwxr-xr-x | lib/protocol_benchmarks.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/protocol_benchmarks.py b/lib/protocol_benchmarks.py index 8bf8bcb..b8d68cc 100755 --- a/lib/protocol_benchmarks.py +++ b/lib/protocol_benchmarks.py @@ -71,6 +71,9 @@ class DummyProtocol: def get_extra_files(self): return dict() + def can_get_serialized_length(self): + return False + class ArduinoJSON(DummyProtocol): def __init__(self, data, bufsize = 255, int_type = 'uint16_t', float_type = 'float'): @@ -88,6 +91,9 @@ class ArduinoJSON(DummyProtocol): def get_serialized_length(self): return len(json.dumps(self.data)) + def can_get_serialized_length(self): + return True + def get_encode(self): return self.enc_buf @@ -439,6 +445,9 @@ class ManualJSON(DummyProtocol): def get_serialized_length(self): return len(json.dumps(self.data)) + def can_get_serialized_length(self): + return True + def is_ascii(self): return True @@ -548,6 +557,23 @@ class ModernJSON(DummyProtocol): else: raise ValueError('invalid output format {}'.format(self.output_format)) + def get_serialized_length(self): + if self.output_format == 'json': + return len(json.dumps(self.data)) + elif self.output_format == 'bson': + return len(bson.BSON.encode(self.data)) + elif self.output_format == 'cbor': + return len(cbor.dumps(self.data)) + elif self.output_format == 'msgpack': + return len(msgpack.dumps(self.data)) + elif self.output_format == 'ubjson': + return len(ubjson.dumpb(self.data)) + else: + raise ValueError('invalid output format {}'.format(self.output_format)) + + def can_get_serialized_length(self): + return True + def get_length_var(self): return 'out.size()' @@ -602,6 +628,9 @@ class MPack(DummyProtocol): def get_serialized_length(self): return len(msgpack.dumps(self.data)) + def can_get_serialized_length(self): + return True + def is_ascii(self): return False @@ -916,6 +945,9 @@ class UBJ(DummyProtocol): def get_serialized_length(self): return len(ubjson.dumpb(self.data)) + def can_get_serialized_length(self): + return True + def is_ascii(self): return False |