ir: add alignment properties to OFClass
Updated pyloxi to use the new properties. Unpack now uses `has_external_alignment`
because internal alignment would be handled by slicing based on the length field.
diff --git a/loxi_ir/ir.py b/loxi_ir/ir.py
index 3785a6f..df1c77d 100644
--- a/loxi_ir/ir.py
+++ b/loxi_ir/ir.py
@@ -175,6 +175,14 @@
else:
raise Exception("Not a fixed length class: {}".format(self.name))
+ @property
+ def has_internal_alignment(self):
+ return self.params.get('length_includes_align') == 'True'
+
+ @property
+ def has_external_alignment(self):
+ return self.params.get('length_includes_align') == 'False'
+
""" one class unified across openflow versions. Keeps around a map version->versioned_class """
class OFUnifiedClass(OFClass):
def __new__(cls, version_classes, *a, **kw):
diff --git a/py_gen/templates/_pack.py b/py_gen/templates/_pack.py
index c292525..0525ef2 100644
--- a/py_gen/templates/_pack.py
+++ b/py_gen/templates/_pack.py
@@ -56,12 +56,12 @@
:: #endfor
:: if length_member_index != None:
length = sum([len(x) for x in packed])
-:: if ofclass.params.get('length_includes_align') == 'True':
+:: if ofclass.has_internal_alignment:
packed.append(loxi.generic_util.pad_to(8, length))
length += len(packed[-1])
:: #endif
packed[${length_member_index}] = ${gen_pack_expr(length_member.oftype, 'length', version=version)}
:: #endif
-:: if ofclass.params.get('length_includes_align') == 'False':
+:: if ofclass.has_external_alignment:
packed.append(loxi.generic_util.pad_to(8, length))
:: #endif
diff --git a/py_gen/templates/_unpack.py b/py_gen/templates/_unpack.py
index 90e5bf2..81f74c7 100644
--- a/py_gen/templates/_unpack.py
+++ b/py_gen/templates/_unpack.py
@@ -51,6 +51,6 @@
obj.${m.name} = ${gen_unpack_expr(m.oftype, reader_expr, version=version)}
:: #endif
:: #endfor
-:: if ofclass.params.get('length_includes_align') != None:
+:: if ofclass.has_external_alignment:
orig_reader.skip_align()
:: #endif