Skip to content

Commit

Permalink
parser: added OVERRIDE_SIGNATURE
Browse files Browse the repository at this point in the history
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 dronecan/DSDL#16
  • Loading branch information
tridge committed Oct 8, 2022
1 parent 2e673de commit 5ca214b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions dronecan/dsdl/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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 == ['---']:
Expand All @@ -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)
Expand All @@ -682,13 +690,15 @@ 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:
t = CompoundType(full_typename, CompoundType.KIND_MESSAGE, filename, default_dtid, version, 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)

Expand Down

0 comments on commit 5ca214b

Please sign in to comment.