From 5ca214b8c2fec4506aa06970bf84a908f02d425d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 8 Oct 2022 15:23:56 +1100 Subject: [PATCH] parser: added OVERRIDE_SIGNATURE this allows for DSDL with an overridden signature, allowing for a message to be moved in the DSDL tree while maintaining compatibility with an existing vendor message for an example see https://github.com/dronecan/DSDL/pull/16 --- dronecan/dsdl/parser.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/dronecan/dsdl/parser.py b/dronecan/dsdl/parser.py index 661c05f..509660f 100644 --- a/dronecan/dsdl/parser.py +++ b/dronecan/dsdl/parser.py @@ -298,6 +298,8 @@ def get_dsdl_signature(self): Computes DSDL signature of this type. Please refer to the specification for details about signatures. """ + if self.override_signature is not None: + return self.override_signature return compute_signature(self.get_dsdl_signature_source_definition()) def get_normalized_definition(self): @@ -641,6 +643,7 @@ def parse_source(self, filename, source_text): fields, constants, resp_fields, resp_constants = [], [], [], [] union, resp_union = False, False response_part = False + override_signature = None for num, tokens in numbered_lines: try: if tokens == ['---']: @@ -656,6 +659,11 @@ def parse_source(self, filename, source_text): enforce(not union, 'Data structure has already been declared as union') union = True continue + + if len(tokens) == 2 and tokens[0] == 'OVERRIDE_SIGNATURE': + override_signature = int(tokens[1],16) + continue + attr = self._parse_line(filename, tokens) if attr.name and attr.name in all_attributes_names: error('Duplicated attribute name [%s]', attr.name) @@ -682,6 +690,7 @@ def parse_source(self, filename, source_text): t.response_constants = resp_constants t.request_union = union t.response_union = resp_union + t.override_signature = override_signature max_bitlen = t.get_max_bitlen_request(), t.get_max_bitlen_response() max_bytelen = tuple(map(bitlen_to_bytelen, max_bitlen)) else: @@ -689,6 +698,7 @@ def parse_source(self, filename, source_text): t.fields = fields t.constants = constants t.union = union + t.override_signature = override_signature max_bitlen = t.get_max_bitlen() max_bytelen = bitlen_to_bytelen(max_bitlen)