Various improvements for pre-written base types (U8 etc.)
diff --git a/java_gen/java_model.py b/java_gen/java_model.py
index d7f7370..944b536 100644
--- a/java_gen/java_model.py
+++ b/java_gen/java_model.py
@@ -617,10 +617,14 @@
if self.is_fixed_value:
return self.enum_value
+ elif java_type == "OFOxmList":
+ return "OFOxmList.EMPTY"
elif re.match(r'List.*', java_type):
return "Collections.emptyList()"
elif java_type == "boolean":
return "false";
+ elif self.java_type.is_array:
+ return "new %s[0]" % java_type[:-2]
elif java_type in ("byte", "char", "short", "int", "long"):
return "({0}) 0".format(java_type);
else:
diff --git a/java_gen/java_type.py b/java_gen/java_type.py
index c98df81..e7f2201 100644
--- a/java_gen/java_type.py
+++ b/java_gen/java_type.py
@@ -219,7 +219,7 @@
u32obj = JType('U32', 'U32') \
.op(read='U32.of(bb.readInt())', write='bb.writeInt($name.getRaw())')
u64 = JType('U64', 'U64') \
- .op(read='U64.of(bb.readLong())', write='bb.writeLong($name.getValue())')
+ .op(read='U64.ofRaw(bb.readLong())', write='bb.writeLong($name.getValue())')
of_port = JType("OFPort") \
.op(version=1, read="OFPort.read2Bytes(bb)", write="$name.write2Bytes(bb)") \
.op(version=ANY, read="OFPort.read4Bytes(bb)", write="$name.write4Bytes(bb)")
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/OFMetadata.java b/java_gen/pre-written/src/main/java/org/openflow/types/OFMetadata.java
index e27679c..e82bc40 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/OFMetadata.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/OFMetadata.java
@@ -2,36 +2,43 @@
import org.jboss.netty.buffer.ChannelBuffer;
-public class OFMetadata extends U64 implements OFValueType<OFMetadata> {
-
+public class OFMetadata implements OFValueType<OFMetadata> {
+
private static int LENGTH = 8;
- public static final OFMetadata NO_MASK = OFMetadata.of(0xFFFFFFFFFFFFFFFFl);
- public static final OFMetadata FULL_MASK = OFMetadata.of(0x0);
+ private final U64 u64;
- protected OFMetadata(long raw) {
- super(raw);
+ public static final OFMetadata NO_MASK = OFMetadata.of(U64.ofRaw(0xFFFFFFFFFFFFFFFFl));
+ public static final OFMetadata FULL_MASK = OFMetadata.of(U64.ofRaw(0x0));
+
+ public OFMetadata(U64 ofRaw) {
+ u64 = ofRaw;
}
- public static OFMetadata of(long raw) {
- return new OFMetadata(raw);
+ public static OFMetadata of(U64 u64) {
+ return new OFMetadata(u64);
}
-
+
+ public static OFMetadata ofRaw(long raw) {
+ return new OFMetadata(U64.ofRaw(raw));
+ }
+
public static OFMetadata read8Bytes(ChannelBuffer cb) {
- return OFMetadata.of(cb.readLong());
+ return OFMetadata.ofRaw(cb.readLong());
}
-
+
public void write8Bytes(ChannelBuffer cb) {
- cb.writeLong(super.getValue());
+ u64.writeTo(cb);
}
@Override
public int getLength() {
- return LENGTH;
+ return u64.getLength();
}
@Override
public OFMetadata applyMask(OFMetadata mask) {
- return OFMetadata.of(this.getValue() & mask.getValue());
+ return OFMetadata.of(this.u64.applyMask(mask.u64));
}
+
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/U16.java b/java_gen/pre-written/src/main/java/org/openflow/types/U16.java
index 5884adc..54e72c1 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/U16.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/U16.java
@@ -17,7 +17,12 @@
package org.openflow.types;
-public class U16 {
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.openflow.exceptions.OFParseError;
+import org.openflow.protocol.OFMessageReader;
+import org.openflow.protocol.Writeable;
+
+public class U16 implements Writeable, OFValueType<U16> {
public static int f(final short i) {
return i & 0xffff;
}
@@ -25,4 +30,79 @@
public static short t(final int l) {
return (short) l;
}
+
+ private final short raw;
+
+ private U16(short raw) {
+ this.raw = raw;
+ }
+
+ public static final U16 of(int value) {
+ return new U16(t(value));
+ }
+
+ public static final U16 ofRaw(short value) {
+ return new U16(value);
+ }
+
+ public int getValue() {
+ return f(raw);
+ }
+
+ public short getRaw() {
+ return raw;
+ }
+
+ @Override
+ public String toString() {
+ return "" + f(raw);
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + raw;
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ U16 other = (U16) obj;
+ if (raw != other.raw)
+ return false;
+ return true;
+ }
+
+
+ @Override
+ public void writeTo(ChannelBuffer bb) {
+ bb.writeShort(raw);
+ }
+
+
+ public final static Reader READER = new Reader();
+
+ private static class Reader implements OFMessageReader<U16> {
+ @Override
+ public U16 readFrom(ChannelBuffer bb) throws OFParseError {
+ return ofRaw(bb.readShort());
+ }
+ }
+
+ @Override
+ public int getLength() {
+ return 2;
+ }
+
+ @Override
+ public U16 applyMask(U16 mask) {
+ return ofRaw( (short) (raw & mask.raw));
+ }
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/U32.java b/java_gen/pre-written/src/main/java/org/openflow/types/U32.java
index 527e778..9cd181c 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/U32.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/U32.java
@@ -22,7 +22,7 @@
import org.openflow.protocol.OFMessageReader;
import org.openflow.protocol.Writeable;
-public class U32 implements Writeable {
+public class U32 implements Writeable, OFValueType<U32> {
private final int raw;
private U32(int raw) {
@@ -69,6 +69,7 @@
U32 other = (U32) obj;
if (raw != other.raw)
return false;
+
return true;
}
@@ -94,4 +95,14 @@
}
}
+ @Override
+ public int getLength() {
+ return 4;
+ }
+
+ @Override
+ public U32 applyMask(U32 mask) {
+ return ofRaw(raw & mask.raw);
+ }
+
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/U64.java b/java_gen/pre-written/src/main/java/org/openflow/types/U64.java
index 7871445..5c69a7c 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/U64.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/U64.java
@@ -19,7 +19,10 @@
import java.math.BigInteger;
-public class U64 {
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.openflow.protocol.Writeable;
+
+public class U64 implements Writeable, OFValueType<U64> {
private static final long UNSIGNED_MASK = 0x7fffffffffffffffL;
private final long raw;
@@ -28,7 +31,11 @@
this.raw = raw;
}
- public static U64 of(final long raw) {
+ public static U64 of(long raw) {
+ return ofRaw(raw);
+ }
+
+ public static U64 ofRaw(final long raw) {
return new U64(raw);
}
@@ -87,4 +94,19 @@
return true;
}
+ @Override
+ public int getLength() {
+ return 8;
+ }
+
+ @Override
+ public U64 applyMask(U64 mask) {
+ return ofRaw(raw & mask.raw);
+ }
+
+ @Override
+ public void writeTo(ChannelBuffer bb) {
+ bb.writeLong(raw);
+ }
+
}
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/U8.java b/java_gen/pre-written/src/main/java/org/openflow/types/U8.java
index 2bd34bf..c15be0e 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/U8.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/U8.java
@@ -22,7 +22,7 @@
import org.openflow.protocol.OFMessageReader;
import org.openflow.protocol.Writeable;
-public class U8 implements Writeable {
+public class U8 implements Writeable, OFValueType<U8> {
private final byte raw;
private U8(byte raw) {
@@ -96,4 +96,14 @@
}
}
+ @Override
+ public int getLength() {
+ return 1;
+ }
+
+ @Override
+ public U8 applyMask(U8 mask) {
+ return ofRaw( (byte) (raw & mask.raw));
+ }
+
}
diff --git a/java_gen/pre-written/src/test/java/org/openflow/types/U64Test.java b/java_gen/pre-written/src/test/java/org/openflow/types/U64Test.java
index 16d3d3e..aefd193 100644
--- a/java_gen/pre-written/src/test/java/org/openflow/types/U64Test.java
+++ b/java_gen/pre-written/src/test/java/org/openflow/types/U64Test.java
@@ -11,16 +11,16 @@
@Test
public void testPositiveRaws() {
for(long positive: new long[] { 0, 1, 100, Long.MAX_VALUE }) {
- assertEquals(positive, U64.of(positive).getValue());
- assertEquals(BigInteger.valueOf(positive), U64.of(positive).getBigInteger());
+ assertEquals(positive, U64.ofRaw(positive).getValue());
+ assertEquals(BigInteger.valueOf(positive), U64.ofRaw(positive).getBigInteger());
}
}
@Test
public void testNegativeRaws() {
long minus_1 = 0xFFffFFffFFffFFffL;
- assertEquals(minus_1, U64.of(minus_1).getValue());
- assertEquals(new BigInteger("FFffFFffFFffFFff", 16), U64.of(minus_1).getBigInteger());
- assertEquals(new BigInteger("18446744073709551615"), U64.of(minus_1).getBigInteger());
+ assertEquals(minus_1, U64.ofRaw(minus_1).getValue());
+ assertEquals(new BigInteger("FFffFFffFFffFFff", 16), U64.ofRaw(minus_1).getBigInteger());
+ assertEquals(new BigInteger("18446744073709551615"), U64.ofRaw(minus_1).getBigInteger());
}
}