pyloxi: include all members in OFClass.members
This preserves ordering, which is important because we can't rely on the offset
field for sorting (it may be -1).
The newly passing show() tests are due to the side effect of removing type
fields from pretty printing.
diff --git a/py_gen/codegen.py b/py_gen/codegen.py
index 9765815..45adc5d 100644
--- a/py_gen/codegen.py
+++ b/py_gen/codegen.py
@@ -32,8 +32,7 @@
import util
import oftype
-OFClass = namedtuple('OFClass', ['name', 'pyname',
- 'members', 'length_member', 'type_members',
+OFClass = namedtuple('OFClass', ['name', 'pyname', 'members', 'type_members',
'min_length', 'is_fixed_length'])
Member = namedtuple('Member', ['name', 'oftype', 'offset', 'skip'])
LengthMember = namedtuple('LengthMember', ['name', 'oftype', 'offset'])
@@ -102,23 +101,22 @@
type_values = get_type_values(cls, version)
members = []
-
- length_member = None
type_members = []
+
pad_count = 0
for member in unified_class['members']:
if member['name'] in ['length', 'len']:
- length_member = LengthMember(name=member['name'],
- offset=member['offset'],
- oftype=oftype.OFType(member['m_type'], version))
+ members.append(LengthMember(name=member['name'],
+ offset=member['offset'],
+ oftype=oftype.OFType(member['m_type'], version)))
elif member['name'] in type_values:
- type_members.append(TypeMember(name=member['name'],
- offset=member['offset'],
- oftype=oftype.OFType(member['m_type'], version),
- value=type_values[member['name']]))
- else:
- # HACK ensure member names are unique
+ members.append(TypeMember(name=member['name'],
+ offset=member['offset'],
+ oftype=oftype.OFType(member['m_type'], version),
+ value=type_values[member['name']]))
+ type_members.append(members[-1])
+ else: # HACK ensure member names are unique
if member['name'].startswith("pad"):
if pad_count == 0:
m_name = 'pad'
@@ -136,7 +134,6 @@
OFClass(name=cls,
pyname=pyname,
members=members,
- length_member=length_member,
type_members=type_members,
min_length=of_g.base_length[(cls, version)],
is_fixed_length=(cls, version) in of_g.is_fixed_length))