pyloxi: slightly generalize alignment

The _pack and _unpack templates should not be matching on particular class
names. Move the decision up a few levels to codegen.
diff --git a/py_gen/templates/_pack.py b/py_gen/templates/_pack.py
index 534e930..9956cf6 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.name == 'of_action_set_field':
+:: 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')}
 :: #endif
-:: if ofclass.name == 'of_match_v3':
+:: 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 133e831..09a0e08 100644
--- a/py_gen/templates/_unpack.py
+++ b/py_gen/templates/_unpack.py
@@ -53,6 +53,6 @@
         obj.${m.name} = ${gen_unpack_expr(m.oftype, reader_expr)}
 ::     #endif
 :: #endfor
-:: if ofclass.name == 'of_match_v3':
-        reader.skip((_length + 7)/8*8 - _length)
+:: if ofclass.has_external_alignment or ofclass.has_internal_alignment:
+        reader.skip_align()
 :: #endif
diff --git a/py_gen/templates/generic_util.py b/py_gen/templates/generic_util.py
index eca828c..28d3b5f 100644
--- a/py_gen/templates/generic_util.py
+++ b/py_gen/templates/generic_util.py
@@ -109,6 +109,12 @@
             raise loxi.ProtocolError("Buffer too short")
         self.offset += length
 
+    def skip_align(self):
+        new_offset = (self.offset + 7) / 8 * 8
+        if new_offset > len(self.buf):
+            raise loxi.ProtocolError("Buffer too short")
+        self.offset = new_offset
+
     def is_empty(self):
         return self.offset == len(self.buf)