java_gen: update pre-written types
allow for instances of U8,U32, U64
diff --git a/java_gen/pre-written/src/main/java/org/openflow/types/OFPhysicalPort.java b/java_gen/pre-written/src/main/java/org/openflow/types/OFPhysicalPort.java
index 7755a4a..6eb07b1 100644
--- a/java_gen/pre-written/src/main/java/org/openflow/types/OFPhysicalPort.java
+++ b/java_gen/pre-written/src/main/java/org/openflow/types/OFPhysicalPort.java
@@ -2,6 +2,8 @@
import org.jboss.netty.buffer.ChannelBuffer;
import org.openflow.exceptions.OFParseError;
+import org.openflow.protocol.OFMessageReader;
+import org.openflow.protocol.Writeable;
/**
* A wrapper around the OpenFlow physical port description. The interfaces to
@@ -10,16 +12,16 @@
* @author capveg
*/
-public class OFPhysicalPort implements OFValueType<OFPhysicalPort> {
+public class OFPhysicalPort implements OFValueType<OFPhysicalPort>, Writeable {
static final int LENGTH = 4;
-
+
private final int port;
-
+
private OFPhysicalPort(int port) {
this.port = port;
}
-
+
public static OFPhysicalPort of(int port) {
return new OFPhysicalPort(port);
}
@@ -56,6 +58,11 @@
c.writeInt(this.port);
}
+ @Override
+ public void writeTo(ChannelBuffer bb) {
+ write4Bytes(bb);
+ }
+
public static OFPhysicalPort read4Bytes(ChannelBuffer c) throws OFParseError {
return OFPhysicalPort.of((int)(c.readUnsignedInt() & 0xFFFFFFFF));
}
@@ -68,4 +75,13 @@
public int getPortNumber() {
return port;
}
+
+ public final static Reader READER = new Reader();
+ private static class Reader implements OFMessageReader<OFPhysicalPort> {
+ @Override
+ public OFPhysicalPort readFrom(ChannelBuffer bb) throws OFParseError {
+ return OFPhysicalPort.read4Bytes(bb);
+ }
+
+ }
}
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 003f35d..88d6b15 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
@@ -17,7 +17,61 @@
package org.openflow.types;
-public class U32 {
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.openflow.exceptions.OFParseError;
+import org.openflow.protocol.OFMessageReader;
+import org.openflow.protocol.Writeable;
+
+public class U32 implements Writeable {
+ private final int raw;
+
+ private U32(int raw) {
+ this.raw = raw;
+ }
+
+ public static U32 of(long value) {
+ return new U32(U32.t(value));
+ }
+
+ public static U32 ofRaw(int value) {
+ return new U32(value);
+ }
+
+ long getValue() {
+ return f(raw);
+ }
+
+ int 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;
+ U32 other = (U32) obj;
+ if (raw != other.raw)
+ return false;
+ return true;
+ }
+
public static long f(final int i) {
return i & 0xffffffffL;
}
@@ -25,4 +79,19 @@
public static int t(final long l) {
return (int) l;
}
+
+ @Override
+ public void writeTo(ChannelBuffer bb) {
+ bb.writeInt(raw);
+ }
+
+ public final static Reader READER = new Reader();
+
+ private static class Reader implements OFMessageReader<U32> {
+ @Override
+ public U32 readFrom(ChannelBuffer bb) throws OFParseError {
+ return new U32(bb.readInt());
+ }
+ }
+
}
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 a46ded3..750398f 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
@@ -64,4 +64,27 @@
public static long t(final BigInteger l) {
return l.longValue();
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + (int) (raw ^ (raw >>> 32));
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ U64 other = (U64) obj;
+ if (raw != other.raw)
+ return false;
+ return true;
+ }
+
}
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 1cdf0e5..2bd34bf 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
@@ -17,8 +17,66 @@
package org.openflow.types;
-public class U8 {
- byte data;
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.openflow.exceptions.OFParseError;
+import org.openflow.protocol.OFMessageReader;
+import org.openflow.protocol.Writeable;
+
+public class U8 implements Writeable {
+ private final byte raw;
+
+ private U8(byte raw) {
+ this.raw = raw;
+ }
+
+ public static final U8 of(short value) {
+ return new U8(t(value));
+ }
+
+ public static final U8 ofRaw(byte value) {
+ return new U8(value);
+ }
+
+ public short getValue() {
+ return f(raw);
+ }
+
+ public byte 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;
+ U8 other = (U8) obj;
+ if (raw != other.raw)
+ return false;
+ return true;
+ }
+
+
+ @Override
+ public void writeTo(ChannelBuffer bb) {
+ bb.writeByte(raw);
+ }
public static short f(final byte i) {
return (short) (i & 0xff);
@@ -28,7 +86,14 @@
return (byte) l;
}
- public byte getValue() {
- return data;
+
+ public final static Reader READER = new Reader();
+
+ private static class Reader implements OFMessageReader<U8> {
+ @Override
+ public U8 readFrom(ChannelBuffer bb) throws OFParseError {
+ return new U8(bb.readByte());
+ }
}
+
}