summaryrefslogtreecommitdiff
path: root/lib/protocol_benchmarks.py
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-02-06 12:00:51 +0100
committerDaniel Friesel <derf@finalrewind.org>2019-02-06 12:00:51 +0100
commit4f744632aff50723979f03fba66f968a6d194dd6 (patch)
tree572bbc5c4acb2faba605ebfac572648b0b1a489f /lib/protocol_benchmarks.py
parentff6dcd2c4c2439e7f5da558a75da758a7eb07629 (diff)
protocol benchmarks: Accessors for serialized data size availability
Diffstat (limited to 'lib/protocol_benchmarks.py')
-rwxr-xr-xlib/protocol_benchmarks.py32
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