http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/EncodeException.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/EncodeException.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/EncodeException.java deleted file mode 100644 index 5aa28bc..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/EncodeException.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * - * 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; - -public class EncodeException extends RuntimeException -{ - public EncodeException() - { - } - - public EncodeException(String message) - { - super(message); - } - - public EncodeException(String message, Throwable cause) - { - super(message, cause); - } - - public EncodeException(Throwable cause) - { - super(cause); - } -}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/Encoder.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/Encoder.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/Encoder.java deleted file mode 100644 index a0ab5b8..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/Encoder.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * - * 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; - -import org.apache.qpid.proton.amqp.Binary; -import org.apache.qpid.proton.amqp.Decimal128; -import org.apache.qpid.proton.amqp.Decimal32; -import org.apache.qpid.proton.amqp.Decimal64; -import org.apache.qpid.proton.amqp.DescribedType; -import org.apache.qpid.proton.amqp.Symbol; -import org.apache.qpid.proton.amqp.UnsignedByte; -import org.apache.qpid.proton.amqp.UnsignedInteger; -import org.apache.qpid.proton.amqp.UnsignedLong; -import org.apache.qpid.proton.amqp.UnsignedShort; - -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -public interface Encoder -{ - void writeNull(); - - void writeBoolean(boolean bool); - - void writeBoolean(Boolean bool); - - void writeUnsignedByte(UnsignedByte ubyte); - - void writeUnsignedShort(UnsignedShort ushort); - - void writeUnsignedInteger(UnsignedInteger ushort); - - void writeUnsignedLong(UnsignedLong ulong); - - void writeByte(byte b); - - void writeByte(Byte b); - - void writeShort(short s); - - void writeShort(Short s); - - void writeInteger(int i); - - void writeInteger(Integer i); - - void writeLong(long l); - - void writeLong(Long l); - - void writeFloat(float f); - - void writeFloat(Float f); - - void writeDouble(double d); - - void writeDouble(Double d); - - void writeDecimal32(Decimal32 d); - - void writeDecimal64(Decimal64 d); - - void writeDecimal128(Decimal128 d); - - void writeCharacter(char c); - - void writeCharacter(Character c); - - void writeTimestamp(long d); - void writeTimestamp(Date d); - - void writeUUID(UUID uuid); - - void writeBinary(Binary b); - - void writeString(String s); - - void writeSymbol(Symbol s); - - void writeList(List l); - - void writeMap(Map m); - - void writeDescribedType(DescribedType d); - - void writeArray(boolean[] a); - void writeArray(byte[] a); - void writeArray(short[] a); - void writeArray(int[] a); - void writeArray(long[] a); - void writeArray(float[] a); - void writeArray(double[] a); - void writeArray(char[] a); - void writeArray(Object[] a); - - void writeObject(Object o); - - <V> void register(AMQPType<V> type); - - AMQPType getType(Object element); -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/EncoderImpl.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/EncoderImpl.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/EncoderImpl.java deleted file mode 100644 index 97e1005..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/EncoderImpl.java +++ /dev/null @@ -1,817 +0,0 @@ -/* - * - * 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; - -import java.nio.ByteBuffer; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.apache.qpid.proton.amqp.Binary; -import org.apache.qpid.proton.amqp.Decimal128; -import org.apache.qpid.proton.amqp.Decimal32; -import org.apache.qpid.proton.amqp.Decimal64; -import org.apache.qpid.proton.amqp.DescribedType; -import org.apache.qpid.proton.amqp.Symbol; -import org.apache.qpid.proton.amqp.UnsignedByte; -import org.apache.qpid.proton.amqp.UnsignedInteger; -import org.apache.qpid.proton.amqp.UnsignedLong; -import org.apache.qpid.proton.amqp.UnsignedShort; - -public final class EncoderImpl implements ByteBufferEncoder -{ - private static final byte DESCRIBED_TYPE_OP = (byte)0; - - - private WritableBuffer _buffer; - - private final Map<Class, AMQPType> _typeRegistry = new HashMap<Class, AMQPType>(); - private Map<Object, AMQPType> _describedDescriptorRegistry = new HashMap<Object, AMQPType>(); - private Map<Class, AMQPType> _describedTypesClassRegistry = new HashMap<Class, AMQPType>(); - - private final NullType _nullType; - private final BooleanType _booleanType; - private final ByteType _byteType; - private final UnsignedByteType _unsignedByteType; - private final ShortType _shortType; - private final UnsignedShortType _unsignedShortType; - private final IntegerType _integerType; - private final UnsignedIntegerType _unsignedIntegerType; - private final LongType _longType; - private final UnsignedLongType _unsignedLongType; - private final BigIntegerType _bigIntegerType; - - private final CharacterType _characterType; - private final FloatType _floatType; - private final DoubleType _doubleType; - private final TimestampType _timestampType; - private final UUIDType _uuidType; - - private final Decimal32Type _decimal32Type; - private final Decimal64Type _decimal64Type; - private final Decimal128Type _decimal128Type; - - private final BinaryType _binaryType; - private final SymbolType _symbolType; - private final StringType _stringType; - - private final ListType _listType; - private final MapType _mapType; - - private final ArrayType _arrayType; - - EncoderImpl(ByteBuffer buffer, DecoderImpl decoder) - { - this(decoder); - setByteBuffer(buffer); - } - - public EncoderImpl(DecoderImpl decoder) - { - - _nullType = new NullType(this, decoder); - _booleanType = new BooleanType(this, decoder); - _byteType = new ByteType(this, decoder); - _unsignedByteType = new UnsignedByteType(this, decoder); - _shortType = new ShortType(this, decoder); - _unsignedShortType = new UnsignedShortType(this, decoder); - _integerType = new IntegerType(this, decoder); - _unsignedIntegerType = new UnsignedIntegerType(this, decoder); - _longType = new LongType(this, decoder); - _unsignedLongType = new UnsignedLongType(this, decoder); - _bigIntegerType = new BigIntegerType(this, decoder); - - _characterType = new CharacterType(this, decoder); - _floatType = new FloatType(this, decoder); - _doubleType = new DoubleType(this, decoder); - _timestampType = new TimestampType(this, decoder); - _uuidType = new UUIDType(this, decoder); - - _decimal32Type = new Decimal32Type(this, decoder); - _decimal64Type = new Decimal64Type(this, decoder); - _decimal128Type = new Decimal128Type(this, decoder); - - - _binaryType = new BinaryType(this, decoder); - _symbolType = new SymbolType(this, decoder); - _stringType = new StringType(this, decoder); - - _listType = new ListType(this, decoder); - _mapType = new MapType(this, decoder); - - _arrayType = new ArrayType(this, - decoder, - _booleanType, - _byteType, - _shortType, - _integerType, - _longType, - _floatType, - _doubleType, - _characterType); - - - } - - public void setByteBuffer(final ByteBuffer buf) - { - _buffer = new WritableBuffer.ByteBufferWrapper(buf); - } - - public void setByteBuffer(final WritableBuffer buf) - { - _buffer = buf; - } - - - @Override - public AMQPType getType(final Object element) - { - if(element instanceof DescribedType) - { - AMQPType amqpType; - - Object descriptor = ((DescribedType)element).getDescriptor(); - amqpType = _describedDescriptorRegistry.get(descriptor); - if(amqpType == null) - { - amqpType = new DynamicDescribedType(this, descriptor); - _describedDescriptorRegistry.put(descriptor, amqpType); - } - return amqpType; - - } - else - { - return getTypeFromClass(element == null ? Void.class : element.getClass()); - } - } - - public AMQPType getTypeFromClass(final Class clazz) - { - AMQPType amqpType = _typeRegistry.get(clazz); - if(amqpType == null) - { - - if(clazz.isArray()) - { - amqpType = _arrayType; - } - else - { - if(List.class.isAssignableFrom(clazz)) - { - amqpType = _listType; - } - else if(Map.class.isAssignableFrom(clazz)) - { - amqpType = _mapType; - } - else if(DescribedType.class.isAssignableFrom(clazz)) - { - amqpType = _describedTypesClassRegistry.get(clazz); - } - } - _typeRegistry.put(clazz, amqpType); - } - return amqpType; - } - - @Override - public <V> void register(AMQPType<V> type) - { - register(type.getTypeClass(), type); - } - - <T> void register(Class<T> clazz, AMQPType<T> type) - { - _typeRegistry.put(clazz, type); - } - - public void registerDescribedType(Class clazz, Object descriptor) - { - AMQPType type = _describedDescriptorRegistry.get(descriptor); - if(type == null) - { - type = new DynamicDescribedType(this, descriptor); - _describedDescriptorRegistry.put(descriptor, type); - } - _describedTypesClassRegistry.put(clazz, type); - } - - public void writeNull() - { - _nullType.write(); - } - - public void writeBoolean(final boolean bool) - { - _booleanType.writeValue(bool); - } - - public void writeBoolean(final Boolean bool) - { - if(bool == null) - { - writeNull(); - } - else - { - _booleanType.write(bool); - } - } - - public void writeUnsignedByte(final UnsignedByte ubyte) - { - if(ubyte == null) - { - writeNull(); - } - else - { - _unsignedByteType.write(ubyte); - } - } - - public void writeUnsignedShort(final UnsignedShort ushort) - { - if(ushort == null) - { - writeNull(); - } - else - { - _unsignedShortType.write(ushort); - } - } - - public void writeUnsignedInteger(final UnsignedInteger uint) - { - if(uint == null) - { - writeNull(); - } - else - { - _unsignedIntegerType.write(uint); - } - } - - public void writeUnsignedLong(final UnsignedLong ulong) - { - if(ulong == null) - { - writeNull(); - } - else - { - _unsignedLongType.write(ulong); - } - } - - public void writeByte(final byte b) - { - _byteType.write(b); - } - - public void writeByte(final Byte b) - { - if(b == null) - { - writeNull(); - } - else - { - writeByte(b.byteValue()); - } - } - - public void writeShort(final short s) - { - _shortType.write(s); - } - - public void writeShort(final Short s) - { - if(s == null) - { - writeNull(); - } - else - { - writeShort(s.shortValue()); - } - } - - public void writeInteger(final int i) - { - _integerType.write(i); - } - - public void writeInteger(final Integer i) - { - if(i == null) - { - writeNull(); - } - else - { - writeInteger(i.intValue()); - } - } - - public void writeLong(final long l) - { - _longType.write(l); - } - - public void writeLong(final Long l) - { - - if(l == null) - { - writeNull(); - } - else - { - writeLong(l.longValue()); - } - } - - public void writeFloat(final float f) - { - _floatType.write(f); - } - - public void writeFloat(final Float f) - { - if(f == null) - { - writeNull(); - } - else - { - writeFloat(f.floatValue()); - } - } - - public void writeDouble(final double d) - { - _doubleType.write(d); - } - - public void writeDouble(final Double d) - { - if(d == null) - { - writeNull(); - } - else - { - writeDouble(d.doubleValue()); - } - } - - public void writeDecimal32(final Decimal32 d) - { - if(d == null) - { - writeNull(); - } - else - { - _decimal32Type.write(d); - } - } - - public void writeDecimal64(final Decimal64 d) - { - if(d == null) - { - writeNull(); - } - else - { - _decimal64Type.write(d); - } - } - - public void writeDecimal128(final Decimal128 d) - { - if(d == null) - { - writeNull(); - } - else - { - _decimal128Type.write(d); - } - } - - public void writeCharacter(final char c) - { - // TODO - java character may be half of a pair, should probably throw exception then - _characterType.write(c); - } - - public void writeCharacter(final Character c) - { - if(c == null) - { - writeNull(); - } - else - { - writeCharacter(c.charValue()); - } - } - - public void writeTimestamp(final long d) - { - _timestampType.write(d); - } - - public void writeTimestamp(final Date d) - { - if(d == null) - { - writeNull(); - } - else - { - writeTimestamp(d.getTime()); - } - } - - public void writeUUID(final UUID uuid) - { - if(uuid == null) - { - writeNull(); - } - else - { - _uuidType.write(uuid); - } - - } - - public void writeBinary(final Binary b) - { - if(b == null) - { - writeNull(); - } - else - { - _binaryType.write(b); - } - } - - public void writeString(final String s) - { - if(s == null) - { - writeNull(); - } - else - { - _stringType.write(s); - } - } - - public void writeSymbol(final Symbol s) - { - if(s == null) - { - writeNull(); - } - else - { - _symbolType.write(s); - } - - } - - public void writeList(final List l) - { - if(l == null) - { - writeNull(); - } - else - { - _listType.write(l); - } - } - - public void writeMap(final Map m) - { - - if(m == null) - { - writeNull(); - } - else - { - _mapType.write(m); - } - } - - public void writeDescribedType(final DescribedType d) - { - if(d == null) - { - writeNull(); - } - else - { - _buffer.put(DESCRIBED_TYPE_OP); - writeObject(d.getDescriptor()); - writeObject(d.getDescribed()); - } - } - - public void writeArray(final boolean[] a) - { - if(a == null) - { - writeNull(); - } - else - { - _arrayType.write(a); - } - } - - public void writeArray(final byte[] a) - { - if(a == null) - { - writeNull(); - } - else - { - _arrayType.write(a); - } - } - - public void writeArray(final short[] a) - { - if(a == null) - { - writeNull(); - } - else - { - _arrayType.write(a); - } - } - - public void writeArray(final int[] a) - { - if(a == null) - { - writeNull(); - } - else - { - _arrayType.write(a); - } - } - - public void writeArray(final long[] a) - { - if(a == null) - { - writeNull(); - } - else - { - _arrayType.write(a); - } - } - - public void writeArray(final float[] a) - { - if(a == null) - { - writeNull(); - } - else - { - _arrayType.write(a); - } - } - - public void writeArray(final double[] a) - { - if(a == null) - { - writeNull(); - } - else - { - _arrayType.write(a); - } - } - - public void writeArray(final char[] a) - { - if(a == null) - { - writeNull(); - } - else - { - _arrayType.write(a); - } - } - - public void writeArray(final Object[] a) - { - if(a == null) - { - writeNull(); - } - else - { - _arrayType.write(a); - } - } - - public void writeObject(final Object o) - { - AMQPType type = _typeRegistry.get(o == null ? Void.class : o.getClass()); - - if(type == null) - { - if(o.getClass().isArray()) - { - Class<?> componentType = o.getClass().getComponentType(); - if(componentType.isPrimitive()) - { - if(componentType == Boolean.TYPE) - { - writeArray((boolean[])o); - } - else if(componentType == Byte.TYPE) - { - writeArray((byte[])o); - } - else if(componentType == Short.TYPE) - { - writeArray((short[])o); - } - else if(componentType == Integer.TYPE) - { - writeArray((int[])o); - } - else if(componentType == Long.TYPE) - { - writeArray((long[])o); - } - else if(componentType == Float.TYPE) - { - writeArray((float[])o); - } - else if(componentType == Double.TYPE) - { - writeArray((double[])o); - } - else if(componentType == Character.TYPE) - { - writeArray((char[])o); - } - else - { - throw new IllegalArgumentException("Cannot write arrays of type " + componentType.getName()); - } - } - else - { - writeArray((Object[]) o); - } - } - else if(o instanceof List) - { - writeList((List)o); - } - else if(o instanceof Map) - { - writeMap((Map)o); - } - else if(o instanceof DescribedType) - { - writeDescribedType((DescribedType)o); - } - else - { - throw new IllegalArgumentException("Do not know how to write Objects of class " + o.getClass() - .getName()); - - } - } - else - { - type.write(o); - } - } - - public void writeRaw(final byte b) - { - _buffer.put(b); - } - - void writeRaw(final short s) - { - _buffer.putShort(s); - } - - void writeRaw(final int i) - { - _buffer.putInt(i); - } - - void writeRaw(final long l) - { - _buffer.putLong(l); - } - - void writeRaw(final float f) - { - _buffer.putFloat(f); - } - - void writeRaw(final double d) - { - _buffer.putDouble(d); - } - - void writeRaw(byte[] src, int offset, int length) - { - _buffer.put(src, offset, length); - } - - void writeRaw(String string) - { - final int length = string.length(); - int c; - - for (int i = 0; i < length; i++) - { - c = string.charAt(i); - if ((c & 0xFF80) == 0) /* U+0000..U+007F */ - { - _buffer.put((byte) c); - } - else if ((c & 0xF800) == 0) /* U+0080..U+07FF */ - { - _buffer.put((byte)(0xC0 | ((c >> 6) & 0x1F))); - _buffer.put((byte)(0x80 | (c & 0x3F))); - } - else if ((c & 0xD800) != 0xD800 || (c > 0xDBFF)) /* U+0800..U+FFFF - excluding surrogate pairs */ - { - _buffer.put((byte)(0xE0 | ((c >> 12) & 0x0F))); - _buffer.put((byte)(0x80 | ((c >> 6) & 0x3F))); - _buffer.put((byte)(0x80 | (c & 0x3F))); - } - else - { - int low; - - if((++i == length) || ((low = string.charAt(i)) & 0xDC00) != 0xDC00) - { - throw new IllegalArgumentException("String contains invalid Unicode code points"); - } - - c = 0x010000 + ((c & 0x03FF) << 10) + (low & 0x03FF); - - _buffer.put((byte)(0xF0 | ((c >> 18) & 0x07))); - _buffer.put((byte)(0x80 | ((c >> 12) & 0x3F))); - _buffer.put((byte)(0x80 | ((c >> 6) & 0x3F))); - _buffer.put((byte)(0x80 | (c & 0x3F))); - } - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/EncodingCodes.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/EncodingCodes.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/EncodingCodes.java deleted file mode 100644 index ec55a90..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/EncodingCodes.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * - * 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; - -public interface EncodingCodes -{ - public static final byte DESCRIBED_TYPE_INDICATOR = (byte) 0x00; - - public static final byte NULL = (byte) 0x40; - - public static final byte BOOLEAN = (byte) 0x56; - public static final byte BOOLEAN_TRUE = (byte) 0x41; - public static final byte BOOLEAN_FALSE = (byte) 0x42; - - public static final byte UBYTE = (byte) 0x50; - - public static final byte USHORT = (byte) 0x60; - - public static final byte UINT = (byte) 0x70; - public static final byte SMALLUINT = (byte) 0x52; - public static final byte UINT0 = (byte) 0x43; - - public static final byte ULONG = (byte) 0x80; - public static final byte SMALLULONG = (byte) 0x53; - public static final byte ULONG0 = (byte) 0x44; - - public static final byte BYTE = (byte) 0x51; - - public static final byte SHORT = (byte) 0x61; - - public static final byte INT = (byte) 0x71; - public static final byte SMALLINT = (byte) 0x54; - - public static final byte LONG = (byte) 0x81; - public static final byte SMALLLONG = (byte) 0x55; - - public static final byte FLOAT = (byte) 0x72; - - public static final byte DOUBLE = (byte) 0x82; - - public static final byte DECIMAL32 = (byte) 0x74; - - public static final byte DECIMAL64 = (byte) 0x84; - - public static final byte DECIMAL128 = (byte) 0x94; - - public static final byte CHAR = (byte) 0x73; - - public static final byte TIMESTAMP = (byte) 0x83; - - public static final byte UUID = (byte) 0x98; - - public static final byte VBIN8 = (byte) 0xa0; - public static final byte VBIN32 = (byte) 0xb0; - - public static final byte STR8 = (byte) 0xa1; - public static final byte STR32 = (byte) 0xb1; - - public static final byte SYM8 = (byte) 0xa3; - public static final byte SYM32 = (byte) 0xb3; - - public static final byte LIST0 = (byte) 0x45; - public static final byte LIST8 = (byte) 0xc0; - public static final byte LIST32 = (byte) 0xd0; - - public static final byte MAP8 = (byte) 0xc1; - public static final byte MAP32 = (byte) 0xd1; - - public static final byte ARRAY8 = (byte) 0xe0; - public static final byte ARRAY32 = (byte) 0xf0; - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/FixedSizePrimitiveTypeEncoding.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/FixedSizePrimitiveTypeEncoding.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/FixedSizePrimitiveTypeEncoding.java deleted file mode 100644 index 2762064..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/FixedSizePrimitiveTypeEncoding.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * - * 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; - -abstract class FixedSizePrimitiveTypeEncoding<T> extends AbstractPrimitiveTypeEncoding<T> -{ - - FixedSizePrimitiveTypeEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - public final boolean isFixedSizeVal() - { - return true; - } - - public final int getValueSize(final T val) - { - return getFixedSize(); - } - - protected abstract int getFixedSize(); -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/FloatType.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/FloatType.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/FloatType.java deleted file mode 100644 index f00af4e..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/FloatType.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * - * 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; - -import java.util.Collection; -import java.util.Collections; - -public class FloatType extends AbstractPrimitiveType<Float> -{ - private FloatEncoding _floatEncoding; - - FloatType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _floatEncoding = new FloatEncoding(encoder, decoder); - encoder.register(Float.class, this); - decoder.register(this); - } - - public Class<Float> getTypeClass() - { - return Float.class; - } - - public FloatEncoding getEncoding(final Float val) - { - return _floatEncoding; - } - - - public FloatEncoding getCanonicalEncoding() - { - return _floatEncoding; - } - - public Collection<FloatEncoding> getAllEncodings() - { - return Collections.singleton(_floatEncoding); - } - - public void write(float f) - { - _floatEncoding.write(f); - } - - public class FloatEncoding extends FixedSizePrimitiveTypeEncoding<Float> - { - - public FloatEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 4; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.FLOAT; - } - - public FloatType getType() - { - return FloatType.this; - } - - public void writeValue(final Float val) - { - getEncoder().writeRaw(val.floatValue()); - } - - public void writeValue(final float val) - { - getEncoder().writeRaw(val); - } - - - public void write(final float f) - { - writeConstructor(); - getEncoder().writeRaw(f); - - } - - public boolean encodesSuperset(final TypeEncoding<Float> encoding) - { - return (getType() == encoding.getType()); - } - - public Float readValue() - { - return readPrimitiveValue(); - } - - public float readPrimitiveValue() - { - return getDecoder().readRawFloat(); - } - - - @Override - public boolean encodesJavaPrimitive() - { - return true; - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/FloatingSizePrimitiveTypeEncoding.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/FloatingSizePrimitiveTypeEncoding.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/FloatingSizePrimitiveTypeEncoding.java deleted file mode 100644 index eb6969d..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/FloatingSizePrimitiveTypeEncoding.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * - * 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; - -abstract class FloatingSizePrimitiveTypeEncoding<T> extends AbstractPrimitiveTypeEncoding<T> -{ - - FloatingSizePrimitiveTypeEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - public final boolean isFixedSizeVal() - { - return false; - } - - abstract int getSizeBytes(); - - public void writeValue(final T val) - { - writeSize(val); - writeEncodedValue(val); - } - - protected abstract void writeEncodedValue(final T val); - - protected abstract void writeSize(final T val); - - public int getValueSize(final T val) - { - return getSizeBytes() + getEncodedValueSize(val); - } - - protected abstract int getEncodedValueSize(final T val); -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/IntegerType.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/IntegerType.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/IntegerType.java deleted file mode 100644 index a4fd0f5..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/IntegerType.java +++ /dev/null @@ -1,213 +0,0 @@ -/* - * - * 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; - -import java.util.Arrays; -import java.util.Collection; - -public class IntegerType extends AbstractPrimitiveType<Integer> -{ - - public static interface IntegerEncoding extends PrimitiveTypeEncoding<Integer> - { - void write(int i); - void writeValue(int i); - int readPrimitiveValue(); - } - - private IntegerEncoding _integerEncoding; - private IntegerEncoding _smallIntegerEncoding; - - IntegerType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _integerEncoding = new AllIntegerEncoding(encoder, decoder); - _smallIntegerEncoding = new SmallIntegerEncoding(encoder, decoder); - encoder.register(Integer.class, this); - decoder.register(this); - } - - public Class<Integer> getTypeClass() - { - return Integer.class; - } - - public IntegerEncoding getEncoding(final Integer val) - { - return getEncoding(val.intValue()); - } - - public IntegerEncoding getEncoding(final int i) - { - - return (i >= -128 && i <= 127) ? _smallIntegerEncoding : _integerEncoding; - } - - - public IntegerEncoding getCanonicalEncoding() - { - return _integerEncoding; - } - - public Collection<IntegerEncoding> getAllEncodings() - { - return Arrays.asList(_integerEncoding, _smallIntegerEncoding); - } - - public void write(int i) - { - if(i >= -128 && i <= 127) - { - _smallIntegerEncoding.write(i); - } - else - { - _integerEncoding.write(i); - } - } - - private class AllIntegerEncoding extends FixedSizePrimitiveTypeEncoding<Integer> implements IntegerEncoding - { - - public AllIntegerEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 4; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.INT; - } - - public IntegerType getType() - { - return IntegerType.this; - } - - public void writeValue(final Integer val) - { - getEncoder().writeRaw(val.intValue()); - } - - public void write(final int i) - { - writeConstructor(); - getEncoder().writeRaw(i); - - } - - public void writeValue(final int i) - { - getEncoder().writeRaw(i); - } - - public int readPrimitiveValue() - { - return getDecoder().readRawInt(); - } - - public boolean encodesSuperset(final TypeEncoding<Integer> encoding) - { - return (getType() == encoding.getType()); - } - - public Integer readValue() - { - return readPrimitiveValue(); - } - - - @Override - public boolean encodesJavaPrimitive() - { - return true; - } - } - - private class SmallIntegerEncoding extends FixedSizePrimitiveTypeEncoding<Integer> implements IntegerEncoding - { - public SmallIntegerEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.SMALLINT; - } - - @Override - protected int getFixedSize() - { - return 1; - } - - public void write(final int i) - { - writeConstructor(); - getEncoder().writeRaw((byte)i); - } - - public void writeValue(final int i) - { - getEncoder().writeRaw((byte)i); - } - - public int readPrimitiveValue() - { - return getDecoder().readRawByte(); - } - - public IntegerType getType() - { - return IntegerType.this; - } - - public void writeValue(final Integer val) - { - getEncoder().writeRaw((byte)val.intValue()); - } - - public boolean encodesSuperset(final TypeEncoding<Integer> encoder) - { - return encoder == this; - } - - public Integer readValue() - { - return readPrimitiveValue(); - } - - - @Override - public boolean encodesJavaPrimitive() - { - return true; - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/LargeFloatingSizePrimitiveTypeEncoding.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/LargeFloatingSizePrimitiveTypeEncoding.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/LargeFloatingSizePrimitiveTypeEncoding.java deleted file mode 100644 index e6be002..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/LargeFloatingSizePrimitiveTypeEncoding.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * - * 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; - -abstract class LargeFloatingSizePrimitiveTypeEncoding<T> extends FloatingSizePrimitiveTypeEncoding<T> -{ - - LargeFloatingSizePrimitiveTypeEncoding(final EncoderImpl encoder, DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - public int getSizeBytes() - { - return 4; - } - - @Override - protected void writeSize(final T val) - { - getEncoder().writeRaw(getEncodedValueSize(val)); - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/ListType.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/ListType.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/ListType.java deleted file mode 100644 index 185373f..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/ListType.java +++ /dev/null @@ -1,300 +0,0 @@ -/* - * - * 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; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -public class ListType extends AbstractPrimitiveType<List> -{ - private final ListEncoding _listEncoding; - private final ListEncoding _shortListEncoding; - private final ListEncoding _zeroListEncoding; - private EncoderImpl _encoder; - - private static interface ListEncoding extends PrimitiveTypeEncoding<List> - { - void setValue(List value, int length); - } - - ListType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _encoder = encoder; - _listEncoding = new AllListEncoding(encoder, decoder); - _shortListEncoding = new ShortListEncoding(encoder, decoder); - _zeroListEncoding = new ZeroListEncoding(encoder, decoder); - encoder.register(List.class, this); - decoder.register(this); - } - - public Class<List> getTypeClass() - { - return List.class; - } - - public ListEncoding getEncoding(final List val) - { - - int calculatedSize = calculateSize(val, _encoder); - ListEncoding encoding = val.isEmpty() - ? _zeroListEncoding - : (val.size() > 255 || calculatedSize >= 254) - ? _listEncoding - : _shortListEncoding; - - encoding.setValue(val, calculatedSize); - return encoding; - } - - private static int calculateSize(final List val, EncoderImpl encoder) - { - int len = 0; - final int count = val.size(); - - for(int i = 0; i < count; i++) - { - Object element = val.get(i); - AMQPType type = encoder.getType(element); - if(type == null) - { - throw new IllegalArgumentException("No encoding defined for type: " + element.getClass()); - } - TypeEncoding elementEncoding = type.getEncoding(element); - len += elementEncoding.getConstructorSize()+elementEncoding.getValueSize(element); - } - return len; - } - - - public ListEncoding getCanonicalEncoding() - { - return _listEncoding; - } - - public Collection<ListEncoding> getAllEncodings() - { - return Arrays.asList(_zeroListEncoding, _shortListEncoding, _listEncoding); - } - - private class AllListEncoding - extends LargeFloatingSizePrimitiveTypeEncoding<List> - implements ListEncoding - { - - private List _value; - private int _length; - - public AllListEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected void writeEncodedValue(final List val) - { - getEncoder().writeRaw(val.size()); - - final int count = val.size(); - - for(int i = 0; i < count; i++) - { - Object element = val.get(i); - TypeEncoding elementEncoding = getEncoder().getType(element).getEncoding(element); - elementEncoding.writeConstructor(); - elementEncoding.writeValue(element); - } - } - - @Override - protected int getEncodedValueSize(final List val) - { - return 4 + ((val == _value) ? _length : calculateSize(val, getEncoder())); - } - - - @Override - public byte getEncodingCode() - { - return EncodingCodes.LIST32; - } - - public ListType getType() - { - return ListType.this; - } - - public boolean encodesSuperset(final TypeEncoding<List> encoding) - { - return (getType() == encoding.getType()); - } - - public List readValue() - { - DecoderImpl decoder = getDecoder(); - int size = decoder.readRawInt(); - // todo - limit the decoder with size - int count = decoder.readRawInt(); - // Ensure we do not allocate an array of size greater then the available data, otherwise there is a risk for an OOM error - if (count > decoder.getByteBufferRemaining()) { - throw new IllegalArgumentException("List element count "+count+" is specified to be greater than the amount of data available ("+ - decoder.getByteBufferRemaining()+")"); - } - List list = new ArrayList(count); - for(int i = 0; i < count; i++) - { - list.add(decoder.readObject()); - } - return list; - } - - public void setValue(final List value, final int length) - { - _value = value; - _length = length; - } - } - - private class ShortListEncoding - extends SmallFloatingSizePrimitiveTypeEncoding<List> - implements ListEncoding - { - - private List _value; - private int _length; - - public ShortListEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected void writeEncodedValue(final List val) - { - getEncoder().writeRaw((byte)val.size()); - - final int count = val.size(); - - for(int i = 0; i < count; i++) - { - Object element = val.get(i); - TypeEncoding elementEncoding = getEncoder().getType(element).getEncoding(element); - elementEncoding.writeConstructor(); - elementEncoding.writeValue(element); - } - } - - @Override - protected int getEncodedValueSize(final List val) - { - return 1 + ((val == _value) ? _length : calculateSize(val, getEncoder())); - } - - - @Override - public byte getEncodingCode() - { - return EncodingCodes.LIST8; - } - - public ListType getType() - { - return ListType.this; - } - - public boolean encodesSuperset(final TypeEncoding<List> encoder) - { - return encoder == this; - } - - public List readValue() - { - - DecoderImpl decoder = getDecoder(); - int size = ((int)decoder.readRawByte()) & 0xff; - // todo - limit the decoder with size - int count = ((int)decoder.readRawByte()) & 0xff; - List list = new ArrayList(count); - for(int i = 0; i < count; i++) - { - list.add(decoder.readObject()); - } - return list; - } - - public void setValue(final List value, final int length) - { - _value = value; - _length = length; - } - } - - - private class ZeroListEncoding - extends FixedSizePrimitiveTypeEncoding<List> - implements ListEncoding - { - public ZeroListEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.LIST0; - } - - @Override - protected int getFixedSize() - { - return 0; - } - - - public ListType getType() - { - return ListType.this; - } - - public void setValue(List value, int length) - { - } - - public void writeValue(final List val) - { - } - - public boolean encodesSuperset(final TypeEncoding<List> encoder) - { - return encoder == this; - } - - public List readValue() - { - return Collections.EMPTY_LIST; - } - - - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/LongType.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/LongType.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/LongType.java deleted file mode 100644 index 47532df..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/LongType.java +++ /dev/null @@ -1,212 +0,0 @@ -/* - * - * 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; - -import java.util.Arrays; -import java.util.Collection; - -public class LongType extends AbstractPrimitiveType<Long> -{ - - public static interface LongEncoding extends PrimitiveTypeEncoding<Long> - { - void write(long l); - void writeValue(long l); - public long readPrimitiveValue(); - } - - private LongEncoding _longEncoding; - private LongEncoding _smallLongEncoding; - - LongType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _longEncoding = new AllLongEncoding(encoder, decoder); - _smallLongEncoding = new SmallLongEncoding(encoder, decoder); - encoder.register(Long.class, this); - decoder.register(this); - } - - public Class<Long> getTypeClass() - { - return Long.class; - } - - public LongEncoding getEncoding(final Long val) - { - return getEncoding(val.longValue()); - } - - public LongEncoding getEncoding(final long l) - { - return (l >= -128l && l <= 127l) ? _smallLongEncoding : _longEncoding; - } - - - public LongEncoding getCanonicalEncoding() - { - return _longEncoding; - } - - public Collection<LongEncoding> getAllEncodings() - { - return Arrays.asList(_smallLongEncoding, _longEncoding); - } - - public void write(long l) - { - if(l >= -128l && l <= 127l) - { - _smallLongEncoding.write(l); - } - else - { - _longEncoding.write(l); - } - } - - private class AllLongEncoding extends FixedSizePrimitiveTypeEncoding<Long> implements LongEncoding - { - - public AllLongEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 8; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.LONG; - } - - public LongType getType() - { - return LongType.this; - } - - public void writeValue(final Long val) - { - getEncoder().writeRaw(val.longValue()); - } - - public void write(final long l) - { - writeConstructor(); - getEncoder().writeRaw(l); - - } - - public void writeValue(final long l) - { - getEncoder().writeRaw(l); - } - - public boolean encodesSuperset(final TypeEncoding<Long> encoding) - { - return (getType() == encoding.getType()); - } - - public Long readValue() - { - return readPrimitiveValue(); - } - - public long readPrimitiveValue() - { - return getDecoder().readRawLong(); - } - - - @Override - public boolean encodesJavaPrimitive() - { - return true; - } - } - - private class SmallLongEncoding extends FixedSizePrimitiveTypeEncoding<Long> implements LongEncoding - { - public SmallLongEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.SMALLLONG; - } - - @Override - protected int getFixedSize() - { - return 1; - } - - public void write(final long l) - { - writeConstructor(); - getEncoder().writeRaw((byte)l); - } - - public void writeValue(final long l) - { - getEncoder().writeRaw((byte)l); - } - - public long readPrimitiveValue() - { - return (long) getDecoder().readRawByte(); - } - - public LongType getType() - { - return LongType.this; - } - - public void writeValue(final Long val) - { - getEncoder().writeRaw((byte)val.longValue()); - } - - public boolean encodesSuperset(final TypeEncoding<Long> encoder) - { - return encoder == this; - } - - public Long readValue() - { - return readPrimitiveValue(); - } - - - @Override - public boolean encodesJavaPrimitive() - { - return true; - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/MapType.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/MapType.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/MapType.java deleted file mode 100644 index 5c8a7c7..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/MapType.java +++ /dev/null @@ -1,255 +0,0 @@ -/* - * - * 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; - -import java.util.*; - -public class MapType extends AbstractPrimitiveType<Map> -{ - private final MapEncoding _mapEncoding; - private final MapEncoding _shortMapEncoding; - private EncoderImpl _encoder; - - private static interface MapEncoding extends PrimitiveTypeEncoding<Map> - { - void setValue(Map value, int length); - } - - MapType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _encoder = encoder; - _mapEncoding = new AllMapEncoding(encoder, decoder); - _shortMapEncoding = new ShortMapEncoding(encoder, decoder); - encoder.register(Map.class, this); - decoder.register(this); - } - - public Class<Map> getTypeClass() - { - return Map.class; - } - - public MapEncoding getEncoding(final Map val) - { - - int calculatedSize = calculateSize(val, _encoder); - MapEncoding encoding = (val.size() > 127 || calculatedSize >= 254) - ? _mapEncoding - : _shortMapEncoding; - - encoding.setValue(val, calculatedSize); - return encoding; - } - - private static int calculateSize(final Map val, EncoderImpl encoder) - { - int len = 0; - Iterator<Map.Entry> iter = val.entrySet().iterator(); - - while(iter.hasNext()) - { - Map.Entry element = iter.next(); - TypeEncoding elementEncoding = encoder.getType(element.getKey()).getEncoding(element.getKey()); - len += elementEncoding.getConstructorSize()+elementEncoding.getValueSize(element.getKey()); - elementEncoding = encoder.getType(element.getValue()).getEncoding(element.getValue()); - len += elementEncoding.getConstructorSize()+elementEncoding.getValueSize(element.getValue()); - - } - return len; - } - - - public MapEncoding getCanonicalEncoding() - { - return _mapEncoding; - } - - public Collection<MapEncoding> getAllEncodings() - { - return Arrays.asList(_shortMapEncoding, _mapEncoding); - } - - private class AllMapEncoding - extends LargeFloatingSizePrimitiveTypeEncoding<Map> - implements MapEncoding - { - - private Map _value; - private int _length; - - public AllMapEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected void writeEncodedValue(final Map val) - { - getEncoder().writeRaw(2 * val.size()); - - - Iterator<Map.Entry> iter = val.entrySet().iterator(); - - while(iter.hasNext()) - { - Map.Entry element = iter.next(); - TypeEncoding elementEncoding = getEncoder().getType(element.getKey()).getEncoding(element.getKey()); - elementEncoding.writeConstructor(); - elementEncoding.writeValue(element.getKey()); - elementEncoding = getEncoder().getType(element.getValue()).getEncoding(element.getValue()); - elementEncoding.writeConstructor(); - elementEncoding.writeValue(element.getValue()); - } - } - - @Override - protected int getEncodedValueSize(final Map val) - { - return 4 + ((val == _value) ? _length : calculateSize(val, getEncoder())); - } - - - @Override - public byte getEncodingCode() - { - return EncodingCodes.MAP32; - } - - public MapType getType() - { - return MapType.this; - } - - public boolean encodesSuperset(final TypeEncoding<Map> encoding) - { - return (getType() == encoding.getType()); - } - - public Map readValue() - { - - DecoderImpl decoder = getDecoder(); - int size = decoder.readRawInt(); - // todo - limit the decoder with size - int count = decoder.readRawInt(); - if (count > decoder.getByteBufferRemaining()) { - throw new IllegalArgumentException("Map element count "+count+" is specified to be greater than the amount of data available ("+ - decoder.getByteBufferRemaining()+")"); - } - Map map = new LinkedHashMap(count); - for(int i = 0; i < count; i++) - { - Object key = decoder.readObject(); - i++; - Object value = decoder.readObject(); - map.put(key, value); - } - return map; - } - - public void setValue(final Map value, final int length) - { - _value = value; - _length = length; - } - } - - private class ShortMapEncoding - extends SmallFloatingSizePrimitiveTypeEncoding<Map> - implements MapEncoding - { - - private Map _value; - private int _length; - - public ShortMapEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected void writeEncodedValue(final Map val) - { - getEncoder().writeRaw((byte)(2*val.size())); - - - Iterator<Map.Entry> iter = val.entrySet().iterator(); - - while(iter.hasNext()) - { - Map.Entry element = iter.next(); - TypeEncoding elementEncoding = getEncoder().getType(element.getKey()).getEncoding(element.getKey()); - elementEncoding.writeConstructor(); - elementEncoding.writeValue(element.getKey()); - elementEncoding = getEncoder().getType(element.getValue()).getEncoding(element.getValue()); - elementEncoding.writeConstructor(); - elementEncoding.writeValue(element.getValue()); - } - } - - @Override - protected int getEncodedValueSize(final Map val) - { - return 1 + ((val == _value) ? _length : calculateSize(val, getEncoder())); - } - - - @Override - public byte getEncodingCode() - { - return EncodingCodes.MAP8; - } - - public MapType getType() - { - return MapType.this; - } - - public boolean encodesSuperset(final TypeEncoding<Map> encoder) - { - return encoder == this; - } - - public Map readValue() - { - DecoderImpl decoder = getDecoder(); - int size = ((int)decoder.readRawByte()) & 0xff; - // todo - limit the decoder with size - int count = ((int)decoder.readRawByte()) & 0xff; - - Map map = new LinkedHashMap(count); - for(int i = 0; i < count; i++) - { - Object key = decoder.readObject(); - i++; - Object value = decoder.readObject(); - map.put(key, value); - } - return map; - } - - public void setValue(final Map value, final int length) - { - _value = value; - _length = length; - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/NullType.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/NullType.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/NullType.java deleted file mode 100644 index 5449f9b..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/NullType.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * - * 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; - -import java.util.Collection; -import java.util.Collections; - -public final class NullType extends AbstractPrimitiveType<Void> -{ - private NullEncoding _nullEncoding; - - NullType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _nullEncoding = new NullEncoding(encoder, decoder); - encoder.register(Void.class, this); - decoder.register(this); - } - - public Class<Void> getTypeClass() - { - return Void.class; - } - - public NullEncoding getEncoding(final Void val) - { - return _nullEncoding; - } - - - public NullEncoding getCanonicalEncoding() - { - return _nullEncoding; - } - - public Collection<NullEncoding> getAllEncodings() - { - return Collections.singleton(_nullEncoding); - } - - public void write() - { - _nullEncoding.write(); - } - - private class NullEncoding extends FixedSizePrimitiveTypeEncoding<Void> - { - - public NullEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 0; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.NULL; - } - - public NullType getType() - { - return NullType.this; - } - - public void writeValue(final Void val) - { - } - - public void writeValue() - { - } - - public boolean encodesSuperset(final TypeEncoding<Void> encoding) - { - return encoding == this; - } - - public Void readValue() - { - return null; - } - - public void write() - { - writeConstructor(); - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/PrimitiveType.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/PrimitiveType.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/PrimitiveType.java deleted file mode 100644 index 25fb9c6..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/PrimitiveType.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * - * 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; - -import java.util.Collection; - -public interface PrimitiveType<V> extends AMQPType<V> -{ - - PrimitiveTypeEncoding<V> getEncoding(V val); - - PrimitiveTypeEncoding<V> getCanonicalEncoding(); - - Collection<? extends PrimitiveTypeEncoding<V>> getAllEncodings(); - - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/PrimitiveTypeEncoding.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/PrimitiveTypeEncoding.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/PrimitiveTypeEncoding.java deleted file mode 100644 index ee0e04a..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/PrimitiveTypeEncoding.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * - * 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; - -public interface PrimitiveTypeEncoding<T> extends TypeEncoding<T>, TypeConstructor<T> -{ - PrimitiveType<T> getType(); - - byte getEncodingCode(); - - void writeConstructor(); - - int getConstructorSize(); -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/ReadableBuffer.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/ReadableBuffer.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/ReadableBuffer.java deleted file mode 100644 index 1360d76..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/ReadableBuffer.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * 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; - -import java.nio.ByteBuffer; -import java.nio.CharBuffer; -import java.nio.charset.Charset; - -/** - * Interface to abstract a buffer, similar to {@link WritableBuffer} - */ -public interface ReadableBuffer { - - void put(ReadableBuffer other); - - byte get(); - - int getInt(); - - long getLong(); - - short getShort(); - - float getFloat(); - - double getDouble(); - - ReadableBuffer get(final byte[] data, final int offset, final int length); - - ReadableBuffer get(final byte[] data); - - ReadableBuffer position(int position); - - ReadableBuffer slice(); - - ReadableBuffer flip(); - - ReadableBuffer limit(int limit); - - int limit(); - - int remaining(); - - int position(); - - boolean hasRemaining(); - - ReadableBuffer duplicate(); - - ByteBuffer byteBuffer(); - - String readUTF8(); - - final class ByteBufferReader implements ReadableBuffer { - - private static final Charset Charset_UTF8 = Charset.forName("UTF-8"); - - private ByteBuffer buffer; - - public static ByteBufferReader allocate(int size) { - ByteBuffer allocated = ByteBuffer.allocate(size); - return new ByteBufferReader(allocated); - } - - public ByteBufferReader(ByteBuffer buffer) { - this.buffer = buffer; - } - - @Override - public byte get() { - return buffer.get(); - } - - @Override - public int getInt() { - return buffer.getInt(); - } - - @Override - public long getLong() { - return buffer.getLong(); - } - - @Override - public short getShort() { - return buffer.getShort(); - } - - @Override - public float getFloat() { - return buffer.getFloat(); - } - - @Override - public double getDouble() { - return buffer.getDouble(); - } - - @Override - public int limit() { - return buffer.limit(); - } - - @Override - public ReadableBuffer get(byte[] data, int offset, int length) { - buffer.get(data, offset, length); - return this; - } - - @Override - public ReadableBuffer get(byte[] data) { - buffer.get(data); - return this; - } - - @Override - public ReadableBuffer flip() { - buffer.flip(); - return this; - } - - @Override - public ReadableBuffer position(int position) { - buffer.position(position); - return this; - } - - @Override - public ReadableBuffer slice() { - return new ByteBufferReader(buffer.slice()); - } - - @Override - public ReadableBuffer limit(int limit) { - buffer.limit(limit); - return this; - } - - @Override - public int remaining() { - return buffer.remaining(); - } - - @Override - public int position() { - return buffer.position(); - } - - @Override - public boolean hasRemaining() { - return buffer.hasRemaining(); - } - - @Override - public ReadableBuffer duplicate() { - return new ByteBufferReader(buffer.duplicate()); - } - - @Override - public ByteBuffer byteBuffer() { - return buffer; - } - - @Override - public String readUTF8() { - CharBuffer charBuf = Charset_UTF8.decode(buffer); - return charBuf.toString(); - } - - @Override - public void put(ReadableBuffer other) { - this.buffer.put(other.byteBuffer()); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/ShortType.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/ShortType.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/ShortType.java deleted file mode 100644 index 7dfe035..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/ShortType.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * - * 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; - -import java.util.Collection; -import java.util.Collections; - -public class ShortType extends AbstractPrimitiveType<Short> -{ - private ShortEncoding _shortEncoding; - - ShortType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _shortEncoding = new ShortEncoding(encoder, decoder); - encoder.register(Short.class, this); - decoder.register(this); - } - - public Class<Short> getTypeClass() - { - return Short.class; - } - - public ShortEncoding getEncoding(final Short val) - { - return _shortEncoding; - } - - public void write(short s) - { - _shortEncoding.write(s); - } - - public ShortEncoding getCanonicalEncoding() - { - return _shortEncoding; - } - - public Collection<ShortEncoding> getAllEncodings() - { - return Collections.singleton(_shortEncoding); - } - - public class ShortEncoding extends FixedSizePrimitiveTypeEncoding<Short> - { - - public ShortEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 2; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.SHORT; - } - - public ShortType getType() - { - return ShortType.this; - } - - public void writeValue(final Short val) - { - getEncoder().writeRaw(val); - } - - public void writeValue(final short val) - { - getEncoder().writeRaw(val); - } - - - public void write(final short s) - { - writeConstructor(); - getEncoder().writeRaw(s); - } - - public boolean encodesSuperset(final TypeEncoding<Short> encoding) - { - return (getType() == encoding.getType()); - } - - public Short readValue() - { - return readPrimitiveValue(); - } - - public short readPrimitiveValue() - { - return getDecoder().readRawShort(); - } - - - @Override - public boolean encodesJavaPrimitive() - { - return true; - } - - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/SmallFloatingSizePrimitiveTypeEncoding.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/SmallFloatingSizePrimitiveTypeEncoding.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/SmallFloatingSizePrimitiveTypeEncoding.java deleted file mode 100644 index 75e405a..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/SmallFloatingSizePrimitiveTypeEncoding.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * - * 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; - -abstract class SmallFloatingSizePrimitiveTypeEncoding<T> extends FloatingSizePrimitiveTypeEncoding<T> -{ - - SmallFloatingSizePrimitiveTypeEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - public int getSizeBytes() - { - return 1; - } - - @Override - protected void writeSize(final T val) - { - getEncoder().writeRaw((byte)getEncodedValueSize(val)); - } -} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
