http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/AbstractPrimitiveType.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/AbstractPrimitiveType.java b/proton-j/codec/src/org/apache/qpid/proton/codec/AbstractPrimitiveType.java deleted file mode 100644 index 9a8c9c4..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/AbstractPrimitiveType.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; - -abstract class AbstractPrimitiveType<T> implements PrimitiveType<T> -{ - public final void write(T val) - { - final TypeEncoding<T> encoding = getEncoding(val); - encoding.writeConstructor(); - encoding.writeValue(val); - } - -}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/AbstractPrimitiveTypeEncoding.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/AbstractPrimitiveTypeEncoding.java b/proton-j/codec/src/org/apache/qpid/proton/codec/AbstractPrimitiveTypeEncoding.java deleted file mode 100644 index 56079ee..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/AbstractPrimitiveTypeEncoding.java +++ /dev/null @@ -1,67 +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 AbstractPrimitiveTypeEncoding<T> implements PrimitiveTypeEncoding<T> -{ - private final EncoderImpl _encoder; - private final DecoderImpl _decoder; - - AbstractPrimitiveTypeEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - _encoder = encoder; - _decoder = decoder; - } - - public final void writeConstructor() - { - _encoder.writeRaw(getEncodingCode()); - } - - public int getConstructorSize() - { - return 1; - } - - public abstract byte getEncodingCode(); - - protected EncoderImpl getEncoder() - { - return _encoder; - } - - public Class<T> getTypeClass() - { - return getType().getTypeClass(); - } - - protected DecoderImpl getDecoder() - { - return _decoder; - } - - - public boolean encodesJavaPrimitive() - { - return false; - } - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/ArrayType.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/ArrayType.java b/proton-j/codec/src/org/apache/qpid/proton/codec/ArrayType.java deleted file mode 100644 index 11a1dc9..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/ArrayType.java +++ /dev/null @@ -1,1139 +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.lang.reflect.Array; -import java.util.Arrays; -import java.util.Collection; - -public class ArrayType implements PrimitiveType<Object[]> -{ - private final EncoderImpl _encoder; - private final BooleanType _booleanType; - private final ByteType _byteType; - private final ShortType _shortType; - private final IntegerType _integerType; - private final LongType _longType; - private final FloatType _floatType; - private final DoubleType _doubleType; - private final CharacterType _characterType; - - public static interface ArrayEncoding extends PrimitiveTypeEncoding<Object[]> - { - void writeValue(boolean[] a); - void writeValue(byte[] a); - void writeValue(short[] a); - void writeValue(int[] a); - void writeValue(long[] a); - void writeValue(float[] a); - void writeValue(double[] a); - void writeValue(char[] a); - - void setValue(Object[] val, TypeEncoding encoder, int size); - - int getSizeBytes(); - - Object readValueArray(); - } - - private final ArrayEncoding _shortArrayEncoding; - private final ArrayEncoding _arrayEncoding; - - public ArrayType(EncoderImpl encoder, - final DecoderImpl decoder, BooleanType boolType, - ByteType byteType, - ShortType shortType, - IntegerType intType, - LongType longType, - FloatType floatType, - DoubleType doubleType, - CharacterType characterType) - { - _encoder = encoder; - _booleanType = boolType; - _byteType = byteType; - _shortType = shortType; - _integerType = intType; - _longType = longType; - _floatType = floatType; - _doubleType = doubleType; - _characterType = characterType; - - _arrayEncoding = new AllArrayEncoding(encoder, decoder); - _shortArrayEncoding = new ShortArrayEncoding(encoder, decoder); - - encoder.register(Object[].class, this); - decoder.register(this); - } - - public Class<Object[]> getTypeClass() - { - return Object[].class; - } - - public ArrayEncoding getEncoding(final Object[] val) - { - TypeEncoding encoder = calculateEncoder(val,_encoder); - int size = calculateSize(val, encoder); - ArrayEncoding arrayEncoding = (val.length > 255 || size > 254) - ? _arrayEncoding - : _shortArrayEncoding; - arrayEncoding.setValue(val, encoder, size); - return arrayEncoding; - } - - private static TypeEncoding calculateEncoder(final Object[] val, final EncoderImpl encoder) - { - - if(val.length == 0) - { - AMQPType underlyingType = encoder.getTypeFromClass(val.getClass().getComponentType()); - return underlyingType.getCanonicalEncoding(); - } - else - { - AMQPType underlyingType = encoder.getTypeFromClass(val.getClass().getComponentType()); - boolean checkTypes = false; - - if(val[0].getClass().isArray() && val[0].getClass().getComponentType().isPrimitive()) - { - Class componentType = val[0].getClass().getComponentType(); - if(componentType == Boolean.TYPE) - { - return ((ArrayType)underlyingType).getEncoding((boolean[])val[0]); - } - else if(componentType == Byte.TYPE) - { - return ((ArrayType)underlyingType).getEncoding((byte[])val[0]); - } - else if(componentType == Short.TYPE) - { - return ((ArrayType)underlyingType).getEncoding((short[])val[0]); - } - else if(componentType == Integer.TYPE) - { - return ((ArrayType)underlyingType).getEncoding((int[])val[0]); - } - else if(componentType == Long.TYPE) - { - return ((ArrayType)underlyingType).getEncoding((long[])val[0]); - } - else if(componentType == Float.TYPE) - { - return ((ArrayType)underlyingType).getEncoding((float[])val[0]); - } - else if(componentType == Double.TYPE) - { - return ((ArrayType)underlyingType).getEncoding((double[])val[0]); - } - else if(componentType == Character.TYPE) - { - return ((ArrayType)underlyingType).getEncoding((char[])val[0]); - } - else - { - throw new IllegalArgumentException("Cannot encode arrays of type " + componentType.getName()); - } - } - else - { - - if(underlyingType == null) - { - checkTypes = true; - underlyingType = encoder.getType(val[0]); - } - TypeEncoding underlyingEncoding = underlyingType.getEncoding(val[0]); - TypeEncoding canonicalEncoding = underlyingType.getCanonicalEncoding(); - - for(int i = 0; i < val.length && (checkTypes || underlyingEncoding != canonicalEncoding); i++) - { - if(checkTypes && encoder.getType(val[i]) != underlyingType) - { - throw new IllegalArgumentException("Non matching types " + underlyingType + " and " + encoder - .getType(val[i]) + " in array"); - } - - - TypeEncoding elementEncoding = underlyingType.getEncoding(val[i]); - if(elementEncoding != underlyingEncoding && !underlyingEncoding.encodesSuperset(elementEncoding)) - { - if(elementEncoding.encodesSuperset(underlyingEncoding)) - { - underlyingEncoding = elementEncoding; - } - else - { - underlyingEncoding = canonicalEncoding; - } - } - - } - - return underlyingEncoding; - } - } - } - - private static int calculateSize(final Object[] val, final TypeEncoding encoder) - { - int size = encoder.getConstructorSize(); - if(encoder.isFixedSizeVal()) - { - size += val.length * encoder.getValueSize(null); - } - else - { - for(Object o : val) - { - if(o.getClass().isArray() && o.getClass().getComponentType().isPrimitive()) - { - ArrayEncoding arrayEncoding = (ArrayEncoding) encoder; - ArrayType arrayType = (ArrayType) arrayEncoding.getType(); - - Class componentType = o.getClass().getComponentType(); - - size += 2 * arrayEncoding.getSizeBytes(); - - TypeEncoding componentEncoding; - int componentCount; - - if(componentType == Boolean.TYPE) - { - boolean[] componentArray = (boolean[]) o; - componentEncoding = arrayType.getUnderlyingEncoding(componentArray); - componentCount = componentArray.length; - } - else if(componentType == Byte.TYPE) - { - byte[] componentArray = (byte[]) o; - componentEncoding = arrayType.getUnderlyingEncoding(componentArray); - componentCount = componentArray.length; - } - else if(componentType == Short.TYPE) - { - short[] componentArray = (short[]) o; - componentEncoding = arrayType.getUnderlyingEncoding(componentArray); - componentCount = componentArray.length; - } - else if(componentType == Integer.TYPE) - { - int[] componentArray = (int[]) o; - componentEncoding = arrayType.getUnderlyingEncoding(componentArray); - componentCount = componentArray.length; - } - else if(componentType == Long.TYPE) - { - long[] componentArray = (long[]) o; - componentEncoding = arrayType.getUnderlyingEncoding(componentArray); - componentCount = componentArray.length; - } - else if(componentType == Float.TYPE) - { - float[] componentArray = (float[]) o; - componentEncoding = arrayType.getUnderlyingEncoding(componentArray); - componentCount = componentArray.length; - } - else if(componentType == Double.TYPE) - { - double[] componentArray = (double[]) o; - componentEncoding = arrayType.getUnderlyingEncoding(componentArray); - componentCount = componentArray.length; - } - else if(componentType == Character.TYPE) - { - char[] componentArray = (char[]) o; - componentEncoding = arrayType.getUnderlyingEncoding(componentArray); - componentCount = componentArray.length; - } - else - { - throw new IllegalArgumentException("Cannot encode arrays of type " + componentType.getName()); - } - - size += componentEncoding.getConstructorSize() - + componentEncoding.getValueSize(null) * componentCount; - - } - else - { - size += encoder.getValueSize(o); - } - } - } - - return size; - } - - public ArrayEncoding getCanonicalEncoding() - { - return _arrayEncoding; - } - - public Collection<ArrayEncoding> getAllEncodings() - { - return Arrays.asList(_shortArrayEncoding, _arrayEncoding); - } - - public void write(final Object[] val) - { - ArrayEncoding encoding = getEncoding(val); - encoding.writeConstructor(); - encoding.writeValue(val); - } - - public void write(boolean[] a) - { - ArrayEncoding encoding = getEncoding(a); - encoding.writeConstructor(); - encoding.writeValue(a); - } - - private ArrayEncoding getEncoding(final boolean[] a) - { - return a.length < 254 || a.length <= 255 && allSameValue(a) ? _shortArrayEncoding : _arrayEncoding; - } - - private boolean allSameValue(final boolean[] a) - { - boolean val = a[0]; - for(int i = 1; i < a.length; i++) - { - if(val != a[i]) - { - return false; - } - } - return true; - } - - public void write(byte[] a) - { - ArrayEncoding encoding = getEncoding(a); - encoding.writeConstructor(); - encoding.writeValue(a); - } - - private ArrayEncoding getEncoding(final byte[] a) - { - return a.length < 254 ? _shortArrayEncoding : _arrayEncoding; - } - - public void write(short[] a) - { - ArrayEncoding encoding = getEncoding(a); - encoding.writeConstructor(); - encoding.writeValue(a); - } - - private ArrayEncoding getEncoding(final short[] a) - { - return a.length < 127 ? _shortArrayEncoding : _arrayEncoding; - } - - public void write(int[] a) - { - ArrayEncoding encoding = getEncoding(a); - encoding.writeConstructor(); - encoding.writeValue(a); - } - - private ArrayEncoding getEncoding(final int[] a) - { - return a.length < 63 || (a.length < 254 && allSmallInts(a)) ? _shortArrayEncoding : _arrayEncoding; - } - - private boolean allSmallInts(final int[] a) - { - for(int i = 0; i < a.length; i++) - { - if(a[i] < -128 || a[i] > 127) - { - return false; - } - } - return true; - } - - public void write(long[] a) - { - ArrayEncoding encoding = getEncoding(a); - encoding.writeConstructor(); - encoding.writeValue(a); - } - - private ArrayEncoding getEncoding(final long[] a) - { - return a.length < 31 || (a.length < 254 && allSmallLongs(a)) ? _shortArrayEncoding : _arrayEncoding; - } - - private boolean allSmallLongs(final long[] a) - { - for(int i = 0; i < a.length; i++) - { - if(a[i] < -128L || a[i] > 127L) - { - return false; - } - } - return true; - } - - public void write(float[] a) - { - ArrayEncoding encoding = getEncoding(a); - encoding.writeConstructor(); - encoding.writeValue(a); - } - - private ArrayEncoding getEncoding(final float[] a) - { - return a.length < 63 ? _shortArrayEncoding : _arrayEncoding; - } - - public void write(double[] a) - { - ArrayEncoding encoding = getEncoding(a); - encoding.writeConstructor(); - encoding.writeValue(a); - } - - private ArrayEncoding getEncoding(final double[] a) - { - return a.length < 31 ? _shortArrayEncoding : _arrayEncoding; - } - - public void write(char[] a) - { - ArrayEncoding encoding = getEncoding(a); - encoding.writeConstructor(); - encoding.writeValue(a); - } - - private ArrayEncoding getEncoding(final char[] a) - { - return a.length < 63 ? _shortArrayEncoding : _arrayEncoding; - } - - private class AllArrayEncoding - extends LargeFloatingSizePrimitiveTypeEncoding<Object[]> - implements ArrayEncoding - { - - private Object[] _val; - private TypeEncoding _underlyingEncoder; - private int _size; - - AllArrayEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - public void writeValue(final boolean[] a) - { - BooleanType.BooleanEncoding underlyingEncoder = getUnderlyingEncoding(a); - getEncoder().writeRaw(4 + underlyingEncoder.getConstructorSize() - + a.length*underlyingEncoder.getValueSize(null)); - getEncoder().writeRaw(a.length); - underlyingEncoder.writeConstructor(); - for(boolean b : a) - { - underlyingEncoder.writeValue(b); - } - - } - - public void writeValue(final byte[] a) - { - ByteType.ByteEncoding underlyingEncoder = getUnderlyingEncoding(a); - getEncoder().writeRaw(4 + underlyingEncoder.getConstructorSize() - + a.length*underlyingEncoder.getValueSize(null)); - getEncoder().writeRaw(a.length); - underlyingEncoder.writeConstructor(); - for(byte b : a) - { - underlyingEncoder.writeValue(b); - } - } - - public void writeValue(final short[] a) - { - ShortType.ShortEncoding underlyingEncoder = getUnderlyingEncoding(a); - getEncoder().writeRaw(4 + underlyingEncoder.getConstructorSize() - + a.length*underlyingEncoder.getValueSize(null)); - getEncoder().writeRaw(a.length); - underlyingEncoder.writeConstructor(); - for(short b : a) - { - underlyingEncoder.writeValue(b); - } - } - - public void writeValue(final int[] a) - { - - IntegerType.IntegerEncoding underlyingEncoder = getUnderlyingEncoding(a); - getEncoder().writeRaw(4 + underlyingEncoder.getConstructorSize() - + a.length*underlyingEncoder.getValueSize(null)); - getEncoder().writeRaw(a.length); - underlyingEncoder.writeConstructor(); - for(int b : a) - { - underlyingEncoder.writeValue(b); - } - } - - public void writeValue(final long[] a) - { - - LongType.LongEncoding underlyingEncoder = getUnderlyingEncoding(a); - getEncoder().writeRaw(4 + underlyingEncoder.getConstructorSize() - + a.length*underlyingEncoder.getValueSize(null)); - getEncoder().writeRaw(a.length); - underlyingEncoder.writeConstructor(); - for(long b : a) - { - underlyingEncoder.writeValue(b); - } - } - - public void writeValue(final float[] a) - { - - FloatType.FloatEncoding underlyingEncoder = getUnderlyingEncoding(a); - getEncoder().writeRaw(4 + underlyingEncoder.getConstructorSize() - + a.length*underlyingEncoder.getValueSize(null)); - getEncoder().writeRaw(a.length); - underlyingEncoder.writeConstructor(); - for(float b : a) - { - underlyingEncoder.writeValue(b); - } - } - - public void writeValue(final double[] a) - { - - DoubleType.DoubleEncoding underlyingEncoder = getUnderlyingEncoding(a); - getEncoder().writeRaw(4 + underlyingEncoder.getConstructorSize() - + a.length*underlyingEncoder.getValueSize(null)); - getEncoder().writeRaw(a.length); - underlyingEncoder.writeConstructor(); - for(double b : a) - { - underlyingEncoder.writeValue(b); - } - } - - public void writeValue(final char[] a) - { - - CharacterType.CharacterEncoding underlyingEncoder = getUnderlyingEncoding(a); - getEncoder().writeRaw(4 + underlyingEncoder.getConstructorSize() - + a.length*underlyingEncoder.getValueSize(null)); - getEncoder().writeRaw(a.length); - underlyingEncoder.writeConstructor(); - for(char b : a) - { - underlyingEncoder.writeValue(b); - } - } - - public void setValue(final Object[] val, final TypeEncoding encoder, final int size) - { - _val = val; - _underlyingEncoder = encoder; - _size = size; - } - - @Override - protected void writeEncodedValue(final Object[] val) - { - TypeEncoding underlyingEncoder; - - if(_val != val) - { - _val = val; - _underlyingEncoder = underlyingEncoder = calculateEncoder(val, getEncoder()); - _size = calculateSize(val, underlyingEncoder); - } - else - { - underlyingEncoder = _underlyingEncoder; - } - getEncoder().writeRaw(val.length); - underlyingEncoder.writeConstructor(); - for(Object o : val) - { - underlyingEncoder.writeValue(o); - } - } - - @Override - protected int getEncodedValueSize(final Object[] val) - { - if(_val != val) - { - _val = val; - _underlyingEncoder = calculateEncoder(val, getEncoder()); - _size = calculateSize(val, _underlyingEncoder); - } - return 4 + _size; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.ARRAY32; - } - - public ArrayType getType() - { - return ArrayType.this; - } - - public boolean encodesSuperset(final TypeEncoding<Object[]> encoding) - { - return getType() == encoding.getType(); - } - - public Object[] readValue() - { - DecoderImpl decoder = getDecoder(); - int size = decoder.readRawInt(); - int count = decoder.readRawInt(); - return decodeArray(decoder, count); - } - - public Object readValueArray() - { - DecoderImpl decoder = getDecoder(); - int size = decoder.readRawInt(); - int count = decoder.readRawInt(); - return decodeArrayAsObject(decoder, count); - } - - - - } - - - - private class ShortArrayEncoding - extends SmallFloatingSizePrimitiveTypeEncoding<Object[]> - implements ArrayEncoding - { - - private Object[] _val; - private TypeEncoding _underlyingEncoder; - private int _size; - - ShortArrayEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - public void writeValue(final boolean[] a) - { - BooleanType.BooleanEncoding underlyingEncoder = getUnderlyingEncoding(a); - getEncoder().writeRaw((byte)(1 + underlyingEncoder.getConstructorSize() - + a.length*underlyingEncoder.getValueSize(null))); - getEncoder().writeRaw((byte)a.length); - underlyingEncoder.writeConstructor(); - for(boolean b : a) - { - underlyingEncoder.writeValue(b); - } - - } - - public void writeValue(final byte[] a) - { - ByteType.ByteEncoding underlyingEncoder = getUnderlyingEncoding(a); - getEncoder().writeRaw((byte)(1 + underlyingEncoder.getConstructorSize() - + a.length*underlyingEncoder.getValueSize(null))); - getEncoder().writeRaw((byte)a.length); - underlyingEncoder.writeConstructor(); - for(byte b : a) - { - underlyingEncoder.writeValue(b); - } - } - - public void writeValue(final short[] a) - { - ShortType.ShortEncoding underlyingEncoder = getUnderlyingEncoding(a); - getEncoder().writeRaw((byte)(1 + underlyingEncoder.getConstructorSize() - + a.length*underlyingEncoder.getValueSize(null))); - getEncoder().writeRaw((byte)a.length); - underlyingEncoder.writeConstructor(); - for(short b : a) - { - underlyingEncoder.writeValue(b); - } - } - - public void writeValue(final int[] a) - { - - IntegerType.IntegerEncoding underlyingEncoder = getUnderlyingEncoding(a); - getEncoder().writeRaw((byte)(1 + underlyingEncoder.getConstructorSize() - + a.length*underlyingEncoder.getValueSize(null))); - getEncoder().writeRaw((byte)a.length); - underlyingEncoder.writeConstructor(); - for(int b : a) - { - underlyingEncoder.writeValue(b); - } - } - - public void writeValue(final long[] a) - { - - LongType.LongEncoding underlyingEncoder = getUnderlyingEncoding(a); - getEncoder().writeRaw((byte)(1 + underlyingEncoder.getConstructorSize() - + a.length*underlyingEncoder.getValueSize(null))); - getEncoder().writeRaw((byte)a.length); - underlyingEncoder.writeConstructor(); - for(long b : a) - { - underlyingEncoder.writeValue(b); - } - } - - public void writeValue(final float[] a) - { - - FloatType.FloatEncoding underlyingEncoder = getUnderlyingEncoding(a); - getEncoder().writeRaw((byte)(1 + underlyingEncoder.getConstructorSize() - + a.length*underlyingEncoder.getValueSize(null))); - getEncoder().writeRaw((byte)a.length); - underlyingEncoder.writeConstructor(); - for(float b : a) - { - underlyingEncoder.writeValue(b); - } - } - - public void writeValue(final double[] a) - { - - DoubleType.DoubleEncoding underlyingEncoder = getUnderlyingEncoding(a); - getEncoder().writeRaw((byte)(1 + underlyingEncoder.getConstructorSize() - + a.length*underlyingEncoder.getValueSize(null))); - getEncoder().writeRaw((byte)a.length); - underlyingEncoder.writeConstructor(); - for(double b : a) - { - underlyingEncoder.writeValue(b); - } - } - - public void writeValue(final char[] a) - { - - CharacterType.CharacterEncoding underlyingEncoder = getUnderlyingEncoding(a); - getEncoder().writeRaw((byte)(1 + underlyingEncoder.getConstructorSize() - + a.length*underlyingEncoder.getValueSize(null))); - getEncoder().writeRaw((byte)a.length); - underlyingEncoder.writeConstructor(); - for(char b : a) - { - underlyingEncoder.writeValue(b); - } - } - - public void setValue(final Object[] val, final TypeEncoding encoder, final int size) - { - _val = val; - _underlyingEncoder = encoder; - _size = size; - } - - @Override - protected void writeEncodedValue(final Object[] val) - { - TypeEncoding underlyingEncoder; - - if(_val != val) - { - _val = val; - _underlyingEncoder = underlyingEncoder = calculateEncoder(val, getEncoder()); - _size = calculateSize(val, underlyingEncoder); - } - else - { - underlyingEncoder = _underlyingEncoder; - } - getEncoder().writeRaw((byte)val.length); - underlyingEncoder.writeConstructor(); - for(Object o : val) - { - if(o.getClass().isArray() && o.getClass().getComponentType().isPrimitive()) - { - ArrayEncoding arrayEncoding = (ArrayEncoding) underlyingEncoder; - ArrayType arrayType = (ArrayType) arrayEncoding.getType(); - - Class componentType = o.getClass().getComponentType(); - - if(componentType == Boolean.TYPE) - { - boolean[] componentArray = (boolean[]) o; - arrayEncoding.writeValue(componentArray); - } - else if(componentType == Byte.TYPE) - { - byte[] componentArray = (byte[]) o; - arrayEncoding.writeValue(componentArray); - } - else if(componentType == Short.TYPE) - { - short[] componentArray = (short[]) o; - arrayEncoding.writeValue(componentArray); - } - else if(componentType == Integer.TYPE) - { - int[] componentArray = (int[]) o; - arrayEncoding.writeValue(componentArray); - } - else if(componentType == Long.TYPE) - { - long[] componentArray = (long[]) o; - arrayEncoding.writeValue(componentArray); - } - else if(componentType == Float.TYPE) - { - float[] componentArray = (float[]) o; - arrayEncoding.writeValue(componentArray); - } - else if(componentType == Double.TYPE) - { - double[] componentArray = (double[]) o; - arrayEncoding.writeValue(componentArray); - } - else if(componentType == Character.TYPE) - { - char[] componentArray = (char[]) o; - arrayEncoding.writeValue(componentArray); - } - else - { - throw new IllegalArgumentException("Cannot encode arrays of type " + componentType.getName()); - } - - } - else - { - underlyingEncoder.writeValue(o); - } - } - } - - @Override - protected int getEncodedValueSize(final Object[] val) - { - if(_val != val) - { - _val = val; - _underlyingEncoder = calculateEncoder(val, getEncoder()); - _size = calculateSize(val, _underlyingEncoder); - } - return 1 + _size; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.ARRAY8; - } - - public ArrayType getType() - { - return ArrayType.this; - } - - public boolean encodesSuperset(final TypeEncoding<Object[]> encoding) - { - return getType() == encoding.getType(); - } - - public Object[] readValue() - { - DecoderImpl decoder = getDecoder(); - int size = ((int)decoder.readRawByte()) & 0xFF; - int count = ((int)decoder.readRawByte()) & 0xFF; - return decodeArray(decoder, count); - } - - public Object readValueArray() - { - DecoderImpl decoder = getDecoder(); - int size = ((int)decoder.readRawByte()) & 0xFF; - int count = ((int)decoder.readRawByte()) & 0xFF; - return decodeArrayAsObject(decoder, count); - } - - } - - private BooleanType.BooleanEncoding getUnderlyingEncoding(final boolean[] a) - { - if(a.length == 0) - { - return _booleanType.getCanonicalEncoding(); - } - else - { - boolean val = a[0]; - for(int i = 1; i < a.length; i++) - { - if(val != a[i]) - { - return _booleanType.getCanonicalEncoding(); - } - } - return _booleanType.getEncoding(val); - } - } - - - private ByteType.ByteEncoding getUnderlyingEncoding(final byte[] a) - { - return _byteType.getCanonicalEncoding(); - } - - - private ShortType.ShortEncoding getUnderlyingEncoding(final short[] a) - { - return _shortType.getCanonicalEncoding(); - } - - private IntegerType.IntegerEncoding getUnderlyingEncoding(final int[] a) - { - if(a.length == 0 || !allSmallInts(a)) - { - return _integerType.getCanonicalEncoding(); - } - else - { - return _integerType.getEncoding(a[0]); - } - } - - private LongType.LongEncoding getUnderlyingEncoding(final long[] a) - { - if(a.length == 0 || !allSmallLongs(a)) - { - return _longType.getCanonicalEncoding(); - } - else - { - return _longType.getEncoding(a[0]); - } - } - - - private FloatType.FloatEncoding getUnderlyingEncoding(final float[] a) - { - return _floatType.getCanonicalEncoding(); - } - - - private DoubleType.DoubleEncoding getUnderlyingEncoding(final double[] a) - { - return _doubleType.getCanonicalEncoding(); - } - - - private CharacterType.CharacterEncoding getUnderlyingEncoding(final char[] a) - { - return _characterType.getCanonicalEncoding(); - } - - private static Object[] decodeArray(final DecoderImpl decoder, final int count) - { - TypeConstructor constructor = decoder.readConstructor(); - return decodeNonPrimitive(constructor, count); - } - - private static Object[] decodeNonPrimitive(final TypeConstructor constructor, - final int count) - { - if(constructor instanceof ArrayEncoding) - { - ArrayEncoding arrayEncoding = (ArrayEncoding) constructor; - - Object[] array = new Object[count]; - for(int i = 0; i < count; i++) - { - array[i] = arrayEncoding.readValueArray(); - } - - return array; - } - else - { - Object[] array = (Object[]) Array.newInstance(constructor.getTypeClass(), count); - - for(int i = 0; i < count; i++) - { - array[i] = constructor.readValue(); - } - - return array; - } - } - - private static Object decodeArrayAsObject(final DecoderImpl decoder, final int count) - { - TypeConstructor constructor = decoder.readConstructor(); - if(constructor.encodesJavaPrimitive()) - { - if(constructor instanceof BooleanType.BooleanEncoding) - { - return decodeBooleanArray((BooleanType.BooleanEncoding) constructor, count); - } - else if(constructor instanceof ByteType.ByteEncoding) - { - return decodeByteArray((ByteType.ByteEncoding)constructor, count); - } - else if(constructor instanceof ShortType.ShortEncoding) - { - return decodeShortArray((ShortType.ShortEncoding)constructor, count); - } - else if(constructor instanceof IntegerType.IntegerEncoding) - { - return decodeIntArray((IntegerType.IntegerEncoding)constructor, count); - } - else if(constructor instanceof LongType.LongEncoding) - { - return decodeLongArray((LongType.LongEncoding) constructor, count); - } - else if(constructor instanceof FloatType.FloatEncoding) - { - return decodeFloatArray((FloatType.FloatEncoding) constructor, count); - } - else if(constructor instanceof DoubleType.DoubleEncoding) - { - return decodeDoubleArray((DoubleType.DoubleEncoding)constructor, count); - } - else - { - throw new ClassCastException("Unexpected class " + constructor.getClass().getName()); - } - - } - else - { - return decodeNonPrimitive(constructor, count); - } - - } - - private static boolean[] decodeBooleanArray(BooleanType.BooleanEncoding constructor, final int count) - { - boolean[] array = new boolean[count]; - - for(int i = 0; i < count; i++) - { - array[i] = constructor.readPrimitiveValue(); - } - - return array; - } - - private static byte[] decodeByteArray(ByteType.ByteEncoding constructor , final int count) - { - byte[] array = new byte[count]; - - for(int i = 0; i < count; i++) - { - array[i] = constructor.readPrimitiveValue(); - } - - return array; - } - - private static short[] decodeShortArray(ShortType.ShortEncoding constructor, final int count) - { - short[] array = new short[count]; - - for(int i = 0; i < count; i++) - { - array[i] = constructor.readPrimitiveValue(); - } - - return array; - } - - private static int[] decodeIntArray(IntegerType.IntegerEncoding constructor, final int count) - { - int[] array = new int[count]; - - for(int i = 0; i < count; i++) - { - array[i] = constructor.readPrimitiveValue(); - } - - return array; - } - - - private static long[] decodeLongArray(LongType.LongEncoding constructor, final int count) - { - long[] array = new long[count]; - - for(int i = 0; i < count; i++) - { - array[i] = constructor.readPrimitiveValue(); - } - - return array; - } - - private static float[] decodeFloatArray(FloatType.FloatEncoding constructor, final int count) - { - float[] array = new float[count]; - - for(int i = 0; i < count; i++) - { - array[i] = constructor.readPrimitiveValue(); - } - - return array; - } - - private static double[] decodeDoubleArray(DoubleType.DoubleEncoding constructor, final int count) - { - double[] array = new double[count]; - - for(int i = 0; i < count; i++) - { - array[i] = constructor.readPrimitiveValue(); - } - - return array; - } - - - - -} - http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/BinaryType.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/BinaryType.java b/proton-j/codec/src/org/apache/qpid/proton/codec/BinaryType.java deleted file mode 100644 index 8d969cb..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/BinaryType.java +++ /dev/null @@ -1,162 +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.type.Binary; - -import java.util.Arrays; -import java.util.Collection; - -public class BinaryType extends AbstractPrimitiveType<Binary> -{ - private final BinaryEncoding _binaryEncoding; - private final BinaryEncoding _shortBinaryEncoding; - - private static interface BinaryEncoding extends PrimitiveTypeEncoding<Binary> - { - - } - - BinaryType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _binaryEncoding = new LongBinaryEncoding(encoder, decoder); - _shortBinaryEncoding = new ShortBinaryEncoding(encoder, decoder); - encoder.register(Binary.class, this); - decoder.register(this); - } - - public Class<Binary> getTypeClass() - { - return Binary.class; - } - - public BinaryEncoding getEncoding(final Binary val) - { - return val.getLength() <= 255 ? _shortBinaryEncoding : _binaryEncoding; - } - - - public BinaryEncoding getCanonicalEncoding() - { - return _binaryEncoding; - } - - public Collection<BinaryEncoding> getAllEncodings() - { - return Arrays.asList(_shortBinaryEncoding, _binaryEncoding); - } - - private class LongBinaryEncoding - extends LargeFloatingSizePrimitiveTypeEncoding<Binary> - implements BinaryEncoding - { - - public LongBinaryEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected void writeEncodedValue(final Binary val) - { - getEncoder().writeRaw(val.getArray(), val.getArrayOffset(), val.getLength()); - } - - @Override - protected int getEncodedValueSize(final Binary val) - { - return val.getLength(); - } - - - @Override - public byte getEncodingCode() - { - return EncodingCodes.VBIN32; - } - - public BinaryType getType() - { - return BinaryType.this; - } - - public boolean encodesSuperset(final TypeEncoding<Binary> encoding) - { - return (getType() == encoding.getType()); - } - - public Binary readValue() - { - int size = getDecoder().readRawInt(); - byte[] data = new byte[size]; - getDecoder().readRaw(data, 0, size); - return new Binary(data); - } - } - - private class ShortBinaryEncoding - extends SmallFloatingSizePrimitiveTypeEncoding<Binary> - implements BinaryEncoding - { - - public ShortBinaryEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected void writeEncodedValue(final Binary val) - { - getEncoder().writeRaw(val.getArray(), val.getArrayOffset(), val.getLength()); - } - - @Override - protected int getEncodedValueSize(final Binary val) - { - return val.getLength(); - } - - - @Override - public byte getEncodingCode() - { - return EncodingCodes.VBIN8; - } - - public BinaryType getType() - { - return BinaryType.this; - } - - public boolean encodesSuperset(final TypeEncoding<Binary> encoder) - { - return encoder == this; - } - - public Binary readValue() - { - int size = ((int)getDecoder().readRawByte()) & 0xff; - byte[] data = new byte[size]; - getDecoder().readRaw(data, 0, size); - return new Binary(data); - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/BooleanType.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/BooleanType.java b/proton-j/codec/src/org/apache/qpid/proton/codec/BooleanType.java deleted file mode 100644 index d87dd19..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/BooleanType.java +++ /dev/null @@ -1,273 +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 final class BooleanType extends AbstractPrimitiveType<Boolean> -{ - - private static final byte BYTE_0 = (byte) 0; - private static final byte BYTE_1 = (byte) 1; - - private org.apache.qpid.proton.codec.BooleanType.BooleanEncoding _trueEncoder; - private org.apache.qpid.proton.codec.BooleanType.BooleanEncoding _falseEncoder; - private org.apache.qpid.proton.codec.BooleanType.BooleanEncoding _booleanEncoder; - - public static interface BooleanEncoding extends PrimitiveTypeEncoding<Boolean> - { - void write(boolean b); - void writeValue(boolean b); - - boolean readPrimitiveValue(); - } - - BooleanType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _trueEncoder = new TrueEncoding(encoder, decoder); - _falseEncoder = new FalseEncoding(encoder, decoder); - _booleanEncoder = new AllBooleanEncoding(encoder, decoder); - - encoder.register(Boolean.class, this); - decoder.register(this); - } - - public Class<Boolean> getTypeClass() - { - return Boolean.class; - } - - public BooleanEncoding getEncoding(final Boolean val) - { - return val ? _trueEncoder : _falseEncoder; - } - - public BooleanEncoding getEncoding(final boolean val) - { - return val ? _trueEncoder : _falseEncoder; - } - - public void writeValue(final boolean val) - { - getEncoding(val).write(val); - } - - - - - public BooleanEncoding getCanonicalEncoding() - { - return _booleanEncoder; - } - - public Collection<BooleanEncoding> getAllEncodings() - { - return Arrays.asList(_trueEncoder, _falseEncoder, _booleanEncoder); - } - - private class TrueEncoding extends FixedSizePrimitiveTypeEncoding<Boolean> implements BooleanEncoding - { - - public TrueEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 0; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.BOOLEAN_TRUE; - } - - public BooleanType getType() - { - return BooleanType.this; - } - - public void writeValue(final Boolean val) - { - } - - public void write(final boolean b) - { - writeConstructor(); - } - - public void writeValue(final boolean b) - { - } - - public boolean encodesSuperset(final TypeEncoding<Boolean> encoding) - { - return encoding == this; - } - - public Boolean readValue() - { - return Boolean.TRUE; - } - - public boolean readPrimitiveValue() - { - return true; - } - - @Override - public boolean encodesJavaPrimitive() - { - return true; - } - } - - - private class FalseEncoding extends FixedSizePrimitiveTypeEncoding<Boolean> implements org.apache.qpid.proton.codec.BooleanType.BooleanEncoding - { - - public FalseEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 0; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.BOOLEAN_FALSE; - } - - public BooleanType getType() - { - return BooleanType.this; - } - - public void writeValue(final Boolean val) - { - } - - public void write(final boolean b) - { - writeConstructor(); - } - - public void writeValue(final boolean b) - { - } - - public boolean readPrimitiveValue() - { - return false; - } - - public boolean encodesSuperset(final TypeEncoding<Boolean> encoding) - { - return encoding == this; - } - - public Boolean readValue() - { - return Boolean.FALSE; - } - - - @Override - public boolean encodesJavaPrimitive() - { - return true; - } - } - - private class AllBooleanEncoding extends FixedSizePrimitiveTypeEncoding<Boolean> implements BooleanEncoding - { - - public AllBooleanEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - public BooleanType getType() - { - return BooleanType.this; - } - - @Override - protected int getFixedSize() - { - return 1; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.BOOLEAN; - } - - public void writeValue(final Boolean val) - { - getEncoder().writeRaw(val ? BYTE_1 : BYTE_0); - } - - public void write(final boolean val) - { - writeConstructor(); - getEncoder().writeRaw(val ? BYTE_1 : BYTE_0); - } - - public void writeValue(final boolean b) - { - getEncoder().writeRaw(b ? BYTE_1 : BYTE_0); - } - - public boolean readPrimitiveValue() - { - - return getDecoder().readRawByte() != BYTE_0; - } - - public boolean encodesSuperset(final TypeEncoding<Boolean> encoding) - { - return (getType() == encoding.getType()); - } - - public Boolean readValue() - { - return readPrimitiveValue() ? Boolean.TRUE : Boolean.FALSE; - } - - - @Override - public boolean encodesJavaPrimitive() - { - return true; - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/ByteBufferDecoder.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/ByteBufferDecoder.java b/proton-j/codec/src/org/apache/qpid/proton/codec/ByteBufferDecoder.java deleted file mode 100644 index 4a10d76..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/ByteBufferDecoder.java +++ /dev/null @@ -1,28 +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; - -public interface ByteBufferDecoder extends Decoder -{ - public void setByteBuffer(ByteBuffer buffer); -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/ByteBufferEncoder.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/ByteBufferEncoder.java b/proton-j/codec/src/org/apache/qpid/proton/codec/ByteBufferEncoder.java deleted file mode 100644 index b773279..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/ByteBufferEncoder.java +++ /dev/null @@ -1,28 +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; - -public interface ByteBufferEncoder extends Encoder -{ - public void setByteBuffer(ByteBuffer buf); -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/ByteType.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/ByteType.java b/proton-j/codec/src/org/apache/qpid/proton/codec/ByteType.java deleted file mode 100644 index b35f4f1..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/ByteType.java +++ /dev/null @@ -1,129 +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 ByteType extends AbstractPrimitiveType<Byte> -{ - private ByteEncoding _byteEncoding; - - ByteType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _byteEncoding = new ByteEncoding(encoder, decoder); - encoder.register(Byte.class, this); - decoder.register(this); - } - - public Class<Byte> getTypeClass() - { - return Byte.class; - } - - public ByteEncoding getEncoding(final Byte val) - { - return _byteEncoding; - } - - - public ByteEncoding getCanonicalEncoding() - { - return _byteEncoding; - } - - public Collection<ByteEncoding> getAllEncodings() - { - return Collections.singleton(_byteEncoding); - } - - public void writeType(byte b) - { - _byteEncoding.write(b); - } - - - public class ByteEncoding extends FixedSizePrimitiveTypeEncoding<Byte> - { - - public ByteEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 1; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.BYTE; - } - - public ByteType getType() - { - return ByteType.this; - } - - public void writeValue(final Byte val) - { - getEncoder().writeRaw(val); - } - - - public void write(final byte val) - { - writeConstructor(); - getEncoder().writeRaw(val); - } - - public void writeValue(final byte val) - { - getEncoder().writeRaw(val); - } - - public boolean encodesSuperset(final TypeEncoding<Byte> encoding) - { - return (getType() == encoding.getType()); - } - - public Byte readValue() - { - return readPrimitiveValue(); - } - - public byte readPrimitiveValue() - { - return getDecoder().readRawByte(); - } - - - @Override - public boolean encodesJavaPrimitive() - { - return true; - } - - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/CharacterType.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/CharacterType.java b/proton-j/codec/src/org/apache/qpid/proton/codec/CharacterType.java deleted file mode 100644 index 8084495..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/CharacterType.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 CharacterType extends AbstractPrimitiveType<Character> -{ - private CharacterEncoding _characterEncoding; - - CharacterType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _characterEncoding = new CharacterEncoding(encoder, decoder); - encoder.register(Character.class, this); - decoder.register(this); - } - - public Class<Character> getTypeClass() - { - return Character.class; - } - - public CharacterEncoding getEncoding(final Character val) - { - return _characterEncoding; - } - - - public CharacterEncoding getCanonicalEncoding() - { - return _characterEncoding; - } - - public Collection<CharacterEncoding> getAllEncodings() - { - return Collections.singleton(_characterEncoding); - } - - public void write(char c) - { - _characterEncoding.write(c); - } - - public class CharacterEncoding extends FixedSizePrimitiveTypeEncoding<Character> - { - - public CharacterEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 4; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.CHAR; - } - - public CharacterType getType() - { - return CharacterType.this; - } - - public void writeValue(final Character val) - { - getEncoder().writeRaw((int)val.charValue() & 0xffff); - } - - public void writeValue(final char val) - { - getEncoder().writeRaw((int)val & 0xffff); - } - - public void write(final char c) - { - writeConstructor(); - getEncoder().writeRaw((int)c & 0xffff); - - } - - public boolean encodesSuperset(final TypeEncoding<Character> encoding) - { - return (getType() == encoding.getType()); - } - - public Character readValue() - { - return readPrimitiveValue(); - } - - public char readPrimitiveValue() - { - return (char) (getDecoder().readRawInt() & 0xffff); - } - - - @Override - public boolean encodesJavaPrimitive() - { - return true; - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/Decimal128Type.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/Decimal128Type.java b/proton-j/codec/src/org/apache/qpid/proton/codec/Decimal128Type.java deleted file mode 100644 index c8e937e..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/Decimal128Type.java +++ /dev/null @@ -1,103 +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.type.Decimal128; - -import java.util.Collection; -import java.util.Collections; - -public class Decimal128Type extends AbstractPrimitiveType<Decimal128> -{ - private Decimal128Encoding _decimal128Encoder; - - Decimal128Type(final EncoderImpl encoder, final DecoderImpl decoder) - { - _decimal128Encoder = new Decimal128Encoding(encoder, decoder); - encoder.register(Decimal128.class, this); - decoder.register(this); - } - - public Class<Decimal128> getTypeClass() - { - return Decimal128.class; - } - - public Decimal128Encoding getEncoding(final Decimal128 val) - { - return _decimal128Encoder; - } - - - public Decimal128Encoding getCanonicalEncoding() - { - return _decimal128Encoder; - } - - public Collection<Decimal128Encoding> getAllEncodings() - { - return Collections.singleton(_decimal128Encoder); - } - - private class Decimal128Encoding extends FixedSizePrimitiveTypeEncoding<Decimal128> - { - - public Decimal128Encoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 16; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.DECIMAL128; - } - - public Decimal128Type getType() - { - return Decimal128Type.this; - } - - public void writeValue(final Decimal128 val) - { - getEncoder().writeRaw(val.getMostSignificantBits()); - getEncoder().writeRaw(val.getLeastSignificantBits()); - } - - public boolean encodesSuperset(final TypeEncoding<Decimal128> encoding) - { - return (getType() == encoding.getType()); - } - - public Decimal128 readValue() - { - long msb = getDecoder().readRawLong(); - long lsb = getDecoder().readRawLong(); - return new Decimal128(msb, lsb); - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/Decimal32Type.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/Decimal32Type.java b/proton-j/codec/src/org/apache/qpid/proton/codec/Decimal32Type.java deleted file mode 100644 index e0e101c..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/Decimal32Type.java +++ /dev/null @@ -1,100 +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.type.Decimal32; - -import java.util.Collection; -import java.util.Collections; - -public class Decimal32Type extends AbstractPrimitiveType<Decimal32> -{ - private Decimal32Encoding _decimal32Encoder; - - Decimal32Type(final EncoderImpl encoder, final DecoderImpl decoder) - { - _decimal32Encoder = new Decimal32Encoding(encoder, decoder); - encoder.register(Decimal32.class, this); - decoder.register(this); - } - - public Class<Decimal32> getTypeClass() - { - return Decimal32.class; - } - - public Decimal32Encoding getEncoding(final Decimal32 val) - { - return _decimal32Encoder; - } - - - public Decimal32Encoding getCanonicalEncoding() - { - return _decimal32Encoder; - } - - public Collection<Decimal32Encoding> getAllEncodings() - { - return Collections.singleton(_decimal32Encoder); - } - - private class Decimal32Encoding extends FixedSizePrimitiveTypeEncoding<Decimal32> - { - - public Decimal32Encoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 4; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.DECIMAL32; - } - - public Decimal32Type getType() - { - return Decimal32Type.this; - } - - public void writeValue(final Decimal32 val) - { - getEncoder().writeRaw(val.getBits()); - } - - public boolean encodesSuperset(final TypeEncoding<Decimal32> encoding) - { - return (getType() == encoding.getType()); - } - - public Decimal32 readValue() - { - return new Decimal32(getDecoder().readRawInt()); - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/Decimal64Type.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/Decimal64Type.java b/proton-j/codec/src/org/apache/qpid/proton/codec/Decimal64Type.java deleted file mode 100644 index c8dceef..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/Decimal64Type.java +++ /dev/null @@ -1,100 +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.type.Decimal64; - -import java.util.Collection; -import java.util.Collections; - -public class Decimal64Type extends AbstractPrimitiveType<Decimal64> -{ - private Decimal64Encoding _decimal64Encoder; - - Decimal64Type(final EncoderImpl encoder, final DecoderImpl decoder) - { - _decimal64Encoder = new Decimal64Encoding(encoder, decoder); - encoder.register(Decimal64.class, this); - decoder.register(this); - } - - public Class<Decimal64> getTypeClass() - { - return Decimal64.class; - } - - public Decimal64Encoding getEncoding(final Decimal64 val) - { - return _decimal64Encoder; - } - - - public Decimal64Encoding getCanonicalEncoding() - { - return _decimal64Encoder; - } - - public Collection<Decimal64Encoding> getAllEncodings() - { - return Collections.singleton(_decimal64Encoder); - } - - private class Decimal64Encoding extends FixedSizePrimitiveTypeEncoding<Decimal64> - { - - public Decimal64Encoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 8; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.DECIMAL64; - } - - public Decimal64Type getType() - { - return Decimal64Type.this; - } - - public void writeValue(final Decimal64 val) - { - getEncoder().writeRaw(val.getBits()); - } - - public boolean encodesSuperset(final TypeEncoding<Decimal64> encoding) - { - return (getType() == encoding.getType()); - } - - public Decimal64 readValue() - { - return new Decimal64(getDecoder().readRawLong()); - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/DecodeException.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/DecodeException.java b/proton-j/codec/src/org/apache/qpid/proton/codec/DecodeException.java deleted file mode 100644 index 213e614..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/DecodeException.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 DecodeException extends RuntimeException -{ - public DecodeException() - { - } - - public DecodeException(String message) - { - super(message); - } - - public DecodeException(String message, Throwable cause) - { - super(message, cause); - } - - public DecodeException(Throwable cause) - { - super(cause); - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/Decoder.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/Decoder.java b/proton-j/codec/src/org/apache/qpid/proton/codec/Decoder.java deleted file mode 100644 index c931617..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/Decoder.java +++ /dev/null @@ -1,141 +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.type.*; - -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -public interface Decoder -{ - public static interface ListProcessor<T> - { - T process(int count, Encoder encoder); - } - - - Boolean readBoolean(); - Boolean readBoolean(Boolean defaultVal); - boolean readBoolean(boolean defaultVal); - - Byte readByte(); - Byte readByte(Byte defaultVal); - byte readByte(byte defaultVal); - - Short readShort(); - Short readShort(Short defaultVal); - short readShort(short defaultVal); - - Integer readInteger(); - Integer readInteger(Integer defaultVal); - int readInteger(int defaultVal); - - Long readLong(); - Long readLong(Long defaultVal); - long readLong(long defaultVal); - - UnsignedByte readUnsignedByte(); - UnsignedByte readUnsignedByte(UnsignedByte defaultVal); - - UnsignedShort readUnsignedShort(); - UnsignedShort readUnsignedShort(UnsignedShort defaultVal); - - UnsignedInteger readUnsignedInteger(); - UnsignedInteger readUnsignedInteger(UnsignedInteger defaultVal); - - UnsignedLong readUnsignedLong(); - UnsignedLong readUnsignedLong(UnsignedLong defaultVal); - - Character readCharacter(); - Character readCharacter(Character defaultVal); - char readCharacter(char defaultVal); - - Float readFloat(); - Float readFloat(Float defaultVal); - float readFloat(float defaultVal); - - Double readDouble(); - Double readDouble(Double defaultVal); - double readDouble(double defaultVal); - - UUID readUUID(); - UUID readUUID(UUID defaultValue); - - Decimal32 readDecimal32(); - Decimal32 readDecimal32(Decimal32 defaultValue); - - Decimal64 readDecimal64(); - Decimal64 readDecimal64(Decimal64 defaultValue); - - Decimal128 readDecimal128(); - Decimal128 readDecimal128(Decimal128 defaultValue); - - Date readTimestamp(); - Date readTimestamp(Date defaultValue); - - Binary readBinary(); - Binary readBinary(Binary defaultValue); - - Symbol readSymbol(); - Symbol readSymbol(Symbol defaultValue); - - String readString(); - String readString(String defaultValue); - - List readList(); - <T> void readList(ListProcessor<T> processor); - - Map readMap(); - - <T> T[] readArray(Class<T> clazz); - - Object[] readArray(); - - boolean[] readBooleanArray(); - byte[] readByteArray(); - short[] readShortArray(); - int[] readIntegerArray(); - long[] readLongArray(); - float[] readFloatArray(); - double[] readDoubleArray(); - char[] readCharacterArray(); - - <T> T[] readMultiple(Class<T> clazz); - - Object[] readMultiple(); - byte[] readByteMultiple(); - short[] readShortMultiple(); - int[] readIntegerMultiple(); - long[] readLongMultiple(); - float[] readFloatMultiple(); - double[] readDoubleMultiple(); - char[] readCharacterMultiple(); - - Object readObject(); - Object readObject(Object defaultValue); - - void register(final Object descriptor, final DescribedTypeConstructor dtc); - - -} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
