You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kw...@apache.org on 2017/05/05 06:12:42 UTC
qpid-broker-j git commit: QPID-7769: [AMQP 0-8..0-91] Support
decoding of type codes u (unsigned short) and B (unsigned byte) to maximise
compatibility with other older AMQP implementations
Repository: qpid-broker-j
Updated Branches:
refs/heads/master 7f9cc7573 -> 75be65b7b
QPID-7769: [AMQP 0-8..0-91] Support decoding of type codes u (unsigned short) and B (unsigned byte) to maximise compatibility with other older AMQP implementations
Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/75be65b7
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/75be65b7
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/75be65b7
Branch: refs/heads/master
Commit: 75be65b7b1d3949ced92b84d3ae3014c82fb06e3
Parents: 7f9cc75
Author: Keith Wall <ke...@gmail.com>
Authored: Thu May 4 21:51:55 2017 +0100
Committer: Keith Wall <ke...@gmail.com>
Committed: Fri May 5 07:10:39 2017 +0100
----------------------------------------------------------------------
.../qpid/server/protocol/v0_8/AMQType.java | 94 ++++++++++++++++++++
.../qpid/server/protocol/v0_8/AMQTypeTest.java | 52 +++++++++++
2 files changed, 146 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/75be65b7/broker-core/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQType.java
----------------------------------------------------------------------
diff --git a/broker-core/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQType.java b/broker-core/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQType.java
index 5d33cc0..463aab9 100644
--- a/broker-core/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQType.java
+++ b/broker-core/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQType.java
@@ -550,6 +550,53 @@ public enum AMQType
}
},
+ UNSIGNED_BYTE('B')
+ {
+ @Override
+ public int getEncodingSize(Object value)
+ {
+ return EncodingUtils.encodedByteLength();
+ }
+
+ @Override
+ public Short toNativeValue(Object value)
+ {
+ if (value == null)
+ {
+ throw new NullPointerException("Cannot convert null into unsigned byte");
+ }
+ else if (value instanceof Short)
+ {
+ return (Short) value;
+ }
+ else if (value instanceof Number)
+ {
+ return ((Number) value).shortValue();
+ }
+ else if (value instanceof String)
+ {
+ return Short.valueOf((String) value);
+ }
+ else
+ {
+ throw new NumberFormatException("Cannot convert: " + value + "(" + value.getClass().getName()
+ + ") to unsigned byte.");
+ }
+ }
+
+ @Override
+ public void writeValueImpl(Object value, QpidByteBuffer buffer)
+ {
+ buffer.putUnsignedByte((Short) value);
+ }
+
+ @Override
+ public Object readValueFromBuffer(QpidByteBuffer buffer)
+ {
+ return buffer.getUnsignedByte();
+ }
+ },
+
SHORT('s')
{
public int getEncodingSize(Object value)
@@ -589,6 +636,53 @@ public enum AMQType
}
},
+ UNSIGNED_SHORT('u')
+ {
+ @Override
+ public int getEncodingSize(Object value)
+ {
+ return EncodingUtils.encodedShortLength();
+ }
+
+ @Override
+ public Integer toNativeValue(Object value)
+ {
+ if (value == null)
+ {
+ throw new NullPointerException("Cannot convert null into unsigned short");
+ }
+ else if (value instanceof Integer)
+ {
+ return (Integer) value;
+ }
+ else if (value instanceof Number)
+ {
+ return ((Number) value).intValue();
+ }
+ else if (value instanceof String)
+ {
+ return Integer.valueOf((String) value);
+ }
+ else
+ {
+ throw new NumberFormatException("Cannot convert: " + value + "(" + value.getClass().getName()
+ + ") to unsigned short.");
+ }
+ }
+
+ @Override
+ public void writeValueImpl(Object value, QpidByteBuffer buffer)
+ {
+ buffer.putUnsignedShort((Integer) value);
+ }
+
+ @Override
+ public Object readValueFromBuffer(QpidByteBuffer buffer)
+ {
+ return buffer.getUnsignedShort();
+ }
+ },
+
INT('I')
{
public int getEncodingSize(Object value)
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/75be65b7/broker-core/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQTypeTest.java
----------------------------------------------------------------------
diff --git a/broker-core/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQTypeTest.java b/broker-core/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQTypeTest.java
new file mode 100644
index 0000000..9433db2
--- /dev/null
+++ b/broker-core/src/test/java/org/apache/qpid/server/protocol/v0_8/AMQTypeTest.java
@@ -0,0 +1,52 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.protocol.v0_8;
+
+import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class AMQTypeTest extends QpidTestCase
+{
+ private static final int SIZE = 1024;
+
+ public void testUnsignedShort()
+ {
+ doTest(AMQType.UNSIGNED_SHORT, 0);
+ doTest(AMQType.UNSIGNED_SHORT, 65535);
+ }
+
+ public void testUnsignedByte()
+ {
+ doTest(AMQType.UNSIGNED_BYTE, (short)0);
+ doTest(AMQType.UNSIGNED_BYTE, (short)255);
+ }
+
+ private <T> void doTest(final AMQType type, final T value)
+ {
+ final QpidByteBuffer buf = QpidByteBuffer.allocate(false, SIZE);
+ AMQTypedValue.createAMQTypedValue(type, value).writeToBuffer(buf);
+ buf.flip();
+
+ T read = (T) AMQTypedValue.readFromBuffer(buf).getValue();
+ assertEquals("Unexpected round trip value", value, read);
+ buf.dispose();
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org