You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rg...@apache.org on 2013/06/18 10:23:58 UTC
svn commit: r1494067 [1/2] - in /qpid/proton/trunk:
proton-c/bindings/java/src/main/java/org/apache/qpid/proton/codec/jni/
proton-j/proton-api/src/main/resources/
proton-j/proton/src/main/java/org/apache/qpid/proton/codec/
proton-j/proton/src/main/java...
Author: rgodfrey
Date: Tue Jun 18 08:23:57 2013
New Revision: 1494067
URL: http://svn.apache.org/r1494067
Log:
PROTON-339 : [Proton-J] Implement pure java version of the Data interface
Added:
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/AbstractElement.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/ArrayElement.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/AtomicElement.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/BinaryElement.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/BooleanElement.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/ByteElement.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/CharElement.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/DataDecoder.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/DataImpl.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/Decimal128Element.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/Decimal32Element.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/Decimal64Element.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/DescribedTypeElement.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/DescribedTypeImpl.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/DoubleElement.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/Element.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/FloatElement.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/IntegerElement.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/ListElement.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/LongElement.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/MapElement.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/NullElement.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/ShortElement.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/StringElement.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/SymbolElement.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/TimestampElement.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/UUIDElement.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/UnsignedByteElement.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/UnsignedIntegerElement.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/UnsignedLongElement.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/UnsignedShortElement.java
qpid/proton/trunk/tests/java/pythonTests.ignore
Removed:
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/Data.java
Modified:
qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/codec/jni/JNIData.java
qpid/proton/trunk/proton-j/proton-api/src/main/resources/proton.py
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/DataFactoryImpl.java
qpid/proton/trunk/tests/java/org/apache/qpid/proton/JythonTest.java
qpid/proton/trunk/tests/pom.xml
qpid/proton/trunk/tests/python/proton_tests/interop.py
Modified: qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/codec/jni/JNIData.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/codec/jni/JNIData.java?rev=1494067&r1=1494066&r2=1494067&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/codec/jni/JNIData.java (original)
+++ qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/codec/jni/JNIData.java Tue Jun 18 08:23:57 2013
@@ -267,6 +267,7 @@ public class JNIData implements Data
{
buf = ByteBuffer.allocate(size);
rval = encode(buf);
+ size = size * 2;
}
return new Binary(buf.array(), buf.arrayOffset(), buf.arrayOffset()+(int)rval);
}
@@ -1123,5 +1124,48 @@ public class JNIData implements Data
{
return _described;
}
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || ! (o instanceof DescribedType))
+ {
+ return false;
+ }
+
+ DescribedType that = (DescribedType) o;
+
+ if (_described != null ? !_described.equals(that.getDescribed()) : that.getDescribed() != null)
+ {
+ return false;
+ }
+ if (_descriptor != null ? !_descriptor.equals(that.getDescriptor()) : that.getDescriptor() != null)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = _descriptor != null ? _descriptor.hashCode() : 0;
+ result = 31 * result + (_described != null ? _described.hashCode() : 0);
+ return result;
+ }
+
+
+ @Override
+ public String toString()
+ {
+ return "{" + _descriptor +
+ ": " + _described +
+ '}';
+ }
}
}
Modified: qpid/proton/trunk/proton-j/proton-api/src/main/resources/proton.py
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/proton-api/src/main/resources/proton.py?rev=1494067&r1=1494066&r2=1494067&view=diff
==============================================================================
--- qpid/proton/trunk/proton-j/proton-api/src/main/resources/proton.py (original)
+++ qpid/proton/trunk/proton-j/proton-api/src/main/resources/proton.py Tue Jun 18 08:23:57 2013
@@ -1128,7 +1128,7 @@ class Data(object):
unicode: put_string,
bytes: put_binary,
symbol: put_symbol,
- int: put_long,
+ int: put_int,
char: put_char,
long: put_long,
ulong: put_ulong,
Added: qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/AbstractElement.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/AbstractElement.java?rev=1494067&view=auto
==============================================================================
--- qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/AbstractElement.java (added)
+++ qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/AbstractElement.java Tue Jun 18 08:23:57 2013
@@ -0,0 +1,67 @@
+/*
+ *
+ * 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;
+
+abstract class AbstractElement<T> implements Element<T>
+{
+ private Element _parent;
+ private Element _next;
+ private Element _prev;
+
+ AbstractElement(Element parent, Element prev)
+ {
+ _parent = parent;
+ _prev = prev;
+ }
+
+ protected boolean isElementOfArray()
+ {
+ return _parent instanceof ArrayElement && !(((ArrayElement)parent()).isDescribed() && this == _parent.child());
+ }
+
+ @Override
+ public Element next()
+ {
+ // TODO
+ return _next;
+ }
+
+ @Override
+ public Element prev()
+ {
+ // TODO
+ return _prev;
+ }
+
+ @Override
+ public Element parent()
+ {
+ // TODO
+ return _parent;
+ }
+
+ @Override
+ public void setNext(Element elt)
+ {
+ _next = elt;
+ }
+}
Added: qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/ArrayElement.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/ArrayElement.java?rev=1494067&view=auto
==============================================================================
--- qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/ArrayElement.java (added)
+++ qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/ArrayElement.java Tue Jun 18 08:23:57 2013
@@ -0,0 +1,462 @@
+/*
+ *
+ * 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 java.nio.ByteBuffer;
+
+import org.apache.qpid.proton.amqp.DescribedType;
+import org.apache.qpid.proton.codec.Data;
+
+class ArrayElement extends AbstractElement<Object[]>
+{
+
+ private final boolean _described;
+ private final Data.DataType _arrayType;
+ private ConstructorType _constructorType;
+ private Element _first;
+
+
+ static enum ConstructorType { TINY, SMALL, LARGE }
+
+
+ static ConstructorType TINY = ConstructorType.TINY;
+ static ConstructorType SMALL = ConstructorType.SMALL;
+ static ConstructorType LARGE = ConstructorType.LARGE;
+
+ ArrayElement(Element parent, Element prev, boolean described, Data.DataType type)
+ {
+ super(parent, prev);
+ _described = described;
+ _arrayType = type;
+ if(_arrayType == null)
+ {
+ throw new NullPointerException("Array type cannot be null");
+ }
+ else if(_arrayType == Data.DataType.DESCRIBED)
+ {
+ throw new IllegalArgumentException("Array type cannot be DESCRIBED");
+ }
+ switch(_arrayType)
+ {
+ case UINT:
+ case ULONG:
+ case LIST:
+ setConstructorType(TINY);
+ break;
+ default:
+ setConstructorType(SMALL);
+ }
+ }
+
+ ConstructorType constructorType()
+ {
+ return _constructorType;
+ }
+
+ void setConstructorType(ConstructorType type)
+ {
+ _constructorType = type;
+ }
+
+ @Override
+ public int size()
+ {
+ ConstructorType oldConstructorType;
+ int bodySize;
+ int count = 0;
+ do
+ {
+ bodySize = 1; // data type constructor
+ oldConstructorType = _constructorType;
+ Element element = _first;
+ while(element != null)
+ {
+ count++;
+ bodySize += element.size();
+ element = element.next();
+ }
+ }
+ while (oldConstructorType != constructorType());
+
+ if(isDescribed())
+ {
+ bodySize++; // 00 instruction
+ if(count != 0)
+ {
+ count--;
+ }
+ }
+
+ if(isElementOfArray())
+ {
+ ArrayElement parent = (ArrayElement)parent();
+ if(parent.constructorType()==SMALL)
+ {
+ if(count<=255 && bodySize<=254)
+ {
+ bodySize+=2;
+ }
+ else
+ {
+ parent.setConstructorType(LARGE);
+ bodySize+=8;
+ }
+ }
+ else
+ {
+ bodySize+=8;
+ }
+ }
+ else
+ {
+
+ if(count<=255 && bodySize<=254)
+ {
+ bodySize+=3;
+ }
+ else
+ {
+ bodySize+=9;
+ }
+
+ }
+
+
+ return bodySize;
+ }
+
+ @Override
+ public Object[] getValue()
+ {
+ if(isDescribed())
+ {
+ DescribedType[] rVal = new DescribedType[(int) count()];
+ Object descriptor = _first == null ? null : _first.getValue();
+ Element element = _first == null ? null : _first.next();
+ int i = 0;
+ while(element != null)
+ {
+ rVal[i++] = new DescribedTypeImpl(descriptor, element.getValue());
+ element = element.next();
+ }
+ return rVal;
+ }
+ else
+ {
+ Object[] rVal = new Object[(int) count()];
+ Element element = _first;
+ int i = 0;
+ while (element!=null)
+ {
+ rVal[i++] = element.getValue();
+ element = element.next();
+ }
+ return rVal;
+ }
+ }
+
+ @Override
+ public Data.DataType getDataType()
+ {
+ return Data.DataType.ARRAY;
+ }
+
+ @Override
+ public int encode(ByteBuffer b)
+ {
+ int size = size();
+
+ final int count = (int) count();
+
+ if(b.remaining()>=size)
+ {
+ if(!isElementOfArray())
+ {
+ if(size>257 || count >255)
+ {
+ b.put((byte)0xf0);
+ b.putInt(size-5);
+ b.putInt(count);
+ }
+ else
+ {
+ b.put((byte)0xe0);
+ b.put((byte)(size-2));
+ b.put((byte)count);
+ }
+ }
+ else
+ {
+ ArrayElement parent = (ArrayElement)parent();
+ if(parent.constructorType()==SMALL)
+ {
+ b.put((byte)(size-1));
+ b.put((byte)count);
+ }
+ else
+ {
+ b.putInt(size-4);
+ b.putInt(count);
+ }
+ }
+ Element element = _first;
+ if(isDescribed())
+ {
+ b.put((byte)0);
+ if(element == null)
+ {
+ b.put((byte)0x40);
+ }
+ else
+ {
+ element.encode(b);
+ element = element.next();
+ }
+ }
+ switch(_arrayType)
+ {
+ case NULL:
+ b.put((byte)0x40);
+ break;
+ case BOOL:
+ b.put((byte)0x56);
+ break;
+ case UBYTE:
+ b.put((byte)0x50);
+ break;
+ case BYTE:
+ b.put((byte)0x51);
+ break;
+ case USHORT:
+ b.put((byte)0x60);
+ break;
+ case SHORT:
+ b.put((byte)0x61);
+ break;
+ case UINT:
+ switch (constructorType())
+ {
+ case TINY:
+ b.put((byte)0x43);
+ break;
+ case SMALL:
+ b.put((byte)0x52);
+ break;
+ case LARGE:
+ b.put((byte)0x70);
+ break;
+ }
+ break;
+ case INT:
+ b.put(_constructorType == SMALL ? (byte)0x54 : (byte)0x71);
+ break;
+ case CHAR:
+ b.put((byte)0x73);
+ break;
+ case ULONG:
+ switch (constructorType())
+ {
+ case TINY:
+ b.put((byte)0x44);
+ break;
+ case SMALL:
+ b.put((byte)0x53);
+ break;
+ case LARGE:
+ b.put((byte)0x80);
+ break;
+ }
+ break;
+ case LONG:
+ b.put(_constructorType == SMALL ? (byte)0x55 : (byte)0x81);
+ break;
+ case TIMESTAMP:
+ b.put((byte)0x83);
+ break;
+ case FLOAT:
+ b.put((byte)0x72);
+ break;
+ case DOUBLE:
+ b.put((byte)0x82);
+ break;
+ case DECIMAL32:
+ b.put((byte)0x74);
+ break;
+ case DECIMAL64:
+ b.put((byte)0x84);
+ break;
+ case DECIMAL128:
+ b.put((byte)0x94);
+ break;
+ case UUID:
+ b.put((byte)0x98);
+ break;
+ case BINARY:
+ b.put(_constructorType == SMALL ? (byte)0xa0 : (byte)0xb0);
+ break;
+ case STRING:
+ b.put(_constructorType == SMALL ? (byte)0xa1 : (byte)0xb1);
+ break;
+ case SYMBOL:
+ b.put(_constructorType == SMALL ? (byte)0xa3 : (byte)0xb3);
+ break;
+ case ARRAY:
+ b.put(_constructorType == SMALL ? (byte)0xe0 : (byte)0xf0);
+ break;
+ case LIST:
+ b.put(_constructorType == TINY ? (byte)0x45 :_constructorType == SMALL ? (byte)0xc0 : (byte)0xd0);
+ break;
+ case MAP:
+ b.put(_constructorType == SMALL ? (byte)0xc1 : (byte)0xd1);
+ break;
+ }
+ while(element!=null)
+ {
+ element.encode(b);
+ element = element.next();
+ }
+ return size;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+
+ @Override
+ public boolean canEnter()
+ {
+ return true;
+ }
+
+ @Override
+ public Element child()
+ {
+ return _first;
+ }
+
+ @Override
+ public Element addChild(Element element)
+ {
+ if(isDescribed() || element.getDataType() == _arrayType)
+ {
+ _first = element;
+ return element;
+ }
+ else
+ {
+ Element replacement = coerce(element);
+ if(replacement != null)
+ {
+ return replacement;
+ }
+ throw new IllegalArgumentException("Attempting to add instance of " + element.getDataType() + " to array of " + _arrayType);
+ }
+ }
+
+ private Element coerce(Element element)
+ {
+ /*switch (_arrayType)
+ {
+ case INT:
+
+ int i;
+ switch (element.getDataType())
+ {
+ case BYTE:
+ i = ((ByteElement)element).getValue().intValue();
+ break;
+ case SHORT:
+ i = ((ShortElement)element).getValue().intValue();
+ break;
+ case LONG:
+ i = ((LongElement)element).getValue().intValue();
+ break;
+ default:
+ return null;
+ }
+ return new IntegerElement(element.parent(),element.prev(),i);
+
+ case LONG:
+ long l;
+ switch (element.getDataType())
+ {
+ case BYTE:
+ l = ((ByteElement)element).getValue().longValue();
+ break;
+ case SHORT:
+ l = ((ShortElement)element).getValue().longValue();
+ break;
+ case INT:
+ l = ((IntegerElement)element).getValue().longValue();
+ break;
+ default:
+ return null;
+ }
+ return new LongElement(element.parent(),element.prev(),l);
+ }*/
+ return null;
+ }
+
+ @Override
+ public Element checkChild(Element element)
+ {
+ if(element.getDataType() != _arrayType)
+ {
+ Element replacement = coerce(element);
+ if(replacement != null)
+ {
+ return replacement;
+ }
+ throw new IllegalArgumentException("Attempting to add instance of " + element.getDataType() + " to array of " + _arrayType);
+ }
+ return element;
+ }
+
+
+ public long count()
+ {
+ int count = 0;
+ Element elt = _first;
+ while(elt != null)
+ {
+ count++;
+ elt = elt.next();
+ }
+ if(isDescribed() && count != 0)
+ {
+ count--;
+ }
+ return count;
+ }
+
+ public boolean isDescribed()
+ {
+ return _described;
+ }
+
+
+ public Data.DataType getArrayDataType()
+ {
+ return _arrayType;
+ }
+}
Added: qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/AtomicElement.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/AtomicElement.java?rev=1494067&view=auto
==============================================================================
--- qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/AtomicElement.java (added)
+++ qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/AtomicElement.java Tue Jun 18 08:23:57 2013
@@ -0,0 +1,57 @@
+/*
+ *
+ * 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;
+
+abstract class AtomicElement<T> extends AbstractElement<T>
+{
+
+ AtomicElement(Element parent, Element prev)
+ {
+ super(parent, prev);
+ }
+
+ @Override
+ public Element child()
+ {
+ // TODO
+ throw new UnsupportedOperationException();
+ }
+
+
+ @Override
+ public boolean canEnter()
+ {
+ return false;
+ }
+
+ @Override
+ public Element checkChild(Element element)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Element addChild(Element element)
+ {
+ throw new UnsupportedOperationException();
+ }
+}
Added: qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/BinaryElement.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/BinaryElement.java?rev=1494067&view=auto
==============================================================================
--- qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/BinaryElement.java (added)
+++ qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/BinaryElement.java Tue Jun 18 08:23:57 2013
@@ -0,0 +1,128 @@
+/*
+ *
+ * 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 java.nio.ByteBuffer;
+
+import org.apache.qpid.proton.amqp.Binary;
+import org.apache.qpid.proton.codec.Data;
+
+class BinaryElement extends AtomicElement<Binary>
+{
+
+ private final Binary _value;
+
+ BinaryElement(Element parent, Element prev, Binary b)
+ {
+ super(parent, prev);
+ byte[] data = new byte[b.getLength()];
+ System.arraycopy(b.getArray(),b.getArrayOffset(),data,0,b.getLength());
+ _value = new Binary(data);
+ }
+
+ @Override
+ public int size()
+ {
+ final int length = _value.getLength();
+
+ if(isElementOfArray())
+ {
+ final ArrayElement parent = (ArrayElement) parent();
+
+ if(parent.constructorType() == ArrayElement.SMALL)
+ {
+ if(length > 255)
+ {
+ parent.setConstructorType(ArrayElement.LARGE);
+ return 4+length;
+ }
+ else
+ {
+ return 1+length;
+ }
+ }
+ else
+ {
+ return 4+length;
+ }
+ }
+ else
+ {
+ if(length >255)
+ {
+ return 5 + length;
+ }
+ else
+ {
+ return 2 + length;
+ }
+ }
+ }
+
+ @Override
+ public Binary getValue()
+ {
+ return _value;
+ }
+
+ @Override
+ public Data.DataType getDataType()
+ {
+ return Data.DataType.BINARY;
+ }
+
+ @Override
+ public int encode(ByteBuffer b)
+ {
+ int size = size();
+ if(b.remaining()<size)
+ {
+ return 0;
+ }
+ if(isElementOfArray())
+ {
+ final ArrayElement parent = (ArrayElement) parent();
+
+ if(parent.constructorType() == ArrayElement.SMALL)
+ {
+ b.put((byte)_value.getLength());
+ }
+ else
+ {
+ b.putInt(_value.getLength());
+ }
+ }
+ else if(_value.getLength()<=255)
+ {
+ b.put((byte)0xa0);
+ b.put((byte)_value.getLength());
+ }
+ else
+ {
+ b.put((byte)0xb0);
+ b.put((byte)_value.getLength());
+ }
+ b.put(_value.getArray(),_value.getArrayOffset(),_value.getLength());
+ return size;
+
+ }
+}
Added: qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/BooleanElement.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/BooleanElement.java?rev=1494067&view=auto
==============================================================================
--- qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/BooleanElement.java (added)
+++ qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/BooleanElement.java Tue Jun 18 08:23:57 2013
@@ -0,0 +1,76 @@
+/*
+ *
+ * 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 java.nio.ByteBuffer;
+
+import org.apache.qpid.proton.codec.Data;
+
+class BooleanElement extends AtomicElement<Boolean>
+{
+ private final boolean _value;
+
+ public BooleanElement(Element parent, Element current, boolean b)
+ {
+ super(parent, current);
+ _value = b;
+ }
+
+ @Override
+ public int size()
+ {
+ // in non-array parent then there is a single byte encoding, in an array there is a 1-byte encoding but no
+ // constructor
+ return 1;
+ }
+
+ @Override
+ public Boolean getValue()
+ {
+ return _value;
+ }
+
+ @Override
+ public Data.DataType getDataType()
+ {
+ return Data.DataType.BOOL;
+ }
+
+ @Override
+ public int encode(ByteBuffer b)
+ {
+ if(b.hasRemaining())
+ {
+ if(isElementOfArray())
+ {
+ b.put(_value ? (byte) 1 : (byte) 0);
+ }
+ else
+ {
+ b.put(_value ? (byte) 0x41 : (byte) 0x42);
+ }
+ return 1;
+ }
+ return 0;
+ }
+
+}
Added: qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/ByteElement.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/ByteElement.java?rev=1494067&view=auto
==============================================================================
--- qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/ByteElement.java (added)
+++ qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/ByteElement.java Tue Jun 18 08:23:57 2013
@@ -0,0 +1,79 @@
+/*
+ *
+ * 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 java.nio.ByteBuffer;
+
+import org.apache.qpid.proton.codec.Data;
+
+class ByteElement extends AtomicElement<Byte>
+{
+
+ private final byte _value;
+
+ ByteElement(Element parent, Element prev, byte b)
+ {
+ super(parent, prev);
+ _value = b;
+ }
+
+ @Override
+ public int size()
+ {
+ return isElementOfArray() ? 1 : 2;
+ }
+
+ @Override
+ public Byte getValue()
+ {
+ return _value;
+ }
+
+ @Override
+ public Data.DataType getDataType()
+ {
+ return Data.DataType.BYTE;
+ }
+
+ @Override
+ public int encode(ByteBuffer b)
+ {
+ if(isElementOfArray())
+ {
+ if(b.hasRemaining())
+ {
+ b.put(_value);
+ return 1;
+ }
+ }
+ else
+ {
+ if(b.remaining()>=2)
+ {
+ b.put((byte)0x51);
+ b.put(_value);
+ return 2;
+ }
+ }
+ return 0;
+ }
+}
Added: qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/CharElement.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/CharElement.java?rev=1494067&view=auto
==============================================================================
--- qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/CharElement.java (added)
+++ qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/CharElement.java Tue Jun 18 08:23:57 2013
@@ -0,0 +1,71 @@
+/*
+ *
+ * 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 java.nio.ByteBuffer;
+
+import org.apache.qpid.proton.codec.Data;
+
+class CharElement extends AtomicElement<Integer>
+{
+
+ private final int _value;
+
+ CharElement(Element parent, Element prev, int i)
+ {
+ super(parent, prev);
+ _value = i;
+ }
+
+ @Override
+ public int size()
+ {
+ return isElementOfArray() ? 4 : 5;
+ }
+
+ @Override
+ public Integer getValue()
+ {
+ return _value;
+ }
+
+ @Override
+ public Data.DataType getDataType()
+ {
+ return Data.DataType.CHAR;
+ }
+
+ @Override
+ public int encode(ByteBuffer b)
+ {
+ final int size = size();
+ if(size <= b.remaining())
+ {
+ if(size == 5)
+ {
+ b.put((byte)0x73);
+ }
+ b.putInt(_value);
+ }
+ return 0;
+ }
+}
Added: qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/DataDecoder.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/DataDecoder.java?rev=1494067&view=auto
==============================================================================
--- qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/DataDecoder.java (added)
+++ qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/DataDecoder.java Tue Jun 18 08:23:57 2013
@@ -0,0 +1,1074 @@
+/*
+ *
+ * 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 java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+import java.util.Date;
+import java.util.UUID;
+
+import org.apache.qpid.proton.amqp.*;
+import org.apache.qpid.proton.codec.Data;
+
+class DataDecoder
+{
+
+ private static final Charset ASCII = Charset.forName("US-ASCII");
+ private static final Charset UTF_8 = Charset.forName("UTF-8");
+
+ private static final TypeConstructor[] _constructors = new TypeConstructor[256];
+
+ static
+ {
+
+ _constructors[0x00] = new DescribedTypeConstructor();
+
+ _constructors[0x40] = new NullConstructor();
+ _constructors[0x41] = new TrueConstructor();
+ _constructors[0x42] = new FalseConstructor();
+ _constructors[0x43] = new UInt0Constructor();
+ _constructors[0x44] = new ULong0Constructor();
+ _constructors[0x45] = new EmptyListConstructor();
+
+ _constructors[0x50] = new UByteConstructor();
+ _constructors[0x51] = new ByteConstructor();
+ _constructors[0x52] = new SmallUIntConstructor();
+ _constructors[0x53] = new SmallULongConstructor();
+ _constructors[0x54] = new SmallIntConstructor();
+ _constructors[0x55] = new SmallLongConstructor();
+ _constructors[0x56] = new BooleanConstructor();
+
+ _constructors[0x60] = new UShortConstructor();
+ _constructors[0x61] = new ShortConstructor();
+
+ _constructors[0x70] = new UIntConstructor();
+ _constructors[0x71] = new IntConstructor();
+ _constructors[0x72] = new FloatConstructor();
+ _constructors[0x73] = new CharConstructor();
+ _constructors[0x74] = new Decimal32Constructor();
+
+ _constructors[0x80] = new ULongConstructor();
+ _constructors[0x81] = new LongConstructor();
+ _constructors[0x82] = new DoubleConstructor();
+ _constructors[0x83] = new TimestampConstructor();
+ _constructors[0x84] = new Decimal64Constructor();
+
+ _constructors[0x94] = new Decimal128Constructor();
+ _constructors[0x98] = new UUIDConstructor();
+
+ _constructors[0xa0] = new SmallBinaryConstructor();
+ _constructors[0xa1] = new SmallStringConstructor();
+ _constructors[0xa3] = new SmallSymbolConstructor();
+
+ _constructors[0xb0] = new BinaryConstructor();
+ _constructors[0xb1] = new StringConstructor();
+ _constructors[0xb3] = new SymbolConstructor();
+
+ _constructors[0xc0] = new SmallListConstructor();
+ _constructors[0xc1] = new SmallMapConstructor();
+
+
+ _constructors[0xd0] = new ListConstructor();
+ _constructors[0xd1] = new MapConstructor();
+
+ _constructors[0xe0] = new SmallArrayConstructor();
+ _constructors[0xf0] = new ArrayConstructor();
+
+ }
+
+ private interface TypeConstructor
+ {
+ Data.DataType getType();
+
+ int size(ByteBuffer b);
+
+ void parse(ByteBuffer b, Data data);
+ }
+
+
+ static int decode(ByteBuffer b, Data data)
+ {
+ if(b.hasRemaining())
+ {
+ int position = b.position();
+ TypeConstructor c = readConstructor(b);
+ final int size = c.size(b);
+ if(b.remaining() >= size)
+ {
+ c.parse(b, data);
+ return 1+size;
+ }
+ else
+ {
+ b.position(position);
+ return -4;
+ }
+ }
+ return 0;
+ }
+
+ private static TypeConstructor readConstructor(ByteBuffer b)
+ {
+ int index = b.get() & 0xff;
+ TypeConstructor tc = _constructors[index];
+ if(tc == null)
+ {
+ throw new IllegalArgumentException("No constructor for type " + index);
+ }
+ return tc;
+ }
+
+
+ private static class NullConstructor implements TypeConstructor
+ {
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.NULL;
+ }
+
+ @Override
+ public int size(ByteBuffer b)
+ {
+ return 0;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ data.putNull();
+ }
+ }
+
+ private static class TrueConstructor implements TypeConstructor
+ {
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.BOOL;
+ }
+
+ @Override
+ public int size(ByteBuffer b)
+ {
+ return 0;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ data.putBoolean(true);
+ }
+ }
+
+
+ private static class FalseConstructor implements TypeConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.BOOL;
+ }
+
+ @Override
+ public int size(ByteBuffer b)
+ {
+ return 0;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ data.putBoolean(false);
+ }
+ }
+
+ private static class UInt0Constructor implements TypeConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.UINT;
+ }
+
+ @Override
+ public int size(ByteBuffer b)
+ {
+ return 0;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ data.putUnsignedInteger(UnsignedInteger.ZERO);
+ }
+ }
+
+ private static class ULong0Constructor implements TypeConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.ULONG;
+ }
+
+ @Override
+ public int size(ByteBuffer b)
+ {
+ return 0;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ data.putUnsignedLong(UnsignedLong.ZERO);
+ }
+ }
+
+
+ private static class EmptyListConstructor implements TypeConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.LIST;
+ }
+
+ @Override
+ public int size(ByteBuffer b)
+ {
+ return 0;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ data.putList();
+ }
+ }
+
+
+ private static abstract class Fixed0SizeConstructor implements TypeConstructor
+ {
+ @Override
+ public final int size(ByteBuffer b)
+ {
+ return 0;
+ }
+ }
+
+ private static abstract class Fixed1SizeConstructor implements TypeConstructor
+ {
+ @Override
+ public int size(ByteBuffer b)
+ {
+ return 1;
+ }
+ }
+
+ private static abstract class Fixed2SizeConstructor implements TypeConstructor
+ {
+ @Override
+ public int size(ByteBuffer b)
+ {
+ return 2;
+ }
+ }
+
+ private static abstract class Fixed4SizeConstructor implements TypeConstructor
+ {
+ @Override
+ public int size(ByteBuffer b)
+ {
+ return 4;
+ }
+ }
+
+ private static abstract class Fixed8SizeConstructor implements TypeConstructor
+ {
+ @Override
+ public int size(ByteBuffer b)
+ {
+ return 8;
+ }
+ }
+
+ private static abstract class Fixed16SizeConstructor implements TypeConstructor
+ {
+ @Override
+ public int size(ByteBuffer b)
+ {
+ return 16;
+ }
+ }
+
+ private static class UByteConstructor extends Fixed1SizeConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.UBYTE;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ data.putUnsignedByte(UnsignedByte.valueOf(b.get()));
+ }
+ }
+
+ private static class ByteConstructor extends Fixed1SizeConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.BYTE;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ data.putByte(b.get());
+ }
+ }
+
+ private static class SmallUIntConstructor extends Fixed1SizeConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.UINT;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ data.putUnsignedInteger(UnsignedInteger.valueOf(((int) b.get()) & 0xff));
+ }
+ }
+
+ private static class SmallIntConstructor extends Fixed1SizeConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.INT;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ data.putInt(b.get());
+ }
+ }
+
+ private static class SmallULongConstructor extends Fixed1SizeConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.ULONG;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ data.putUnsignedLong(UnsignedLong.valueOf(((int) b.get()) & 0xff));
+ }
+ }
+
+ private static class SmallLongConstructor extends Fixed1SizeConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.LONG;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ data.putLong(b.get());
+ }
+ }
+
+ private static class BooleanConstructor extends Fixed1SizeConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.BOOL;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ int i = b.get();
+ if(i != 0 && i != 1)
+ {
+ throw new IllegalArgumentException("Illegal value " + i + " for boolean");
+ }
+ data.putBoolean(i == 1);
+ }
+ }
+
+ private static class UShortConstructor extends Fixed2SizeConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.USHORT;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ data.putUnsignedShort(UnsignedShort.valueOf(b.getShort()));
+ }
+ }
+
+ private static class ShortConstructor extends Fixed2SizeConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.SHORT;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ data.putShort(b.getShort());
+ }
+ }
+
+ private static class UIntConstructor extends Fixed4SizeConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.UINT;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ data.putUnsignedInteger(UnsignedInteger.valueOf(b.getInt()));
+ }
+ }
+
+ private static class IntConstructor extends Fixed4SizeConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.INT;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ data.putInt(b.getInt());
+ }
+ }
+
+ private static class FloatConstructor extends Fixed4SizeConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.FLOAT;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ data.putFloat(b.getFloat());
+ }
+ }
+
+ private static class CharConstructor extends Fixed4SizeConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.CHAR;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ data.putChar(b.getInt());
+ }
+ }
+
+ private static class Decimal32Constructor extends Fixed4SizeConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.DECIMAL32;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ data.putDecimal32(new Decimal32(b.getInt()));
+ }
+ }
+
+ private static class ULongConstructor extends Fixed8SizeConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.ULONG;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ data.putUnsignedLong(UnsignedLong.valueOf(b.getLong()));
+ }
+ }
+
+ private static class LongConstructor extends Fixed8SizeConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.LONG;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ data.putLong(b.getLong());
+ }
+ }
+
+ private static class DoubleConstructor extends Fixed8SizeConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.DOUBLE;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ data.putDouble(b.getDouble());
+ }
+ }
+
+ private static class TimestampConstructor extends Fixed8SizeConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.TIMESTAMP;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ data.putTimestamp(new Date(b.getLong()));
+ }
+ }
+
+ private static class Decimal64Constructor extends Fixed8SizeConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.DECIMAL64;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ data.putDecimal64(new Decimal64(b.getLong()));
+ }
+ }
+
+ private static class Decimal128Constructor extends Fixed16SizeConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.DECIMAL128;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ data.putDecimal128(new Decimal128(b.getLong(), b.getLong()));
+ }
+ }
+
+ private static class UUIDConstructor extends Fixed16SizeConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.UUID;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ data.putUUID(new UUID(b.getLong(), b.getLong()));
+ }
+ }
+
+ private static abstract class SmallVariableConstructor implements TypeConstructor
+ {
+
+ @Override
+ public int size(ByteBuffer b)
+ {
+ int position = b.position();
+ if(b.hasRemaining())
+ {
+ int size = b.get() & 0xff;
+ b.position(position);
+
+ return size+1;
+ }
+ else
+ {
+ return 1;
+ }
+ }
+
+ }
+
+ private static abstract class VariableConstructor implements TypeConstructor
+ {
+
+ @Override
+ public int size(ByteBuffer b)
+ {
+ int position = b.position();
+ if(b.remaining()>=4)
+ {
+ int size = b.getInt();
+ b.position(position);
+
+ return size+4;
+ }
+ else
+ {
+ return 4;
+ }
+ }
+
+ }
+
+
+ private static class SmallBinaryConstructor extends SmallVariableConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.BINARY;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ int size = b.get() & 0xff;
+ byte[] bytes = new byte[size];
+ b.get(bytes);
+ data.putBinary(bytes);
+ }
+ }
+
+ private static class SmallSymbolConstructor extends SmallVariableConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.SYMBOL;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ int size = b.get() & 0xff;
+ byte[] bytes = new byte[size];
+ b.get(bytes);
+ data.putSymbol(Symbol.valueOf(new String(bytes, ASCII)));
+ }
+ }
+
+
+ private static class SmallStringConstructor extends SmallVariableConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.STRING;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ int size = b.get() & 0xff;
+ byte[] bytes = new byte[size];
+ b.get(bytes);
+ data.putString(new String(bytes, UTF_8));
+ }
+ }
+
+ private static class BinaryConstructor extends VariableConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.BINARY;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ int size = b.getInt();
+ byte[] bytes = new byte[size];
+ b.get(bytes);
+ data.putBinary(bytes);
+ }
+ }
+
+ private static class SymbolConstructor extends VariableConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.SYMBOL;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ int size = b.getInt();
+ byte[] bytes = new byte[size];
+ b.get(bytes);
+ data.putSymbol(Symbol.valueOf(new String(bytes, ASCII)));
+ }
+ }
+
+
+ private static class StringConstructor extends VariableConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.STRING;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ int size = b.getInt();
+ byte[] bytes = new byte[size];
+ b.get(bytes);
+ data.putString(new String(bytes, UTF_8));
+ }
+ }
+
+
+ private static class SmallListConstructor extends SmallVariableConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.LIST;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ int size = b.get() & 0xff;
+ ByteBuffer buf = b.slice();
+ buf.limit(size);
+ b.position(b.position()+size);
+ int count = buf.get() & 0xff;
+ data.putList();
+ parseChildren(data, buf, count);
+ }
+ }
+
+
+ private static class SmallMapConstructor extends SmallVariableConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.MAP;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ int size = b.get() & 0xff;
+ ByteBuffer buf = b.slice();
+ buf.limit(size);
+ b.position(b.position()+size);
+ int count = buf.get() & 0xff;
+ data.putMap();
+ parseChildren(data, buf, count);
+ }
+ }
+
+
+ private static class ListConstructor extends VariableConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.LIST;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ int size = b.getInt();
+ ByteBuffer buf = b.slice();
+ buf.limit(size);
+ b.position(b.position()+size);
+ int count = buf.getInt();
+ data.putList();
+ parseChildren(data, buf, count);
+ }
+ }
+
+
+ private static class MapConstructor extends VariableConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.MAP;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ int size = b.getInt();
+ ByteBuffer buf = b.slice();
+ buf.limit(size);
+ b.position(b.position()+size);
+ int count = buf.getInt();
+ data.putMap();
+ parseChildren(data, buf, count);
+ }
+ }
+
+
+ private static void parseChildren(Data data, ByteBuffer buf, int count)
+ {
+ data.enter();
+ for(int i = 0; i < count; i++)
+ {
+ TypeConstructor c = readConstructor(buf);
+ final int size = c.size(buf);
+ final int remaining = buf.remaining();
+ if(size <= remaining)
+ {
+ c.parse(buf, data);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Malformed data");
+ }
+
+ }
+ data.exit();
+ }
+
+ private static class DescribedTypeConstructor implements TypeConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.DESCRIBED;
+ }
+
+ @Override
+ public int size(ByteBuffer b)
+ {
+ ByteBuffer buf = b.slice();
+ if(buf.hasRemaining())
+ {
+ TypeConstructor c = readConstructor(buf);
+ int size = c.size(buf);
+ if(buf.remaining()>size)
+ {
+ buf.position(size + 1);
+ c = readConstructor(buf);
+ return size + 2 + c.size(buf);
+ }
+ else
+ {
+ return size + 2;
+ }
+ }
+ else
+ {
+ return 1;
+ }
+
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+ data.putDescribed();
+ data.enter();
+ TypeConstructor c = readConstructor(b);
+ c.parse(b, data);
+ c = readConstructor(b);
+ c.parse(b, data);
+ data.exit();
+ }
+ }
+
+ private static class SmallArrayConstructor extends SmallVariableConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.ARRAY;
+ }
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+
+ int size = b.get() & 0xff;
+ ByteBuffer buf = b.slice();
+ buf.limit(size);
+ b.position(b.position()+size);
+ int count = buf.get() & 0xff;
+ parseArray(data, buf, count);
+ }
+
+ }
+
+ private static class ArrayConstructor extends VariableConstructor
+ {
+
+ @Override
+ public Data.DataType getType()
+ {
+ return Data.DataType.ARRAY;
+ }
+
+
+ @Override
+ public void parse(ByteBuffer b, Data data)
+ {
+
+ int size = b.getInt();
+ ByteBuffer buf = b.slice();
+ buf.limit(size);
+ b.position(b.position()+size);
+ int count = buf.getInt();
+ parseArray(data, buf, count);
+ }
+ }
+
+ private static void parseArray(Data data, ByteBuffer buf, int count)
+ {
+ byte type = buf.get();
+ boolean isDescribed = type == (byte)0x00;
+ int descriptorPosition = buf.position();
+ if(isDescribed)
+ {
+ TypeConstructor descriptorTc = readConstructor(buf);
+ buf.position(buf.position()+descriptorTc.size(buf));
+ type = buf.get();
+ if(type == (byte)0x00)
+ {
+ throw new IllegalArgumentException("Malformed array data");
+ }
+
+ }
+ TypeConstructor tc = _constructors[type&0xff];
+
+ data.putArray(isDescribed, tc.getType());
+ data.enter();
+ if(isDescribed)
+ {
+ int position = buf.position();
+ buf.position(descriptorPosition);
+ TypeConstructor descriptorTc = readConstructor(buf);
+ descriptorTc.parse(buf,data);
+ buf.position(position);
+ }
+ for(int i = 0; i<count; i++)
+ {
+ tc.parse(buf,data);
+ }
+
+ data.exit();
+ }
+
+}
\ No newline at end of file
Modified: qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/DataFactoryImpl.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/DataFactoryImpl.java?rev=1494067&r1=1494066&r2=1494067&view=diff
==============================================================================
--- qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/DataFactoryImpl.java (original)
+++ qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/DataFactoryImpl.java Tue Jun 18 08:23:57 2013
@@ -30,7 +30,6 @@ public class DataFactoryImpl extends Pro
@Override
public Data createData(final long capacity)
{
- // TODO
- throw new ProtonUnsupportedOperationException();
+ return new DataImpl();
}
}
Added: qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/DataImpl.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/DataImpl.java?rev=1494067&view=auto
==============================================================================
--- qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/DataImpl.java (added)
+++ qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/DataImpl.java Tue Jun 18 08:23:57 2013
@@ -0,0 +1,866 @@
+/*
+ *
+ * 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 java.nio.ByteBuffer;
+import java.util.*;
+
+import org.apache.qpid.proton.ProtonUnsupportedOperationException;
+import org.apache.qpid.proton.amqp.*;
+import org.apache.qpid.proton.codec.Data;
+
+
+public class DataImpl implements Data
+{
+
+ private Element _first;
+ private Element _current;
+ private Element _parent;
+
+
+ public DataImpl()
+ {
+ }
+
+ @Override
+ public void free()
+ {
+ _first = null;
+ _current = null;
+
+ }
+
+ @Override
+ public void clear()
+ {
+ _first=null;
+ _current=null;
+ _parent=null;
+ }
+
+ @Override
+ public long size()
+ {
+ return _first == null ? 0 : _first.size();
+ }
+
+ @Override
+ public void rewind()
+ {
+ _current = null;
+ _parent = null;
+ }
+
+ @Override
+ public DataType next()
+ {
+ Element next = _current == null ? (_parent == null ? _first : _parent.child()) : _current.next();
+
+ if(next != null)
+ {
+ _current = next;
+ }
+ return next == null ? null : next.getDataType();
+ }
+
+ @Override
+ public DataType prev()
+ {
+ Element prev = _current == null ? null : _current.prev();
+
+ _current = prev;
+ return prev == null ? null : prev.getDataType();
+ }
+
+ @Override
+ public boolean enter()
+ {
+ if(_current != null && _current.canEnter())
+ {
+
+ _parent = _current;
+ _current = null;
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public boolean exit()
+ {
+ if(_parent != null)
+ {
+ Element parent = _parent;
+ _current = parent;
+ _parent = _current.parent();
+ return true;
+
+ }
+ return false;
+ }
+
+ @Override
+ public boolean lookup(String name)
+ {
+ // TODO
+ throw new ProtonUnsupportedOperationException();
+
+ }
+
+ @Override
+ public DataType type()
+ {
+ return _current == null ? null : _current.getDataType();
+ }
+
+ @Override
+ public Binary encode()
+ {
+ int size = 0;
+ Element elt = _first;
+ while(elt != null)
+ {
+ size += elt.size();
+ elt = elt.next();
+ }
+ byte[] data = new byte[size];
+ ByteBuffer buf = ByteBuffer.wrap(data);
+ encode(buf);
+
+ return new Binary(data);
+ }
+
+ @Override
+ public long encode(ByteBuffer buf)
+ {
+ Element elt = _first;
+ int size = 0;
+ while(elt != null )
+ {
+ final int eltSize = elt.size();
+ if(eltSize <= buf.remaining())
+ {
+ size += elt.encode(buf);
+ }
+ else
+ {
+ size+= eltSize;
+ }
+ elt = elt.next();
+ }
+ return size;
+ }
+
+ @Override
+ public long decode(ByteBuffer buf)
+ {
+ return DataDecoder.decode(buf, this);
+ }
+
+
+ private void putElement(Element element)
+ {
+ if(_first == null)
+ {
+ _first = element;
+ }
+ else
+ {
+ if(_current == null)
+ {
+ element = _parent.addChild(element);
+ }
+ else
+ {
+ if(_parent!=null)
+ {
+ element = _parent.checkChild(element);
+ }
+ _current.setNext(element);
+ }
+ }
+
+ _current = element;
+ }
+
+ @Override
+ public void putList()
+ {
+ putElement(new ListElement(_parent, _current));
+ }
+
+ @Override
+ public void putMap()
+ {
+ putElement(new MapElement(_parent, _current));
+ }
+
+ @Override
+ public void putArray(boolean described, DataType type)
+ {
+ putElement(new ArrayElement(_parent, _current, described, type));
+
+ }
+
+ @Override
+ public void putDescribed()
+ {
+ putElement(new DescribedTypeElement(_parent, _current));
+ }
+
+ @Override
+ public void putNull()
+ {
+ putElement(new NullElement(_parent, _current));
+
+ }
+
+ @Override
+ public void putBoolean(boolean b)
+ {
+ putElement(new BooleanElement(_parent, _current, b));
+ }
+
+ @Override
+ public void putUnsignedByte(UnsignedByte ub)
+ {
+ putElement(new UnsignedByteElement(_parent, _current, ub));
+
+ }
+
+ @Override
+ public void putByte(byte b)
+ {
+ putElement(new ByteElement(_parent, _current, b));
+ }
+
+ @Override
+ public void putUnsignedShort(UnsignedShort us)
+ {
+ putElement(new UnsignedShortElement(_parent, _current, us));
+
+ }
+
+ @Override
+ public void putShort(short s)
+ {
+ putElement(new ShortElement(_parent, _current, s));
+ }
+
+ @Override
+ public void putUnsignedInteger(UnsignedInteger ui)
+ {
+ putElement(new UnsignedIntegerElement(_parent, _current, ui));
+ }
+
+ @Override
+ public void putInt(int i)
+ {
+ putElement(new IntegerElement(_parent, _current, i));
+ }
+
+ @Override
+ public void putChar(int c)
+ {
+ putElement(new CharElement(_parent, _current, c));
+ }
+
+ @Override
+ public void putUnsignedLong(UnsignedLong ul)
+ {
+ putElement(new UnsignedLongElement(_parent, _current, ul));
+ }
+
+ @Override
+ public void putLong(long l)
+ {
+ putElement(new LongElement(_parent, _current, l));
+ }
+
+ @Override
+ public void putTimestamp(Date t)
+ {
+ putElement(new TimestampElement(_parent,_current,t));
+ }
+
+ @Override
+ public void putFloat(float f)
+ {
+ putElement(new FloatElement(_parent,_current,f));
+ }
+
+ @Override
+ public void putDouble(double d)
+ {
+ putElement(new DoubleElement(_parent,_current,d));
+ }
+
+ @Override
+ public void putDecimal32(Decimal32 d)
+ {
+ putElement(new Decimal32Element(_parent,_current,d));
+ }
+
+ @Override
+ public void putDecimal64(Decimal64 d)
+ {
+ putElement(new Decimal64Element(_parent,_current,d));
+ }
+
+ @Override
+ public void putDecimal128(Decimal128 d)
+ {
+ putElement(new Decimal128Element(_parent,_current,d));
+ }
+
+ @Override
+ public void putUUID(UUID u)
+ {
+ putElement(new UUIDElement(_parent,_current,u));
+ }
+
+ @Override
+ public void putBinary(Binary bytes)
+ {
+ putElement(new BinaryElement(_parent, _current, bytes));
+ }
+
+ @Override
+ public void putBinary(byte[] bytes)
+ {
+ putBinary(new Binary(bytes));
+ }
+
+ @Override
+ public void putString(String string)
+ {
+ putElement(new StringElement(_parent,_current,string));
+ }
+
+ @Override
+ public void putSymbol(Symbol symbol)
+ {
+ putElement(new SymbolElement(_parent,_current,symbol));
+ }
+
+ @Override
+ public void putObject(Object o)
+ {
+ if(o == null)
+ {
+ putNull();
+ }
+ else if(o instanceof Boolean)
+ {
+ putBoolean((Boolean) o);
+ }
+ else if(o instanceof UnsignedByte)
+ {
+ putUnsignedByte((UnsignedByte)o);
+ }
+ else if(o instanceof Byte)
+ {
+ putByte((Byte)o);
+ }
+ else if(o instanceof UnsignedShort)
+ {
+ putUnsignedShort((UnsignedShort)o);
+ }
+ else if(o instanceof Short)
+ {
+ putShort((Short)o);
+ }
+ else if(o instanceof UnsignedInteger)
+ {
+ putUnsignedInteger((UnsignedInteger)o);
+ }
+ else if(o instanceof Integer)
+ {
+ putInt((Integer)o);
+ }
+ else if(o instanceof Character)
+ {
+ putChar((Character)o);
+ }
+ else if(o instanceof UnsignedLong)
+ {
+ putUnsignedLong((UnsignedLong)o);
+ }
+ else if(o instanceof Long)
+ {
+ putLong((Long)o);
+ }
+ else if(o instanceof Date)
+ {
+ putTimestamp((Date)o);
+ }
+ else if(o instanceof Float)
+ {
+ putFloat((Float)o);
+ }
+ else if(o instanceof Double)
+ {
+ putDouble((Double)o);
+ }
+ else if(o instanceof Decimal32)
+ {
+ putDecimal32((Decimal32)o);
+ }
+ else if(o instanceof Decimal64)
+ {
+ putDecimal64((Decimal64)o);
+ }
+ else if(o instanceof Decimal128)
+ {
+ putDecimal128((Decimal128)o);
+ }
+ else if(o instanceof UUID)
+ {
+ putUUID((UUID)o);
+ }
+ else if(o instanceof Binary)
+ {
+ putBinary((Binary)o);
+ }
+ else if(o instanceof String)
+ {
+ putString((String)o);
+ }
+ else if(o instanceof Symbol)
+ {
+ putSymbol((Symbol)o);
+ }
+ else if(o instanceof DescribedType)
+ {
+ putDescribedType((DescribedType)o);
+ }
+ else if(o instanceof Object[])
+ {
+ putJavaArray((Object[]) o);
+ }
+ else if(o instanceof List)
+ {
+ putJavaList((List)o);
+ }
+ else if(o instanceof Map)
+ {
+ putJavaMap((Map)o);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Unknown type " + o.getClass().getSimpleName());
+ }
+ }
+
+ @Override
+ public void putJavaMap(Map<Object, Object> map)
+ {
+ putMap();
+ enter();
+ for(Map.Entry<Object, Object> entry : map.entrySet())
+ {
+ putObject(entry.getKey());
+ putObject(entry.getValue());
+ }
+ exit();
+
+ }
+
+ @Override
+ public void putJavaList(List<Object> list)
+ {
+ putList();
+ enter();
+ for(Object o : list)
+ {
+ putObject(o);
+ }
+ exit();
+ }
+
+ @Override
+ public void putJavaArray(Object[] array)
+ {
+ // TODO
+ throw new ProtonUnsupportedOperationException();
+ }
+
+ @Override
+ public void putDescribedType(DescribedType dt)
+ {
+ putElement(new DescribedTypeElement(_parent,_current));
+ enter();
+ putObject(dt.getDescriptor());
+ putObject(dt.getDescribed());
+ exit();
+ }
+
+ @Override
+ public long getList()
+ {
+ if(_current instanceof ListElement)
+ {
+ return ((ListElement)_current).count();
+ }
+ throw new IllegalStateException("Current value not list");
+ }
+
+ @Override
+ public long getMap()
+ {
+ if(_current instanceof MapElement)
+ {
+ return ((MapElement)_current).count();
+ }
+ throw new IllegalStateException("Current value not map");
+ }
+
+ @Override
+ public long getArray()
+ {
+ if(_current instanceof ArrayElement)
+ {
+ return ((ArrayElement)_current).count();
+ }
+ throw new IllegalStateException("Current value not array");
+ }
+
+ @Override
+ public boolean isArrayDescribed()
+ {
+ if(_current instanceof ArrayElement)
+ {
+ return ((ArrayElement)_current).isDescribed();
+ }
+ throw new IllegalStateException("Current value not array");
+ }
+
+ @Override
+ public DataType getArrayType()
+ {
+ if(_current instanceof ArrayElement)
+ {
+ return ((ArrayElement)_current).getArrayDataType();
+ }
+ throw new IllegalStateException("Current value not array");
+ }
+
+ @Override
+ public boolean isDescribed()
+ {
+ return _current != null && _current.getDataType() == DataType.DESCRIBED;
+ }
+
+ @Override
+ public boolean isNull()
+ {
+ return _current != null && _current.getDataType() == DataType.NULL;
+ }
+
+ @Override
+ public boolean getBoolean()
+ {
+ if(_current instanceof BooleanElement)
+ {
+ return ((BooleanElement)_current).getValue();
+ }
+ throw new IllegalStateException("Current value not boolean");
+ }
+
+ @Override
+ public UnsignedByte getUnsignedByte()
+ {
+
+ if(_current instanceof UnsignedByteElement)
+ {
+ return ((UnsignedByteElement)_current).getValue();
+ }
+ throw new IllegalStateException("Current value not unsigned byte");
+ }
+
+ @Override
+ public byte getByte()
+ {
+ if(_current instanceof ByteElement)
+ {
+ return ((ByteElement)_current).getValue();
+ }
+ throw new IllegalStateException("Current value not byte");
+ }
+
+ @Override
+ public UnsignedShort getUnsignedShort()
+ {
+ if(_current instanceof UnsignedShortElement)
+ {
+ return ((UnsignedShortElement)_current).getValue();
+ }
+ throw new IllegalStateException("Current value not unsigned short");
+ }
+
+ @Override
+ public short getShort()
+ {
+ if(_current instanceof ShortElement)
+ {
+ return ((ShortElement)_current).getValue();
+ }
+ throw new IllegalStateException("Current value not short");
+ }
+
+ @Override
+ public UnsignedInteger getUnsignedInteger()
+ {
+ if(_current instanceof UnsignedIntegerElement)
+ {
+ return ((UnsignedIntegerElement)_current).getValue();
+ }
+ throw new IllegalStateException("Current value not unsigned integer");
+ }
+
+ @Override
+ public int getInt()
+ {
+ if(_current instanceof IntegerElement)
+ {
+ return ((IntegerElement)_current).getValue();
+ }
+ throw new IllegalStateException("Current value not integer");
+ }
+
+ @Override
+ public int getChar()
+ {
+ if(_current instanceof CharElement)
+ {
+ return ((CharElement)_current).getValue();
+ }
+ throw new IllegalStateException("Current value not char");
+ }
+
+ @Override
+ public UnsignedLong getUnsignedLong()
+ {
+ if(_current instanceof UnsignedLongElement)
+ {
+ return ((UnsignedLongElement)_current).getValue();
+ }
+ throw new IllegalStateException("Current value not unsigned long");
+ }
+
+ @Override
+ public long getLong()
+ {
+ if(_current instanceof LongElement)
+ {
+ return ((LongElement)_current).getValue();
+ }
+ throw new IllegalStateException("Current value not long");
+ }
+
+ @Override
+ public Date getTimestamp()
+ {
+ if(_current instanceof TimestampElement)
+ {
+ return ((TimestampElement)_current).getValue();
+ }
+ throw new IllegalStateException("Current value not timestamp");
+ }
+
+ @Override
+ public float getFloat()
+ {
+ if(_current instanceof FloatElement)
+ {
+ return ((FloatElement)_current).getValue();
+ }
+ throw new IllegalStateException("Current value not float");
+ }
+
+ @Override
+ public double getDouble()
+ {
+ if(_current instanceof DoubleElement)
+ {
+ return ((DoubleElement)_current).getValue();
+ }
+ throw new IllegalStateException("Current value not double");
+ }
+
+ @Override
+ public Decimal32 getDecimal32()
+ {
+ if(_current instanceof Decimal32Element)
+ {
+ return ((Decimal32Element)_current).getValue();
+ }
+ throw new IllegalStateException("Current value not decimal32");
+ }
+
+ @Override
+ public Decimal64 getDecimal64()
+ {
+ if(_current instanceof Decimal64Element)
+ {
+ return ((Decimal64Element)_current).getValue();
+ }
+ throw new IllegalStateException("Current value not decimal32");
+ }
+
+ @Override
+ public Decimal128 getDecimal128()
+ {
+ if(_current instanceof Decimal128Element)
+ {
+ return ((Decimal128Element)_current).getValue();
+ }
+ throw new IllegalStateException("Current value not decimal32");
+ }
+
+ @Override
+ public UUID getUUID()
+ {
+ if(_current instanceof UUIDElement)
+ {
+ return ((UUIDElement)_current).getValue();
+ }
+ throw new IllegalStateException("Current value not uuid");
+ }
+
+ @Override
+ public Binary getBinary()
+ {
+ if(_current instanceof BinaryElement)
+ {
+ return ((BinaryElement)_current).getValue();
+ }
+ throw new IllegalStateException("Current value not binary");
+ }
+
+ @Override
+ public String getString()
+ {
+ if (_current instanceof StringElement)
+ {
+ return ((StringElement) _current).getValue();
+ }
+ throw new IllegalStateException("Current value not string");
+ }
+
+ @Override
+ public Symbol getSymbol()
+ {
+ if(_current instanceof SymbolElement)
+ {
+ return ((SymbolElement)_current).getValue();
+ }
+ throw new IllegalStateException("Current value not symbol");
+ }
+
+ @Override
+ public Object getObject()
+ {
+ return _current.getValue();
+ }
+
+ @Override
+ public Map<Object, Object> getJavaMap()
+ {
+ if(_current instanceof MapElement)
+ {
+ return ((MapElement)_current).getValue();
+ }
+ throw new IllegalStateException("Current value not map");
+ }
+
+ @Override
+ public List<Object> getJavaList()
+ {
+ if(_current instanceof ListElement)
+ {
+ return ((ListElement)_current).getValue();
+ }
+ throw new IllegalStateException("Current value not list");
+ }
+
+ @Override
+ public Object[] getJavaArray()
+ {
+ if(_current instanceof ArrayElement)
+ {
+ return ((ArrayElement)_current).getValue();
+ }
+ throw new IllegalStateException("Current value not array");
+ }
+
+ @Override
+ public DescribedType getDescribedType()
+ {
+ if(_current instanceof DescribedTypeElement)
+ {
+ return ((DescribedTypeElement)_current).getValue();
+ }
+ throw new IllegalStateException("Current value not described type");
+ }
+
+ @Override
+ public void copy(Data src)
+ {
+ // TODO
+
+ throw new ProtonUnsupportedOperationException();
+ }
+
+ @Override
+ public void append(Data src)
+ {
+ // TODO
+
+ throw new ProtonUnsupportedOperationException();
+ }
+
+ @Override
+ public void appendn(Data src, int limit)
+ {
+ // TODO
+
+ throw new ProtonUnsupportedOperationException();
+ }
+
+ @Override
+ public void narrow()
+ {
+ // TODO
+
+ throw new ProtonUnsupportedOperationException();
+ }
+
+ @Override
+ public void widen()
+ {
+ // TODO
+
+ throw new ProtonUnsupportedOperationException();
+ }
+
+}
\ No newline at end of file
Added: qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/Decimal128Element.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/Decimal128Element.java?rev=1494067&view=auto
==============================================================================
--- qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/Decimal128Element.java (added)
+++ qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/Decimal128Element.java Tue Jun 18 08:23:57 2013
@@ -0,0 +1,77 @@
+/*
+ *
+ * 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 java.nio.ByteBuffer;
+
+import org.apache.qpid.proton.amqp.Decimal128;
+import org.apache.qpid.proton.codec.Data;
+
+class Decimal128Element extends AtomicElement<Decimal128>
+{
+
+ private final Decimal128 _value;
+
+ Decimal128Element(Element parent, Element prev, Decimal128 d)
+ {
+ super(parent, prev);
+ _value = d;
+ }
+
+ @Override
+ public int size()
+ {
+ return isElementOfArray() ? 16 : 17;
+ }
+
+ @Override
+ public Decimal128 getValue()
+ {
+ return _value;
+ }
+
+ @Override
+ public Data.DataType getDataType()
+ {
+ return Data.DataType.DECIMAL128;
+ }
+
+ @Override
+ public int encode(ByteBuffer b)
+ {
+ int size = size();
+ if(b.remaining()>=size)
+ {
+ if(size == 17)
+ {
+ b.put((byte)0x94);
+ }
+ b.putLong(_value.getMostSignificantBits());
+ b.putLong(_value.getLeastSignificantBits());
+ return size;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org