From: Christopher Peplin Date: Mon, 30 Sep 2013 20:07:27 +0000 (-0400) Subject: Use a container type to be able to stream protobufs. X-Git-Tag: 3.99.1~103^2~58 X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=commitdiff_plain;h=1820baf320d5831815de35dddbbfc5818a0e004b;p=apps%2Flow-level-can-service.git Use a container type to be able to stream protobufs. --- diff --git a/benchmark/proto/compare_sizes.py b/benchmark/proto/compare_sizes.py index b6936df..192716f 100755 --- a/benchmark/proto/compare_sizes.py +++ b/benchmark/proto/compare_sizes.py @@ -26,6 +26,8 @@ for trace_file in sys.argv[1:]: except ValueError: continue + message = openxc_pb2.VehicleMessage() + if 'id' and 'data' in json_message: # rough approx. that CAN messages are 10 bytes - they could be less # but most of ours are full 64+11 bits @@ -34,18 +36,24 @@ for trace_file in sys.argv[1:]: binary_message = openxc_pb2.RawMessage() binary_message.message_id = json_message['id'] binary_message.data = int(json_message['data'], 0) - total_raw_binary_size += len(binary_message.SerializeToString()) + message.type = openxc_pb2.VehicleMessage.RAW + message.raw_message = binary_message + total_raw_binary_size += len(message.SerializeToString()) else: if isinstance(json_message['value'], bool): - binary_message = openxc_pb2.TranslatedBooleanMessage() + message.type = openxc_pb2.VehicleMessage.BOOL + message.boolean_message.name = json_message['name'] + message.boolean_message.value = json_message['value'] elif isinstance(json_message['value'], numbers.Number): - binary_message = openxc_pb2.TranslatedNumericMessage() + message.type = openxc_pb2.VehicleMessage.NUM + message.numerical_message.name = json_message['name'] + message.numerical_message.value = json_message['value'] else: - binary_message = openxc_pb2.TranslatedStringMessage() - binary_message.name = json_message['name'] - binary_message.value = json_message['value'] + message.type = openxc_pb2.VehicleMessage.STRING + message.string_message.name = json_message['name'] + message.string_message.value = json_message['value'] total_translated_json_size += len(line) - total_translated_binary_size += len(binary_message.SerializeToString()) + total_translated_binary_size += len(message.SerializeToString()) print("For the %d trace files given..." % len(sys.argv[1:])) diff --git a/benchmark/proto/openxc.proto b/benchmark/proto/openxc.proto index 0e39bb6..1917b0b 100644 --- a/benchmark/proto/openxc.proto +++ b/benchmark/proto/openxc.proto @@ -1,5 +1,16 @@ package openxc; +message VehicleMessage { + enum Type { RAW = 1; STRING = 2; NUM = 3; BOOL = 4; } + + optional Type type = 1; + + optional RawMessage raw_message = 2; + optional TranslatedStringMessage string_message = 3; + optional TranslatedNumericMessage numerical_message = 4; + optional TranslatedBooleanMessage boolean_message = 5; +} + message RawMessage { optional uint32 message_id = 1; optional double data = 2;