summaryrefslogtreecommitdiff
path: root/lib/protocol_benchmarks.py
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2019-05-07 12:20:58 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2019-05-07 12:20:58 +0200
commit6c07028dc50e21f397ca867bef5d750f06eb090b (patch)
tree768b096197ad7e9b541cec629a939c155ff321b8 /lib/protocol_benchmarks.py
parentfc1368b3421171467d5925537b271091215f74f4 (diff)
Avro: Add strip_schema option
Diffstat (limited to 'lib/protocol_benchmarks.py')
-rwxr-xr-xlib/protocol_benchmarks.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/protocol_benchmarks.py b/lib/protocol_benchmarks.py
index 02bd89b..81ff365 100755
--- a/lib/protocol_benchmarks.py
+++ b/lib/protocol_benchmarks.py
@@ -99,9 +99,10 @@ class DummyProtocol:
class Avro(DummyProtocol):
- def __init__(self, data):
+ def __init__(self, data, strip_schema = False):
super().__init__()
self.data = data
+ self.strip_schema = strip_schema
self.schema = {
'namespace' : 'benchmark.avro',
'type' : 'record',
@@ -117,8 +118,13 @@ class Avro(DummyProtocol):
writer.flush()
except avro.schema.SchemaParseException:
raise RuntimeError('Unsupported schema') from None
- buf.seek(0)
- self.serialized_data = buf.read()
+ self.serialized_data = buf.getvalue()
+ if strip_schema:
+ self.serialized_data = self.serialized_data[self.serialized_data.find(b'}\x00')+2 : ]
+ # strip leading 16-byte sync marker
+ self.serialized_data = self.serialized_data[16:]
+ # strip trailing 16-byte sync marker
+ self.serialized_data = self.serialized_data[:-16]
def can_get_serialized_length(self):
return True
@@ -1372,7 +1378,8 @@ def codegen_for_lib(library, library_options, data):
return ArduinoJSON(data, bufsize = 512)
if library == 'avro':
- return Avro(data)
+ strip_schema = bool(int(library_options[0]))
+ return Avro(data, strip_schema = strip_schema)
if library == 'capnproto_c':
packed = bool(int(library_options[0]))