-
Notifications
You must be signed in to change notification settings - Fork 0
/
etimodel.py
55 lines (48 loc) · 1.37 KB
/
etimodel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# SPDX-FileCopyrightText: © 2021 Georg Sauthoff <mail@gms.tf>
# SPDX-License-Identifier: GPL-2.0-or-later
import itertools
# XXX also move other shared functions:
#
# get_data_types
# get_structs
# get_templates
# group_members
# is_counter
# is_elementary
# is_enum
# is_fixed_string
# is_int
# is_padding
# is_unsigned
# is_var_string
# pp_int_type
# type_to_fmt
def get_max_sizes(st, dt):
h = {}
for name, e in dt.items():
v = e.get('size', '0')
h[name] = int(v)
for name, e in itertools.chain((i for i in st.items() if i[1].get('type') != 'Message'),
(i for i in st.items() if i[1].get('type') == 'Message')):
s = 0
for m in e:
x = h.get(m.get('type'), 0)
s += x * int(m.get('cardinality'))
h[name] = s
return h
def get_min_sizes(st, dt):
h = {}
for name, e in dt.items():
v = e.get('size', '0')
if e.get('variableSize') is None:
h[name] = int(v)
else:
h[name] = 0
for name, e in itertools.chain((i for i in st.items() if i[1].get('type') != 'Message'),
(i for i in st.items() if i[1].get('type') == 'Message')):
s = 0
for m in e:
x = h.get(m.get('type'), 0)
s += x * int(m.get('minCardinality', '1'))
h[name] = s
return h