forked from osmocom/wireshark
asterix: minor cleanup in decoding subitems
The "VALUE" string should not be displayed for generated subitem levels.
This commit is contained in:
parent
b4e74af118
commit
99ab96555a
File diff suppressed because it is too large
Load Diff
|
@ -15,6 +15,7 @@ import urllib.request
|
|||
import json
|
||||
from copy import copy
|
||||
from itertools import chain, repeat
|
||||
from functools import reduce
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
|
@ -297,12 +298,39 @@ def get_bit_size(item):
|
|||
|
||||
def get_description(item, content=None):
|
||||
"""Return item description."""
|
||||
result = item['name']
|
||||
if item['title']:
|
||||
result += ', {}'.format(item['title'])
|
||||
name = item['name'] if not is_generated(item) else None
|
||||
title = item.get('title')
|
||||
if content is not None and content.get('unit'):
|
||||
result += ', [{}]'.format(replace_unicode(content['unit']))
|
||||
return result
|
||||
unit = '[{}]'.format(replace_unicode(content['unit']))
|
||||
else:
|
||||
unit = None
|
||||
|
||||
parts = filter(lambda x: bool(x), [name, title, unit])
|
||||
if not parts:
|
||||
return ''
|
||||
return reduce(lambda a,b: a + ', ' + b, parts)
|
||||
|
||||
def generate_group(item, variation=None):
|
||||
"""Generate group-item from element-item."""
|
||||
level2 = copy(item)
|
||||
level2['name'] = 'VALUE'
|
||||
level2['is_generated'] = True
|
||||
if variation is None:
|
||||
level1 = copy(item)
|
||||
level1['variation'] = {
|
||||
'type': 'Group',
|
||||
'items': [level2],
|
||||
}
|
||||
else:
|
||||
level2['variation'] = variation['variation']
|
||||
level1 = {
|
||||
'type': "Group",
|
||||
'items': [level2],
|
||||
}
|
||||
return level1
|
||||
|
||||
def is_generated(item):
|
||||
return item.get('is_generated') is not None
|
||||
|
||||
def part1(ctx, get_ref, catalogue):
|
||||
"""Generate components in order
|
||||
|
@ -446,13 +474,7 @@ def part1(ctx, get_ref, catalogue):
|
|||
|
||||
# Group is required below this item.
|
||||
if variation['variation']['type'] == 'Element':
|
||||
subitem = copy(item)
|
||||
subitem['variation'] = variation['variation']
|
||||
subitem['name'] = 'VALUE'
|
||||
subvar = {
|
||||
'type': "Group",
|
||||
'items': [subitem],
|
||||
}
|
||||
subvar = generate_group(item, variation)
|
||||
else:
|
||||
subvar = variation['variation']
|
||||
handle_variation(path, subvar)
|
||||
|
@ -486,14 +508,7 @@ def part1(ctx, get_ref, catalogue):
|
|||
continue
|
||||
# Group is required below this item.
|
||||
if i['variation']['type'] == 'Element':
|
||||
level2 = copy(i)
|
||||
level2['name'] = 'VALUE'
|
||||
level1 = copy(i)
|
||||
level1['variation'] = {
|
||||
'items': [level2],
|
||||
'type': 'Group',
|
||||
}
|
||||
subitem = level1
|
||||
subitem = generate_group(i)
|
||||
else:
|
||||
subitem = i
|
||||
comp += ' &I{}_{},'.format(ref, subitem['name'])
|
||||
|
@ -513,12 +528,7 @@ def part1(ctx, get_ref, catalogue):
|
|||
|
||||
# Group is required on the first level.
|
||||
if path == [] and item['variation']['type'] == 'Element':
|
||||
level2 = copy(item)
|
||||
level2['name'] = 'VALUE'
|
||||
variation = {
|
||||
'items': [level2],
|
||||
'type': "Group",
|
||||
}
|
||||
variation = generate_group(item)['variation']
|
||||
else:
|
||||
variation = item['variation']
|
||||
handle_variation(path + [item['name']], variation)
|
||||
|
|
Loading…
Reference in New Issue