http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/StringType.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/StringType.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/StringType.java deleted file mode 100644 index a035e94..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/StringType.java +++ /dev/null @@ -1,238 +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.CharacterCodingException; -import java.nio.charset.Charset; -import java.nio.charset.CharsetDecoder; -import java.util.Arrays; -import java.util.Collection; - -public class StringType extends AbstractPrimitiveType<String> -{ - private static final Charset Charset_UTF8 = Charset.forName("UTF-8"); - private static final DecoderImpl.TypeDecoder<String> _stringCreator = - new DecoderImpl.TypeDecoder<String>() - { - - public String decode(final ByteBuffer buf) - { - CharsetDecoder charsetDecoder = Charset_UTF8.newDecoder(); - try - { - CharBuffer charBuf = charsetDecoder.decode(buf); - return charBuf.toString(); - } - catch (CharacterCodingException e) - { - throw new IllegalArgumentException("Cannot parse String"); - } - - } - }; - - - public static interface StringEncoding extends PrimitiveTypeEncoding<String> - { - void setValue(String val, int length); - } - - private final StringEncoding _stringEncoding; - private final StringEncoding _shortStringEncoding; - - StringType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _stringEncoding = new AllStringEncoding(encoder, decoder); - _shortStringEncoding = new ShortStringEncoding(encoder, decoder); - encoder.register(String.class, this); - decoder.register(this); - } - - public Class<String> getTypeClass() - { - return String.class; - } - - public StringEncoding getEncoding(final String val) - { - final int length = calculateUTF8Length(val); - StringEncoding encoding = length <= 255 - ? _shortStringEncoding - : _stringEncoding; - encoding.setValue(val, length); - return encoding; - } - - static int calculateUTF8Length(final String s) - { - int len = s.length(); - final int length = len; - for (int i = 0; i < length; i++) - { - int c = s.charAt(i); - if ((c & 0xFF80) != 0) /* U+0080.. */ - { - len++; - if(((c & 0xF800) != 0)) /* U+0800.. */ - { - len++; - // surrogate pairs should always combine to create a code point with a 4 octet representation - if ((c & 0xD800) == 0xD800 && c < 0xDC00) - { - i++; - } - } - } - } - return len; - } - - - public StringEncoding getCanonicalEncoding() - { - return _stringEncoding; - } - - public Collection<StringEncoding> getAllEncodings() - { - return Arrays.asList(_shortStringEncoding, _stringEncoding); - } - - private class AllStringEncoding - extends LargeFloatingSizePrimitiveTypeEncoding<String> - implements StringEncoding - { - - private String _value; - private int _length; - - - public AllStringEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected void writeEncodedValue(final String val) - { - getEncoder().writeRaw(val); - } - - @Override - protected int getEncodedValueSize(final String val) - { - return (val == _value) ? _length : calculateUTF8Length(val); - } - - - @Override - public byte getEncodingCode() - { - return EncodingCodes.STR32; - } - - public StringType getType() - { - return StringType.this; - } - - public boolean encodesSuperset(final TypeEncoding<String> encoding) - { - return (getType() == encoding.getType()); - } - - public String readValue() - { - - DecoderImpl decoder = getDecoder(); - int size = decoder.readRawInt(); - return decoder.readRaw(_stringCreator, size); - } - - public void setValue(final String val, final int length) - { - _value = val; - _length = length; - } - - } - - private class ShortStringEncoding - extends SmallFloatingSizePrimitiveTypeEncoding<String> - implements StringEncoding - { - - private String _value; - private int _length; - - public ShortStringEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - - @Override - protected void writeEncodedValue(final String val) - { - getEncoder().writeRaw(val); - } - - @Override - protected int getEncodedValueSize(final String val) - { - return (val == _value) ? _length : calculateUTF8Length(val); - } - - - @Override - public byte getEncodingCode() - { - return EncodingCodes.STR8; - } - - public StringType getType() - { - return StringType.this; - } - - public boolean encodesSuperset(final TypeEncoding<String> encoder) - { - return encoder == this; - } - - public String readValue() - { - - DecoderImpl decoder = getDecoder(); - int size = ((int)decoder.readRawByte()) & 0xff; - return decoder.readRaw(_stringCreator, size); - } - - public void setValue(final String val, final int length) - { - _value = val; - _length = length; - } - } - -}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/SymbolType.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/SymbolType.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/SymbolType.java deleted file mode 100644 index 4fb2038..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/SymbolType.java +++ /dev/null @@ -1,201 +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.Symbol; - -import java.nio.ByteBuffer; -import java.nio.charset.Charset; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -public class SymbolType extends AbstractPrimitiveType<Symbol> -{ - private static final Charset ASCII_CHARSET = Charset.forName("US-ASCII"); - private final SymbolEncoding _symbolEncoding; - private final SymbolEncoding _shortSymbolEncoding; - - private final Map<ByteBuffer, Symbol> _symbolCache = new HashMap<ByteBuffer, Symbol>(); - private DecoderImpl.TypeDecoder<Symbol> _symbolCreator = - new DecoderImpl.TypeDecoder<Symbol>() - { - - public Symbol decode(final ByteBuffer buf) - { - - Symbol symbol = _symbolCache.get(buf); - if(symbol == null) - { - byte[] bytes = new byte[buf.limit()]; - buf.get(bytes); - - String str = new String(bytes, ASCII_CHARSET); - symbol = Symbol.getSymbol(str); - - _symbolCache.put(ByteBuffer.wrap(bytes), symbol); - } - return symbol; - } - }; - - public static interface SymbolEncoding extends PrimitiveTypeEncoding<Symbol> - { - - } - - SymbolType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _symbolEncoding = new LongSymbolEncoding(encoder, decoder); - _shortSymbolEncoding = new ShortSymbolEncoding(encoder, decoder); - encoder.register(Symbol.class, this); - decoder.register(this); - } - - public Class<Symbol> getTypeClass() - { - return Symbol.class; - } - - public SymbolEncoding getEncoding(final Symbol val) - { - return val.length() <= 255 ? _shortSymbolEncoding : _symbolEncoding; - } - - - public SymbolEncoding getCanonicalEncoding() - { - return _symbolEncoding; - } - - public Collection<SymbolEncoding> getAllEncodings() - { - return Arrays.asList(_shortSymbolEncoding, _symbolEncoding); - } - - private class LongSymbolEncoding - extends LargeFloatingSizePrimitiveTypeEncoding<Symbol> - implements SymbolEncoding - { - - public LongSymbolEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected void writeEncodedValue(final Symbol val) - { - final int length = val.length(); - final EncoderImpl encoder = getEncoder(); - - for(int i = 0; i < length; i++) - { - encoder.writeRaw((byte)val.charAt(i)); - } - } - - @Override - protected int getEncodedValueSize(final Symbol val) - { - return val.length(); - } - - - @Override - public byte getEncodingCode() - { - return EncodingCodes.SYM32; - } - - public SymbolType getType() - { - return SymbolType.this; - } - - public boolean encodesSuperset(final TypeEncoding<Symbol> encoding) - { - return (getType() == encoding.getType()); - } - - public Symbol readValue() - { - DecoderImpl decoder = getDecoder(); - int size = decoder.readRawInt(); - return decoder.readRaw(_symbolCreator, size); - } - } - - private class ShortSymbolEncoding - extends SmallFloatingSizePrimitiveTypeEncoding<Symbol> - implements SymbolEncoding - { - - public ShortSymbolEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected void writeEncodedValue(final Symbol val) - { - - final int length = val.length(); - final EncoderImpl encoder = getEncoder(); - - for(int i = 0; i < length; i++) - { - encoder.writeRaw((byte)val.charAt(i)); - } - } - - @Override - protected int getEncodedValueSize(final Symbol val) - { - return val.length(); - } - - - @Override - public byte getEncodingCode() - { - return EncodingCodes.SYM8; - } - - public SymbolType getType() - { - return SymbolType.this; - } - - public boolean encodesSuperset(final TypeEncoding<Symbol> encoder) - { - return encoder == this; - } - - public Symbol readValue() - { - DecoderImpl decoder = getDecoder(); - int size = ((int)decoder.readRawByte()) & 0xff; - return decoder.readRaw(_symbolCreator, size); - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/TimestampType.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/TimestampType.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/TimestampType.java deleted file mode 100644 index 54baa25..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/TimestampType.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; -import java.util.Date; - -public class TimestampType extends AbstractPrimitiveType<Date> -{ - private TimestampEncoding _timestampEncoding; - - TimestampType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _timestampEncoding = new TimestampEncoding(encoder, decoder); - encoder.register(Date.class, this); - decoder.register(this); - } - - public Class<Date> getTypeClass() - { - return Date.class; - } - - public TimestampEncoding getEncoding(final Date val) - { - return _timestampEncoding; - } - - - public TimestampEncoding getCanonicalEncoding() - { - return _timestampEncoding; - } - - public Collection<TimestampEncoding> getAllEncodings() - { - return Collections.singleton(_timestampEncoding); - } - - public void write(long l) - { - _timestampEncoding.write(l); - } - - private class TimestampEncoding extends FixedSizePrimitiveTypeEncoding<Date> - { - - public TimestampEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 8; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.TIMESTAMP; - } - - public TimestampType getType() - { - return TimestampType.this; - } - - public void writeValue(final Date val) - { - getEncoder().writeRaw(val.getTime()); - } - - public void write(final long l) - { - writeConstructor(); - getEncoder().writeRaw(l); - - } - - public boolean encodesSuperset(final TypeEncoding<Date> encoding) - { - return (getType() == encoding.getType()); - } - - public Date readValue() - { - return new Date(getDecoder().readRawLong()); - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/TypeConstructor.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/TypeConstructor.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/TypeConstructor.java deleted file mode 100644 index 7b3f3a0..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/TypeConstructor.java +++ /dev/null @@ -1,30 +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 TypeConstructor<V> -{ - V readValue(); - - boolean encodesJavaPrimitive(); - - Class<V> getTypeClass(); -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/TypeEncoding.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/TypeEncoding.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/TypeEncoding.java deleted file mode 100644 index 2a8d4e5..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/TypeEncoding.java +++ /dev/null @@ -1,40 +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 TypeEncoding<V> -{ - AMQPType<V> getType(); - - void writeConstructor(); - - int getConstructorSize(); - - void writeValue(V val); - - int getValueSize(V val); - - boolean isFixedSizeVal(); - - boolean encodesSuperset(TypeEncoding<V> encoder); - - boolean encodesJavaPrimitive(); -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/UUIDType.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/UUIDType.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/UUIDType.java deleted file mode 100644 index 20b9002..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/UUIDType.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 java.util.Collection; -import java.util.Collections; -import java.util.UUID; - -public class UUIDType extends AbstractPrimitiveType<UUID> -{ - private UUIDEncoding _uuidEncoding; - - UUIDType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _uuidEncoding = new UUIDEncoding(encoder, decoder); - encoder.register(UUID.class, this); - decoder.register(this); - } - - public Class<UUID> getTypeClass() - { - return UUID.class; - } - - public UUIDEncoding getEncoding(final UUID val) - { - return _uuidEncoding; - } - - - public UUIDEncoding getCanonicalEncoding() - { - return _uuidEncoding; - } - - public Collection<UUIDEncoding> getAllEncodings() - { - return Collections.singleton(_uuidEncoding); - } - - private class UUIDEncoding extends FixedSizePrimitiveTypeEncoding<UUID> - { - - public UUIDEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 16; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.UUID; - } - - public UUIDType getType() - { - return UUIDType.this; - } - - public void writeValue(final UUID val) - { - getEncoder().writeRaw(val.getMostSignificantBits()); - getEncoder().writeRaw(val.getLeastSignificantBits()); - } - - public boolean encodesSuperset(final TypeEncoding<UUID> encoding) - { - return (getType() == encoding.getType()); - } - - public UUID readValue() - { - long msb = getDecoder().readRawLong(); - long lsb = getDecoder().readRawLong(); - - return new UUID(msb, lsb); - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/UnsignedByteType.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/UnsignedByteType.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/UnsignedByteType.java deleted file mode 100644 index 781a9de..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/UnsignedByteType.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.amqp.UnsignedByte; - -import java.util.Collection; -import java.util.Collections; - -public class UnsignedByteType extends AbstractPrimitiveType<UnsignedByte> -{ - private UnsignedByteEncoding _unsignedByteEncoding; - - UnsignedByteType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _unsignedByteEncoding = new UnsignedByteEncoding(encoder, decoder); - encoder.register(UnsignedByte.class, this); - decoder.register(this); - } - - public Class<UnsignedByte> getTypeClass() - { - return UnsignedByte.class; - } - - public UnsignedByteEncoding getEncoding(final UnsignedByte val) - { - return _unsignedByteEncoding; - } - - - public UnsignedByteEncoding getCanonicalEncoding() - { - return _unsignedByteEncoding; - } - - public Collection<UnsignedByteEncoding> getAllEncodings() - { - return Collections.singleton(_unsignedByteEncoding); - } - - public class UnsignedByteEncoding extends FixedSizePrimitiveTypeEncoding<UnsignedByte> - { - - public UnsignedByteEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 1; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.UBYTE; - } - - public UnsignedByteType getType() - { - return UnsignedByteType.this; - } - - public void writeValue(final UnsignedByte val) - { - getEncoder().writeRaw(val.byteValue()); - } - - public boolean encodesSuperset(final TypeEncoding<UnsignedByte> encoding) - { - return (getType() == encoding.getType()); - } - - public UnsignedByte readValue() - { - return UnsignedByte.valueOf(getDecoder().readRawByte()); - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/UnsignedIntegerType.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/UnsignedIntegerType.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/UnsignedIntegerType.java deleted file mode 100644 index 860e373..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/UnsignedIntegerType.java +++ /dev/null @@ -1,209 +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.UnsignedInteger; - -import java.util.Arrays; -import java.util.Collection; - -public class UnsignedIntegerType extends AbstractPrimitiveType<UnsignedInteger> -{ - public static interface UnsignedIntegerEncoding extends PrimitiveTypeEncoding<UnsignedInteger> - { - - } - - private UnsignedIntegerEncoding _unsignedIntegerEncoding; - private UnsignedIntegerEncoding _smallUnsignedIntegerEncoding; - private UnsignedIntegerEncoding _zeroUnsignedIntegerEncoding; - - - UnsignedIntegerType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _unsignedIntegerEncoding = new AllUnsignedIntegerEncoding(encoder, decoder); - _smallUnsignedIntegerEncoding = new SmallUnsignedIntegerEncoding(encoder, decoder); - _zeroUnsignedIntegerEncoding = new ZeroUnsignedIntegerEncoding(encoder, decoder); - encoder.register(UnsignedInteger.class, this); - decoder.register(this); - } - - public Class<UnsignedInteger> getTypeClass() - { - return UnsignedInteger.class; - } - - public UnsignedIntegerEncoding getEncoding(final UnsignedInteger val) - { - int i = val.intValue(); - return i == 0 - ? _zeroUnsignedIntegerEncoding - : (i >= 0 && i <= 255) ? _smallUnsignedIntegerEncoding : _unsignedIntegerEncoding; - } - - - public UnsignedIntegerEncoding getCanonicalEncoding() - { - return _unsignedIntegerEncoding; - } - - public Collection<UnsignedIntegerEncoding> getAllEncodings() - { - return Arrays.asList(_unsignedIntegerEncoding, _smallUnsignedIntegerEncoding, _zeroUnsignedIntegerEncoding); - } - - - private class AllUnsignedIntegerEncoding - extends FixedSizePrimitiveTypeEncoding<UnsignedInteger> - implements UnsignedIntegerEncoding - { - - public AllUnsignedIntegerEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 4; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.UINT; - } - - public UnsignedIntegerType getType() - { - return UnsignedIntegerType.this; - } - - public void writeValue(final UnsignedInteger val) - { - getEncoder().writeRaw(val.intValue()); - } - - public void write(final int i) - { - writeConstructor(); - getEncoder().writeRaw(i); - - } - - public boolean encodesSuperset(final TypeEncoding<UnsignedInteger> encoding) - { - return (getType() == encoding.getType()); - } - - public UnsignedInteger readValue() - { - return UnsignedInteger.valueOf(getDecoder().readRawInt()); - } - } - - private class SmallUnsignedIntegerEncoding - extends FixedSizePrimitiveTypeEncoding<UnsignedInteger> - implements UnsignedIntegerEncoding - { - public SmallUnsignedIntegerEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.SMALLUINT; - } - - @Override - protected int getFixedSize() - { - return 1; - } - - - public UnsignedIntegerType getType() - { - return UnsignedIntegerType.this; - } - - public void writeValue(final UnsignedInteger val) - { - getEncoder().writeRaw((byte)val.intValue()); - } - - public boolean encodesSuperset(final TypeEncoding<UnsignedInteger> encoder) - { - return encoder == this || encoder instanceof ZeroUnsignedIntegerEncoding; - } - - public UnsignedInteger readValue() - { - return UnsignedInteger.valueOf(((int)getDecoder().readRawByte()) & 0xff); - } - } - - - private class ZeroUnsignedIntegerEncoding - extends FixedSizePrimitiveTypeEncoding<UnsignedInteger> - implements UnsignedIntegerEncoding - { - public ZeroUnsignedIntegerEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.UINT0; - } - - @Override - protected int getFixedSize() - { - return 0; - } - - - public UnsignedIntegerType getType() - { - return UnsignedIntegerType.this; - } - - public void writeValue(final UnsignedInteger val) - { - } - - public boolean encodesSuperset(final TypeEncoding<UnsignedInteger> encoder) - { - return encoder == this; - } - - public UnsignedInteger readValue() - { - return UnsignedInteger.ZERO; - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/UnsignedLongType.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/UnsignedLongType.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/UnsignedLongType.java deleted file mode 100644 index 4b7980e..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/UnsignedLongType.java +++ /dev/null @@ -1,203 +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.UnsignedLong; - -import java.util.Arrays; -import java.util.Collection; - -public class UnsignedLongType extends AbstractPrimitiveType<UnsignedLong> -{ - public static interface UnsignedLongEncoding extends PrimitiveTypeEncoding<UnsignedLong> - { - - } - - private UnsignedLongEncoding _unsignedLongEncoding; - private UnsignedLongEncoding _smallUnsignedLongEncoding; - private UnsignedLongEncoding _zeroUnsignedLongEncoding; - - - UnsignedLongType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _unsignedLongEncoding = new AllUnsignedLongEncoding(encoder, decoder); - _smallUnsignedLongEncoding = new SmallUnsignedLongEncoding(encoder, decoder); - _zeroUnsignedLongEncoding = new ZeroUnsignedLongEncoding(encoder, decoder); - encoder.register(UnsignedLong.class, this); - decoder.register(this); - } - - public Class<UnsignedLong> getTypeClass() - { - return UnsignedLong.class; - } - - public UnsignedLongEncoding getEncoding(final UnsignedLong val) - { - long l = val.longValue(); - return l == 0L - ? _zeroUnsignedLongEncoding - : (l >= 0 && l <= 255L) ? _smallUnsignedLongEncoding : _unsignedLongEncoding; - } - - - public UnsignedLongEncoding getCanonicalEncoding() - { - return _unsignedLongEncoding; - } - - public Collection<UnsignedLongEncoding> getAllEncodings() - { - return Arrays.asList(_zeroUnsignedLongEncoding, _smallUnsignedLongEncoding, _unsignedLongEncoding); - } - - - private class AllUnsignedLongEncoding - extends FixedSizePrimitiveTypeEncoding<UnsignedLong> - implements UnsignedLongEncoding - { - - public AllUnsignedLongEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 8; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.ULONG; - } - - public UnsignedLongType getType() - { - return UnsignedLongType.this; - } - - public void writeValue(final UnsignedLong val) - { - getEncoder().writeRaw(val.longValue()); - } - - - public boolean encodesSuperset(final TypeEncoding<UnsignedLong> encoding) - { - return (getType() == encoding.getType()); - } - - public UnsignedLong readValue() - { - return UnsignedLong.valueOf(getDecoder().readRawLong()); - } - } - - private class SmallUnsignedLongEncoding - extends FixedSizePrimitiveTypeEncoding<UnsignedLong> - implements UnsignedLongEncoding - { - public SmallUnsignedLongEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.SMALLULONG; - } - - @Override - protected int getFixedSize() - { - return 1; - } - - - public UnsignedLongType getType() - { - return UnsignedLongType.this; - } - - public void writeValue(final UnsignedLong val) - { - getEncoder().writeRaw((byte)val.longValue()); - } - - public boolean encodesSuperset(final TypeEncoding<UnsignedLong> encoder) - { - return encoder == this || encoder instanceof ZeroUnsignedLongEncoding; - } - - public UnsignedLong readValue() - { - return UnsignedLong.valueOf(((long)getDecoder().readRawByte())&0xffl); - } - } - - - private class ZeroUnsignedLongEncoding - extends FixedSizePrimitiveTypeEncoding<UnsignedLong> - implements UnsignedLongEncoding - { - public ZeroUnsignedLongEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.ULONG0; - } - - @Override - protected int getFixedSize() - { - return 0; - } - - - public UnsignedLongType getType() - { - return UnsignedLongType.this; - } - - public void writeValue(final UnsignedLong val) - { - } - - public boolean encodesSuperset(final TypeEncoding<UnsignedLong> encoder) - { - return encoder == this; - } - - public UnsignedLong readValue() - { - return UnsignedLong.ZERO; - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/UnsignedShortType.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/UnsignedShortType.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/UnsignedShortType.java deleted file mode 100644 index 378c207..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/UnsignedShortType.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.amqp.UnsignedShort; - -import java.util.Collection; -import java.util.Collections; - -public class UnsignedShortType extends AbstractPrimitiveType<UnsignedShort> -{ - private UnsignedShortEncoding _unsignedShortEncoder; - - UnsignedShortType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _unsignedShortEncoder = new UnsignedShortEncoding(encoder, decoder); - encoder.register(UnsignedShort.class, this); - decoder.register(this); - } - - public Class<UnsignedShort> getTypeClass() - { - return UnsignedShort.class; - } - - public UnsignedShortEncoding getEncoding(final UnsignedShort val) - { - return _unsignedShortEncoder; - } - - - public UnsignedShortEncoding getCanonicalEncoding() - { - return _unsignedShortEncoder; - } - - public Collection<UnsignedShortEncoding> getAllEncodings() - { - return Collections.singleton(_unsignedShortEncoder); - } - - private class UnsignedShortEncoding extends FixedSizePrimitiveTypeEncoding<UnsignedShort> - { - - public UnsignedShortEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 2; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.USHORT; - } - - public UnsignedShortType getType() - { - return UnsignedShortType.this; - } - - public void writeValue(final UnsignedShort val) - { - getEncoder().writeRaw(val.shortValue()); - } - - public boolean encodesSuperset(final TypeEncoding<UnsignedShort> encoding) - { - return (getType() == encoding.getType()); - } - - public UnsignedShort readValue() - { - return UnsignedShort.valueOf(getDecoder().readRawShort()); - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/WritableBuffer.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/WritableBuffer.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/WritableBuffer.java deleted file mode 100644 index 79676b3..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/WritableBuffer.java +++ /dev/null @@ -1,153 +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 WritableBuffer -{ - void put(byte b); - - void putFloat(float f); - - void putDouble(double d); - - void put(byte[] src, int offset, int length); - - void putShort(short s); - - void putInt(int i); - - void putLong(long l); - - boolean hasRemaining(); - - int remaining(); - - int position(); - - void position(int position); - - void put(ByteBuffer payload); - - int limit(); - - class ByteBufferWrapper implements WritableBuffer - { - private final ByteBuffer _buf; - - public ByteBufferWrapper(ByteBuffer buf) - { - _buf = buf; - } - - @Override - public void put(byte b) - { - _buf.put(b); - } - - @Override - public void putFloat(float f) - { - _buf.putFloat(f); - } - - @Override - public void putDouble(double d) - { - _buf.putDouble(d); - } - - @Override - public void put(byte[] src, int offset, int length) - { - _buf.put(src, offset, length); - } - - @Override - public void putShort(short s) - { - _buf.putShort(s); - } - - @Override - public void putInt(int i) - { - _buf.putInt(i); - } - - @Override - public void putLong(long l) - { - _buf.putLong(l); - } - - @Override - public boolean hasRemaining() - { - return _buf.hasRemaining(); - } - - @Override - public int remaining() - { - return _buf.remaining(); - } - - @Override - public int position() - { - return _buf.position(); - } - - @Override - public void position(int position) - { - _buf.position(position); - } - - @Override - public void put(ByteBuffer src) - { - _buf.put(src); - } - - @Override - public int limit() - { - return _buf.limit(); - } - - @Override - public String toString() - { - return String.format("[pos: %d, limit: %d, remaining:%d]", _buf.position(), _buf.limit(), _buf.remaining()); - } - - public static ByteBufferWrapper allocate(int size) - { - ByteBuffer allocated = ByteBuffer.allocate(size); - return new ByteBufferWrapper(allocated); - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/AbstractElement.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/AbstractElement.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/AbstractElement.java deleted file mode 100644 index d0dd30c..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/AbstractElement.java +++ /dev/null @@ -1,142 +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.impl; - -abstract class AbstractElement<T> implements Element<T> -{ - private Element _parent; - private Element _next; - private Element _prev; - - AbstractElement(Element parent, Element prev) - { - _parent = parent; - _prev = prev; - } - - protected boolean isElementOfArray() - { - return _parent instanceof ArrayElement && !(((ArrayElement)parent()).isDescribed() && this == _parent.child()); - } - - @Override - public Element next() - { - // TODO - return _next; - } - - @Override - public Element prev() - { - // TODO - return _prev; - } - - @Override - public Element parent() - { - // TODO - return _parent; - } - - @Override - public void setNext(Element elt) - { - _next = elt; - } - - @Override - public void setPrev(Element elt) - { - _prev = elt; - } - - @Override - public void setParent(Element elt) - { - _parent = elt; - } - - @Override - public Element replaceWith(Element elt) - { - if (_parent != null) { - elt = _parent.checkChild(elt); - } - - elt.setPrev(_prev); - elt.setNext(_next); - elt.setParent(_parent); - - if (_prev != null) { - _prev.setNext(elt); - } - if (_next != null) { - _next.setPrev(elt); - } - - if (_parent != null && _parent.child() == this) { - _parent.setChild(elt); - } - - return elt; - } - - @Override - public String toString() - { - return String.format("%s[%h]{parent=%h, prev=%h, next=%h}", - this.getClass().getSimpleName(), - System.identityHashCode(this), - System.identityHashCode(_parent), - System.identityHashCode(_prev), - System.identityHashCode(_next)); - } - - abstract String startSymbol(); - - abstract String stopSymbol(); - - @Override - public void render(StringBuilder sb) - { - if (canEnter()) { - sb.append(startSymbol()); - Element el = child(); - boolean first = true; - while (el != null) { - if (first) { - first = false; - } else { - sb.append(", "); - } - el.render(sb); - el = el.next(); - } - sb.append(stopSymbol()); - } else { - sb.append(getDataType()).append(" ").append(getValue()); - } - } - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/ArrayElement.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/ArrayElement.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/ArrayElement.java deleted file mode 100644 index 22251fe..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/ArrayElement.java +++ /dev/null @@ -1,492 +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.impl; - -import java.nio.ByteBuffer; - -import org.apache.qpid.proton.amqp.DescribedType; -import org.apache.qpid.proton.amqp.Symbol; -import org.apache.qpid.proton.codec.Data; - -class ArrayElement extends AbstractElement<Object[]> -{ - - private final boolean _described; - private final Data.DataType _arrayType; - private ConstructorType _constructorType; - private Element _first; - - - static enum ConstructorType { TINY, SMALL, LARGE } - - - static ConstructorType TINY = ConstructorType.TINY; - static ConstructorType SMALL = ConstructorType.SMALL; - static ConstructorType LARGE = ConstructorType.LARGE; - - ArrayElement(Element parent, Element prev, boolean described, Data.DataType type) - { - super(parent, prev); - _described = described; - _arrayType = type; - if(_arrayType == null) - { - throw new NullPointerException("Array type cannot be null"); - } - else if(_arrayType == Data.DataType.DESCRIBED) - { - throw new IllegalArgumentException("Array type cannot be DESCRIBED"); - } - switch(_arrayType) - { - case UINT: - case ULONG: - case LIST: - setConstructorType(TINY); - break; - default: - setConstructorType(SMALL); - } - } - - ConstructorType constructorType() - { - return _constructorType; - } - - void setConstructorType(ConstructorType type) - { - _constructorType = type; - } - - @Override - public int size() - { - ConstructorType oldConstructorType; - int bodySize; - int count = 0; - do - { - bodySize = 1; // data type constructor - oldConstructorType = _constructorType; - Element element = _first; - while(element != null) - { - count++; - bodySize += element.size(); - element = element.next(); - } - } - while (oldConstructorType != constructorType()); - - if(isDescribed()) - { - bodySize++; // 00 instruction - if(count != 0) - { - count--; - } - } - - if(isElementOfArray()) - { - ArrayElement parent = (ArrayElement)parent(); - if(parent.constructorType()==SMALL) - { - if(count<=255 && bodySize<=254) - { - bodySize+=2; - } - else - { - parent.setConstructorType(LARGE); - bodySize+=8; - } - } - else - { - bodySize+=8; - } - } - else - { - - if(count<=255 && bodySize<=254) - { - bodySize+=3; - } - else - { - bodySize+=9; - } - - } - - - return bodySize; - } - - @Override - public Object[] getValue() - { - if(isDescribed()) - { - DescribedType[] rVal = new DescribedType[(int) count()]; - Object descriptor = _first == null ? null : _first.getValue(); - Element element = _first == null ? null : _first.next(); - int i = 0; - while(element != null) - { - rVal[i++] = new DescribedTypeImpl(descriptor, element.getValue()); - element = element.next(); - } - return rVal; - } - else if(_arrayType == Data.DataType.SYMBOL) - { - Symbol[] rVal = new Symbol[(int) count()]; - SymbolElement element = (SymbolElement) _first; - int i = 0; - while (element!=null) - { - rVal[i++] = element.getValue(); - element = (SymbolElement) element.next(); - } - return rVal; - } - else - { - Object[] rVal = new Object[(int) count()]; - Element element = _first; - int i = 0; - while (element!=null) - { - rVal[i++] = element.getValue(); - element = element.next(); - } - return rVal; - } - } - - @Override - public Data.DataType getDataType() - { - return Data.DataType.ARRAY; - } - - @Override - public int encode(ByteBuffer b) - { - int size = size(); - - final int count = (int) count(); - - if(b.remaining()>=size) - { - if(!isElementOfArray()) - { - if(size>257 || count >255) - { - b.put((byte)0xf0); - b.putInt(size-5); - b.putInt(count); - } - else - { - b.put((byte)0xe0); - b.put((byte)(size-2)); - b.put((byte)count); - } - } - else - { - ArrayElement parent = (ArrayElement)parent(); - if(parent.constructorType()==SMALL) - { - b.put((byte)(size-1)); - b.put((byte)count); - } - else - { - b.putInt(size-4); - b.putInt(count); - } - } - Element element = _first; - if(isDescribed()) - { - b.put((byte)0); - if(element == null) - { - b.put((byte)0x40); - } - else - { - element.encode(b); - element = element.next(); - } - } - switch(_arrayType) - { - case NULL: - b.put((byte)0x40); - break; - case BOOL: - b.put((byte)0x56); - break; - case UBYTE: - b.put((byte)0x50); - break; - case BYTE: - b.put((byte)0x51); - break; - case USHORT: - b.put((byte)0x60); - break; - case SHORT: - b.put((byte)0x61); - break; - case UINT: - switch (constructorType()) - { - case TINY: - b.put((byte)0x43); - break; - case SMALL: - b.put((byte)0x52); - break; - case LARGE: - b.put((byte)0x70); - break; - } - break; - case INT: - b.put(_constructorType == SMALL ? (byte)0x54 : (byte)0x71); - break; - case CHAR: - b.put((byte)0x73); - break; - case ULONG: - switch (constructorType()) - { - case TINY: - b.put((byte)0x44); - break; - case SMALL: - b.put((byte)0x53); - break; - case LARGE: - b.put((byte)0x80); - break; - } - break; - case LONG: - b.put(_constructorType == SMALL ? (byte)0x55 : (byte)0x81); - break; - case TIMESTAMP: - b.put((byte)0x83); - break; - case FLOAT: - b.put((byte)0x72); - break; - case DOUBLE: - b.put((byte)0x82); - break; - case DECIMAL32: - b.put((byte)0x74); - break; - case DECIMAL64: - b.put((byte)0x84); - break; - case DECIMAL128: - b.put((byte)0x94); - break; - case UUID: - b.put((byte)0x98); - break; - case BINARY: - b.put(_constructorType == SMALL ? (byte)0xa0 : (byte)0xb0); - break; - case STRING: - b.put(_constructorType == SMALL ? (byte)0xa1 : (byte)0xb1); - break; - case SYMBOL: - b.put(_constructorType == SMALL ? (byte)0xa3 : (byte)0xb3); - break; - case ARRAY: - b.put(_constructorType == SMALL ? (byte)0xe0 : (byte)0xf0); - break; - case LIST: - b.put(_constructorType == TINY ? (byte)0x45 :_constructorType == SMALL ? (byte)0xc0 : (byte)0xd0); - break; - case MAP: - b.put(_constructorType == SMALL ? (byte)0xc1 : (byte)0xd1); - break; - } - while(element!=null) - { - element.encode(b); - element = element.next(); - } - return size; - } - else - { - return 0; - } - } - - @Override - public boolean canEnter() - { - return true; - } - - @Override - public Element child() - { - return _first; - } - - @Override - public void setChild(Element elt) - { - _first = elt; - } - - @Override - public Element addChild(Element element) - { - if(isDescribed() || element.getDataType() == _arrayType) - { - _first = element; - return element; - } - else - { - Element replacement = coerce(element); - if(replacement != null) - { - _first = replacement; - return replacement; - } - throw new IllegalArgumentException("Attempting to add instance of " + element.getDataType() + " to array of " + _arrayType); - } - } - - private Element coerce(Element element) - { - switch (_arrayType) - { - case INT: - int i; - switch (element.getDataType()) - { - case BYTE: - i = ((ByteElement)element).getValue().intValue(); - break; - case SHORT: - i = ((ShortElement)element).getValue().intValue(); - break; - case LONG: - i = ((LongElement)element).getValue().intValue(); - break; - default: - return null; - } - return new IntegerElement(element.parent(),element.prev(),i); - - case LONG: - long l; - switch (element.getDataType()) - { - case BYTE: - l = ((ByteElement)element).getValue().longValue(); - break; - case SHORT: - l = ((ShortElement)element).getValue().longValue(); - break; - case INT: - l = ((IntegerElement)element).getValue().longValue(); - break; - default: - return null; - } - return new LongElement(element.parent(),element.prev(),l); - } - return null; - } - - @Override - public Element checkChild(Element element) - { - if(element.getDataType() != _arrayType) - { - Element replacement = coerce(element); - if(replacement != null) - { - return replacement; - } - throw new IllegalArgumentException("Attempting to add instance of " + element.getDataType() + " to array of " + _arrayType); - } - return element; - } - - - public long count() - { - int count = 0; - Element elt = _first; - while(elt != null) - { - count++; - elt = elt.next(); - } - if(isDescribed() && count != 0) - { - count--; - } - return count; - } - - public boolean isDescribed() - { - return _described; - } - - - public Data.DataType getArrayDataType() - { - return _arrayType; - } - - @Override - String startSymbol() { - return String.format("%s%s[", isDescribed() ? "D" : "", getArrayDataType()); - } - - @Override - String stopSymbol() { - return "]"; - } - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/AtomicElement.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/AtomicElement.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/AtomicElement.java deleted file mode 100644 index d414943..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/AtomicElement.java +++ /dev/null @@ -1,73 +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.impl; - -abstract class AtomicElement<T> extends AbstractElement<T> -{ - - AtomicElement(Element parent, Element prev) - { - super(parent, prev); - } - - @Override - public Element child() - { - throw new UnsupportedOperationException(); - } - - @Override - public void setChild(Element elt) - { - throw new UnsupportedOperationException(); - } - - - @Override - public boolean canEnter() - { - return false; - } - - @Override - public Element checkChild(Element element) - { - throw new UnsupportedOperationException(); - } - - @Override - public Element addChild(Element element) - { - throw new UnsupportedOperationException(); - } - - @Override - String startSymbol() { - throw new UnsupportedOperationException(); - } - - @Override - String stopSymbol() { - throw new UnsupportedOperationException(); - } - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/BinaryElement.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/BinaryElement.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/BinaryElement.java deleted file mode 100644 index fd05243..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/BinaryElement.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.impl; - -import java.nio.ByteBuffer; - -import org.apache.qpid.proton.amqp.Binary; -import org.apache.qpid.proton.codec.Data; - -class BinaryElement extends AtomicElement<Binary> -{ - - private final Binary _value; - - BinaryElement(Element parent, Element prev, Binary b) - { - super(parent, prev); - byte[] data = new byte[b.getLength()]; - System.arraycopy(b.getArray(),b.getArrayOffset(),data,0,b.getLength()); - _value = new Binary(data); - } - - @Override - public int size() - { - final int length = _value.getLength(); - - if(isElementOfArray()) - { - final ArrayElement parent = (ArrayElement) parent(); - - if(parent.constructorType() == ArrayElement.SMALL) - { - if(length > 255) - { - parent.setConstructorType(ArrayElement.LARGE); - return 4+length; - } - else - { - return 1+length; - } - } - else - { - return 4+length; - } - } - else - { - if(length >255) - { - return 5 + length; - } - else - { - return 2 + length; - } - } - } - - @Override - public Binary getValue() - { - return _value; - } - - @Override - public Data.DataType getDataType() - { - return Data.DataType.BINARY; - } - - @Override - public int encode(ByteBuffer b) - { - int size = size(); - if(b.remaining()<size) - { - return 0; - } - if(isElementOfArray()) - { - final ArrayElement parent = (ArrayElement) parent(); - - if(parent.constructorType() == ArrayElement.SMALL) - { - b.put((byte)_value.getLength()); - } - else - { - b.putInt(_value.getLength()); - } - } - else if(_value.getLength()<=255) - { - b.put((byte)0xa0); - b.put((byte)_value.getLength()); - } - else - { - b.put((byte)0xb0); - b.put((byte)_value.getLength()); - } - b.put(_value.getArray(),_value.getArrayOffset(),_value.getLength()); - return size; - - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/BooleanElement.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/BooleanElement.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/BooleanElement.java deleted file mode 100644 index f2fb704..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/BooleanElement.java +++ /dev/null @@ -1,76 +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.impl; - -import java.nio.ByteBuffer; - -import org.apache.qpid.proton.codec.Data; - -class BooleanElement extends AtomicElement<Boolean> -{ - private final boolean _value; - - public BooleanElement(Element parent, Element current, boolean b) - { - super(parent, current); - _value = b; - } - - @Override - public int size() - { - // in non-array parent then there is a single byte encoding, in an array there is a 1-byte encoding but no - // constructor - return 1; - } - - @Override - public Boolean getValue() - { - return _value; - } - - @Override - public Data.DataType getDataType() - { - return Data.DataType.BOOL; - } - - @Override - public int encode(ByteBuffer b) - { - if(b.hasRemaining()) - { - if(isElementOfArray()) - { - b.put(_value ? (byte) 1 : (byte) 0); - } - else - { - b.put(_value ? (byte) 0x41 : (byte) 0x42); - } - return 1; - } - return 0; - } - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/ByteElement.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/ByteElement.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/ByteElement.java deleted file mode 100644 index 69bde08..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/ByteElement.java +++ /dev/null @@ -1,79 +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.impl; - -import java.nio.ByteBuffer; - -import org.apache.qpid.proton.codec.Data; - -class ByteElement extends AtomicElement<Byte> -{ - - private final byte _value; - - ByteElement(Element parent, Element prev, byte b) - { - super(parent, prev); - _value = b; - } - - @Override - public int size() - { - return isElementOfArray() ? 1 : 2; - } - - @Override - public Byte getValue() - { - return _value; - } - - @Override - public Data.DataType getDataType() - { - return Data.DataType.BYTE; - } - - @Override - public int encode(ByteBuffer b) - { - if(isElementOfArray()) - { - if(b.hasRemaining()) - { - b.put(_value); - return 1; - } - } - else - { - if(b.remaining()>=2) - { - b.put((byte)0x51); - b.put(_value); - return 2; - } - } - return 0; - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/CharElement.java ---------------------------------------------------------------------- diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/CharElement.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/CharElement.java deleted file mode 100644 index 808d43e..0000000 --- a/proton-j/src/main/java/org/apache/qpid/proton/codec/impl/CharElement.java +++ /dev/null @@ -1,71 +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.impl; - -import java.nio.ByteBuffer; - -import org.apache.qpid.proton.codec.Data; - -class CharElement extends AtomicElement<Integer> -{ - - private final int _value; - - CharElement(Element parent, Element prev, int i) - { - super(parent, prev); - _value = i; - } - - @Override - public int size() - { - return isElementOfArray() ? 4 : 5; - } - - @Override - public Integer getValue() - { - return _value; - } - - @Override - public Data.DataType getDataType() - { - return Data.DataType.CHAR; - } - - @Override - public int encode(ByteBuffer b) - { - final int size = size(); - if(size <= b.remaining()) - { - if(size == 5) - { - b.put((byte)0x73); - } - b.putInt(_value); - } - return 0; - } -} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org