summaryrefslogtreecommitdiff
path: root/java/common/src/main/java/org/apache/qpid/framing/AMQType.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/common/src/main/java/org/apache/qpid/framing/AMQType.java')
-rw-r--r--java/common/src/main/java/org/apache/qpid/framing/AMQType.java138
1 files changed, 56 insertions, 82 deletions
diff --git a/java/common/src/main/java/org/apache/qpid/framing/AMQType.java b/java/common/src/main/java/org/apache/qpid/framing/AMQType.java
index 4bce1ca5f0..ad07634554 100644
--- a/java/common/src/main/java/org/apache/qpid/framing/AMQType.java
+++ b/java/common/src/main/java/org/apache/qpid/framing/AMQType.java
@@ -28,35 +28,39 @@ public enum AMQType
//AMQP FieldTable Wire Types
- DECIMAL('D')
+ LONG_STRING('S')
{
-
public int getEncodingSize(Object value)
{
- // TODO : fixme
- throw new UnsupportedOperationException();
+ return EncodingUtils.encodedLongStringLength((String) value);
}
- public Object toNativeValue(Object value)
+
+ public String toNativeValue(Object value)
{
- // TODO : fixme
- throw new UnsupportedOperationException();
+ if (value != null)
+ {
+ return value.toString();
+ }
+ else
+ {
+ throw new NullPointerException("Cannot convert: null to String.");
+ }
}
public void writeValueImpl(Object value, ByteBuffer buffer)
{
- // TODO : fixme
- throw new UnsupportedOperationException();
+ EncodingUtils.writeLongStringBytes(buffer, (String) value);
}
public Object readValueFromBuffer(ByteBuffer buffer)
{
- // TODO : fixme
- throw new UnsupportedOperationException();
+ return EncodingUtils.readLongString(buffer);
}
+
},
- UNSIGNED_SHORT('S')
+ INTEGER('I')
{
public int getEncodingSize(Object value)
@@ -65,6 +69,7 @@ public enum AMQType
throw new UnsupportedOperationException();
}
+
public Object toNativeValue(Object value)
{
// TODO : fixme
@@ -82,10 +87,9 @@ public enum AMQType
// TODO : fixme
throw new UnsupportedOperationException();
}
-
},
- UNSIGNED_INT('I')
+ DECIMAL('D')
{
public int getEncodingSize(Object value)
@@ -94,7 +98,6 @@ public enum AMQType
throw new UnsupportedOperationException();
}
-
public Object toNativeValue(Object value)
{
// TODO : fixme
@@ -114,7 +117,7 @@ public enum AMQType
}
},
- UNSIGNED_LONG('L')
+ TIMESTAMP('T')
{
public int getEncodingSize(Object value)
@@ -124,7 +127,7 @@ public enum AMQType
}
- public Long toNativeValue(Object value)
+ public Object toNativeValue(Object value)
{
// TODO : fixme
throw new UnsupportedOperationException();
@@ -143,9 +146,8 @@ public enum AMQType
}
},
- EXTTENDED('D')
+ FIELD_TABLE('F')
{
-
public int getEncodingSize(Object value)
{
// TODO : fixme
@@ -172,35 +174,39 @@ public enum AMQType
}
},
- TIMESTAMP('T')
+ VOID('V')
{
-
public int getEncodingSize(Object value)
{
- // TODO : fixme
- throw new UnsupportedOperationException();
+ return 0;
}
public Object toNativeValue(Object value)
{
- // TODO : fixme
- throw new UnsupportedOperationException();
+ if (value == null)
+ {
+ return null;
+ }
+ else
+ {
+ throw new NumberFormatException("Cannot convert: " + value + "(" +
+ value.getClass().getName() + ") to null String.");
+ }
}
public void writeValueImpl(Object value, ByteBuffer buffer)
{
- // TODO : fixme
- throw new UnsupportedOperationException();
}
public Object readValueFromBuffer(ByteBuffer buffer)
{
- // TODO : fixme
- throw new UnsupportedOperationException();
+ return null;
}
},
+ // Extended types
+
BINARY('x')
{
public int getEncodingSize(Object value)
@@ -299,38 +305,6 @@ public enum AMQType
}
},
- NULL_STRING('n')
- {
-
- public int getEncodingSize(Object value)
- {
- return 0;
- }
-
-
- public String toNativeValue(Object value)
- {
- if (value == null)
- {
- return null;
- }
- else
- {
- throw new NumberFormatException("Cannot convert: " + value + "(" +
- value.getClass().getName() + ") to null String.");
- }
- }
-
- public void writeValueImpl(Object value, ByteBuffer buffer)
- {
- }
-
- public Object readValueFromBuffer(ByteBuffer buffer)
- {
- return null;
- }
- },
-
BOOLEAN('t')
{
public int getEncodingSize(Object value)
@@ -368,77 +342,77 @@ public enum AMQType
}
},
- BYTE('b')
+ ASCII_CHARACTER('k')
{
public int getEncodingSize(Object value)
{
- return EncodingUtils.encodedByteLength();
+ return EncodingUtils.encodedCharLength();
}
- public Byte toNativeValue(Object value)
+ public Character toNativeValue(Object value)
{
- if (value instanceof Byte)
+ if (value instanceof Character)
{
- return (Byte) value;
+ return (Character) value;
}
- else if ((value instanceof String) || (value == null))
+ else if (value == null)
{
- return Byte.valueOf((String)value);
+ throw new NullPointerException("Cannot convert null into char");
}
else
{
throw new NumberFormatException("Cannot convert: " + value + "(" +
- value.getClass().getName() + ") to byte.");
+ value.getClass().getName() + ") to char.");
}
}
public void writeValueImpl(Object value, ByteBuffer buffer)
{
- EncodingUtils.writeByte(buffer, (Byte) value);
+ EncodingUtils.writeChar(buffer, (Character) value);
}
public Object readValueFromBuffer(ByteBuffer buffer)
{
- return EncodingUtils.readByte(buffer);
+ return EncodingUtils.readChar(buffer);
}
+
},
- ASCII_CHARACTER('k')
+ BYTE('b')
{
public int getEncodingSize(Object value)
{
- return EncodingUtils.encodedCharLength();
+ return EncodingUtils.encodedByteLength();
}
- public Character toNativeValue(Object value)
+ public Byte toNativeValue(Object value)
{
- if (value instanceof Character)
+ if (value instanceof Byte)
{
- return (Character) value;
+ return (Byte) value;
}
- else if (value == null)
+ else if ((value instanceof String) || (value == null))
{
- throw new NullPointerException("Cannot convert null into char");
+ return Byte.valueOf((String)value);
}
else
{
throw new NumberFormatException("Cannot convert: " + value + "(" +
- value.getClass().getName() + ") to char.");
+ value.getClass().getName() + ") to byte.");
}
}
public void writeValueImpl(Object value, ByteBuffer buffer)
{
- EncodingUtils.writeChar(buffer, (Character) value);
+ EncodingUtils.writeByte(buffer, (Byte) value);
}
public Object readValueFromBuffer(ByteBuffer buffer)
{
- return EncodingUtils.readChar(buffer);
+ return EncodingUtils.readByte(buffer);
}
-
},
SHORT('s')