java_gen: align messages (for OFMatchv3)
diff --git a/java_gen/java_model.py b/java_gen/java_model.py
index f603411..a894179 100644
--- a/java_gen/java_model.py
+++ b/java_gen/java_model.py
@@ -354,6 +354,10 @@
def is_extension(self):
return type_maps.message_is_extension(self.c_name, -1)
+ @property
+ def align(self):
+ return int(self.ir_class.params['align']) if 'align' in self.ir_class.params else 0
+
#######################################################################
### Member
#######################################################################
diff --git a/java_gen/templates/of_class.java b/java_gen/templates/of_class.java
index fb1d027..05018d3 100644
--- a/java_gen/templates/of_class.java
+++ b/java_gen/templates/of_class.java
@@ -153,6 +153,11 @@
// fixme: todo ${prop.name}
//:: #endif
//:: #endfor
+ //:: if msg.align:
+ // align message to ${msg.align} bytes
+ bb.skipBytes(((length + ${msg.align-1})/${msg.align} * ${msg.align} ) - length );
+ //:: #endif
+
return new ${impl_class}(
${",\n ".join(
[ prop.name for prop in msg.data_members])}
@@ -205,13 +210,14 @@
//:: #endif
//:: #endfor
-//:: if msg.is_fixed_length:
- return LENGTH;
-//:: else:
+//:: if not msg.is_fixed_length:
// update length field
int length = bb.writerIndex() - startIndex;
bb.setShort(startIndex + 2, length);
- return length;
+ //:: if msg.align:
+ // align message to ${msg.align} bytes
+ bb.writeZero( ((length + ${msg.align-1})/${msg.align} * ${msg.align}) - length);
+ //:: #endif
//:: #end
}