Put redundant type checking in a nested function
@@ -88,23 +88,24 @@ def _create_message_encode_decode_formats(signals):
big_fmt = ''
start = 0
- for signal in signals:
- if signal.byte_order == 'little_endian':
- continue
-
+ def get_format_string_type(signal):
if signal.is_float:
- signal_type = 'f'
+ return 'f'
elif signal.is_signed:
- signal_type = 's'
+ return 's'
else:
- signal_type = 'u'
+ return 'u'
+
+ for signal in signals:
+ if signal.byte_order == 'little_endian':
+ continue
padding = (signal.start - start)
if padding > 0:
big_fmt += 'p{}'.format(padding)
- big_fmt += '{}{}'.format(signal_type, signal.length)
+ big_fmt += '{}{}'.format(get_format_string_type(signal), signal.length)
start = (signal.start + signal.length)
if start < 64:
@@ -118,19 +119,12 @@ def _create_message_encode_decode_formats(signals):
if signal.byte_order == 'big_endian':
continue
- if signal.is_float:
- signal_type = 'f'
- elif signal.is_signed:
- signal_type = 's'
- else:
- signal_type = 'u'
-
padding = end - (signal.start + signal.length)
if padding > 0:
little_fmt += 'p{}'.format(padding)
- little_fmt += '{}{}'.format(signal_type, signal.length)
+ little_fmt += '{}{}'.format(get_format_string_type(signal), signal.length)
end = signal.start
if end > 0:
