You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2014/11/14 16:47:56 UTC

qpid-proton git commit: PROTON-745: update DataImpl to return arrays of Symbol as Symbol[] instance rather than Object[] instance, and enable Data#putObject() to accept the Symbol[].

Repository: qpid-proton
Updated Branches:
  refs/heads/master c5c1879fd -> a04193d2c


PROTON-745: update DataImpl to return arrays of Symbol as Symbol[] instance rather than Object[] instance, and enable Data#putObject() to accept the Symbol[].


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/a04193d2
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/a04193d2
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/a04193d2

Branch: refs/heads/master
Commit: a04193d2c745bbf045fcc191a5d5de8fbdba9812
Parents: c5c1879
Author: Robert Gemmell <ro...@apache.org>
Authored: Fri Nov 14 15:46:44 2014 +0000
Committer: Robert Gemmell <ro...@apache.org>
Committed: Fri Nov 14 15:46:44 2014 +0000

----------------------------------------------------------------------
 .../qpid/proton/codec/impl/ArrayElement.java    | 13 +++
 .../apache/qpid/proton/codec/impl/DataImpl.java | 10 +++
 .../qpid/proton/codec/impl/DataImplTest.java    | 84 ++++++++++++++++++++
 3 files changed, 107 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a04193d2/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/ArrayElement.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/ArrayElement.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/ArrayElement.java
index 2ac9668..22251fe 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/ArrayElement.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/ArrayElement.java
@@ -24,6 +24,7 @@ package org.apache.qpid.proton.codec.impl;
 import java.nio.ByteBuffer;
 
 import org.apache.qpid.proton.amqp.DescribedType;
+import org.apache.qpid.proton.amqp.Symbol;
 import org.apache.qpid.proton.codec.Data;
 
 class ArrayElement extends AbstractElement<Object[]>
@@ -160,6 +161,18 @@ class ArrayElement extends AbstractElement<Object[]>
             }
             return rVal;
         }
+        else if(_arrayType == Data.DataType.SYMBOL)
+        {
+            Symbol[] rVal = new Symbol[(int) count()];
+            SymbolElement element = (SymbolElement) _first;
+            int i = 0;
+            while (element!=null)
+            {
+                rVal[i++] = element.getValue();
+                element = (SymbolElement) element.next();
+            }
+            return rVal;
+        }
         else
         {
             Object[] rVal = new Object[(int) count()];

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a04193d2/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/DataImpl.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/DataImpl.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/DataImpl.java
index b22ae30..c6520ed 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/DataImpl.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/DataImpl.java
@@ -458,6 +458,16 @@ public class DataImpl implements Data
         {
             putDescribedType((DescribedType)o);
         }
+        else if(o instanceof Symbol[])
+        {
+            putArray(false, Data.DataType.SYMBOL);
+            enter();
+            for(Symbol s : (Symbol[]) o)
+            {
+                putSymbol(s);
+            }
+            exit();
+        }
         else if(o instanceof Object[])
         {
             putJavaArray((Object[]) o);

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a04193d2/proton-j/src/test/java/org/apache/qpid/proton/codec/impl/DataImplTest.java
----------------------------------------------------------------------
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/codec/impl/DataImplTest.java b/proton-j/src/test/java/org/apache/qpid/proton/codec/impl/DataImplTest.java
new file mode 100644
index 0000000..6bb3f2c
--- /dev/null
+++ b/proton-j/src/test/java/org/apache/qpid/proton/codec/impl/DataImplTest.java
@@ -0,0 +1,84 @@
+/*
+ *
+ * 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.proton.codec.impl;
+
+import static org.junit.Assert.*;
+
+import org.apache.qpid.proton.amqp.Binary;
+import org.apache.qpid.proton.amqp.Symbol;
+import org.apache.qpid.proton.codec.Data;
+import org.junit.Test;
+
+public class DataImplTest
+{
+    @Test
+    public void testEncodeDecodeSymbolArrayUsingPutArray()
+    {
+        Symbol symbol1 = Symbol.valueOf("testRoundtripSymbolArray1");
+        Symbol symbol2 = Symbol.valueOf("testRoundtripSymbolArray2");
+
+        Data data1 = new DataImpl();
+        data1.putArray(false, Data.DataType.SYMBOL);
+        data1.enter();
+        data1.putSymbol(symbol1);
+        data1.putSymbol(symbol2);
+        data1.exit();
+
+        Binary encoded = data1.encode();
+        encoded.asByteBuffer();
+
+        Data data2 = new DataImpl();
+        data2.decode(encoded.asByteBuffer());
+
+        assertEquals("unexpected array length", 2, data2.getArray());
+        assertEquals("unexpected array length", Data.DataType.SYMBOL, data2.getArrayType());
+
+        Object[] array = data2.getJavaArray();
+        assertNotNull("Array should not be null", array);
+        assertEquals("Expected a Symbol array", Symbol[].class, array.getClass());
+        assertEquals("unexpected array length", 2, array.length);
+        assertEquals("unexpected value", symbol1, array[0]);
+        assertEquals("unexpected value", symbol2, array[1]);
+    }
+
+    @Test
+    public void testEncodeDecodeSymbolArrayUsingPutObject()
+    {
+        Symbol symbol1 = Symbol.valueOf("testRoundtripSymbolArray1");
+        Symbol symbol2 = Symbol.valueOf("testRoundtripSymbolArray2");
+        Symbol[] input = new Symbol[]{symbol1, symbol2};
+
+        Data data1 = new DataImpl();
+        data1.putObject(input);
+
+        Binary encoded = data1.encode();
+        encoded.asByteBuffer();
+
+        Data data2 = new DataImpl();
+        data2.decode(encoded.asByteBuffer());
+
+        assertEquals("unexpected array length", 2, data2.getArray());
+        assertEquals("unexpected array length", Data.DataType.SYMBOL, data2.getArrayType());
+
+        Object[] array = data2.getJavaArray();
+        assertArrayEquals("Array not as expected", input, array);
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org