You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rg...@apache.org on 2011/08/14 19:15:08 UTC

svn commit: r1157566 [7/23] - in /qpid: branches/rg-amqp-1-0-sandbox/qpid/java/ branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-client/ branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-client/src/ branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-client/s...

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DelegatingValueWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DelegatingValueWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DelegatingValueWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DelegatingValueWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,52 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import java.nio.ByteBuffer;
+
+public abstract class DelegatingValueWriter<V> implements ValueWriter<V>
+{
+    private ValueWriter _delegate;
+    private Registry _registry;
+
+
+    protected DelegatingValueWriter(final Registry registry)
+    {
+        _registry = registry;
+    }
+
+    public int writeToBuffer(final ByteBuffer buffer)
+    {
+        return _delegate.writeToBuffer(buffer);
+    }
+
+    public void setValue(final V frameBody)
+    {
+        _delegate = _registry.getValueWriter(getUnderlyingValue(frameBody));
+    }
+
+    protected abstract Object getUnderlyingValue(final V frameBody);
+
+    public boolean isComplete()
+    {
+        return _delegate.isComplete();
+    }
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DescribedType.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DescribedType.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DescribedType.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DescribedType.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,85 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+public class DescribedType
+{
+    private final Object _descriptor;
+    private final Object _described;
+
+    public DescribedType(final Object descriptor, final Object described)
+    {
+        _descriptor = descriptor;
+        _described = described;
+    }
+
+    public Object getDescriptor()
+    {
+        return _descriptor;
+    }
+
+    public Object getDescribed()
+    {
+        return _described;
+    }
+
+    @Override
+    public boolean equals(final Object o)
+    {
+        if (this == o)
+        {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass())
+        {
+            return false;
+        }
+
+        final DescribedType that = (DescribedType) o;
+
+        if (_described != null ? !_described.equals(that._described) : that._described != null)
+        {
+            return false;
+        }
+        if (_descriptor != null ? !_descriptor.equals(that._descriptor) : that._descriptor != null)
+        {
+            return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public int hashCode()
+    {
+        int result = _descriptor != null ? _descriptor.hashCode() : 0;
+        result = 31 * result + (_described != null ? _described.hashCode() : 0);
+        return result;
+    }
+
+    @Override
+    public String toString()
+    {
+        return "DescribedType{"+ _descriptor +
+               ", " + _described +
+               '}';
+    }
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DescribedTypeConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DescribedTypeConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DescribedTypeConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DescribedTypeConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,41 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.AmqpErrorException;
+
+import java.nio.ByteBuffer;
+
+public abstract class DescribedTypeConstructor<T extends Object>
+{
+    public TypeConstructor<T> construct(final TypeConstructor describedConstructor) throws AmqpErrorException
+    {
+        return new TypeConstructor<T>()
+        {
+            public T construct(final ByteBuffer in, final ValueHandler handler) throws AmqpErrorException
+            {
+                return DescribedTypeConstructor.this.construct(describedConstructor.construct(in, handler));
+            }
+        };
+    }
+
+    public abstract T construct(Object underlying);
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DescribedTypeConstructorRegistry.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DescribedTypeConstructorRegistry.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DescribedTypeConstructorRegistry.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DescribedTypeConstructorRegistry.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,35 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+public interface DescribedTypeConstructorRegistry
+{
+    public static interface Source
+    {
+        public DescribedTypeConstructorRegistry getDescribedTypeRegistry();
+    }
+
+    void register(Object descriptor, DescribedTypeConstructor constructor);
+
+    DescribedTypeConstructor getConstructor(Object descriptor);
+
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DoubleTypeConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DoubleTypeConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DoubleTypeConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DoubleTypeConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,58 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.AmqpErrorException;
+import org.apache.qpid.amqp_1_0.type.transport.ConnectionError;
+import org.apache.qpid.amqp_1_0.type.transport.Error;
+
+import java.nio.ByteBuffer;
+
+public class DoubleTypeConstructor implements TypeConstructor
+{
+    private static final DoubleTypeConstructor INSTANCE = new DoubleTypeConstructor();
+
+
+    public static DoubleTypeConstructor getInstance()
+    {
+        return INSTANCE;
+    }
+
+    private DoubleTypeConstructor()
+    {
+    }
+
+    public Object construct(final ByteBuffer in, ValueHandler handler) throws AmqpErrorException
+    {
+        if(in.remaining()>=8)
+        {
+            return in.getDouble();
+        }
+        else
+        {
+            Error error = new Error();
+            error.setCondition(ConnectionError.FRAMING_ERROR);
+            error.setDescription("Cannot construct double: insufficient input data");
+            throw new AmqpErrorException(error);
+        }
+    }
+
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DoubleWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DoubleWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DoubleWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/DoubleWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,54 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+public class DoubleWriter extends FixedEightWriter<Double>
+{
+    private static final byte FORMAT_CODE = (byte) 0x82;
+
+
+    @Override
+    byte getFormatCode()
+    {
+        return FORMAT_CODE;
+    }
+
+    @Override
+    long convertValueToLong(Double value)
+    {
+        return Double.doubleToLongBits(value.doubleValue());
+    }
+
+    private static Factory<Double> FACTORY = new Factory<Double>()
+                                            {
+
+                                                public ValueWriter<Double> newInstance(Registry registry)
+                                                {
+                                                    return new DoubleWriter();
+                                                }
+                                            };
+
+    public static void register(ValueWriter.Registry registry)
+    {
+        registry.register(Double.class, FACTORY);
+    }
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/Encoder.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/Encoder.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/Encoder.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/Encoder.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,85 @@
+/*
+ * 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.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.Binary;
+import org.apache.qpid.amqp_1_0.type.Symbol;
+import org.apache.qpid.amqp_1_0.type.UnsignedByte;
+import org.apache.qpid.amqp_1_0.type.UnsignedInteger;
+import org.apache.qpid.amqp_1_0.type.UnsignedLong;
+import org.apache.qpid.amqp_1_0.type.UnsignedShort;
+
+import java.nio.ByteBuffer;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+public interface Encoder
+{
+
+    public boolean writeNull();
+
+    public boolean writeBoolean(boolean b);
+
+    public boolean writeByte(byte b);
+
+    public boolean writeUnsignedByte(ByteBuffer buf, UnsignedByte ub);
+
+    public boolean writeShort(ByteBuffer buf, short s);
+
+    public boolean writeUnsignedShort(UnsignedShort s);
+
+    public boolean writeInt(int i);
+
+    public boolean writeUnsignedInt(UnsignedInteger i);
+
+    public boolean writeLong(long l);
+
+    public boolean writeUnsignedLong(UnsignedLong l);
+
+    public boolean writeFloat(float f);
+
+    public boolean writeDouble(double d);
+
+    public boolean writeChar(char c);
+
+    public boolean writeTimestamp(Date d);
+
+    public boolean writeSymbol(Symbol s);
+
+    public boolean writeString(String s);
+
+    public boolean writeBytes(byte[] bytes);
+
+    public boolean writeBytes(Binary bin);
+
+    public boolean writeList(List l);
+
+    public boolean writeMap(Map m);
+
+    public boolean writeEncodable(EncodableValue o);
+
+    public boolean writeDescribedType(EncodableValue descriptor, EncodableValue described);
+
+    interface EncodableValue
+    {
+        void encode(Encoder encoder);
+    }
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FixedEightWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FixedEightWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FixedEightWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FixedEightWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,108 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import java.nio.ByteBuffer;
+
+public abstract class FixedEightWriter<T extends Object> implements ValueWriter<T>
+{
+    private int _written = 9;
+    private long _value;
+
+    public final int writeToBuffer(ByteBuffer buffer)
+    {
+        int remaining = buffer.remaining();
+        int written = _written;
+        switch(written)
+        {
+            case 0:
+                if(buffer.hasRemaining())
+                {
+                    buffer.put(getFormatCode());
+                    remaining--;
+                    written = 1;
+                }
+                else
+                {
+                    break;
+                }
+            case 1:
+                if(remaining>=8)
+                {
+                    buffer.putLong(_value);
+                    written = 9;
+                    break;
+                }
+            case 2:
+            case 3:
+            case 4:
+            case 5:
+                if(remaining >= 4)
+                {
+                    buffer.putInt((int)((_value >> ((5-written)<<3)) & 0xFFFFFFFF ));
+                    remaining-=4;
+                    written+=4;
+                }
+            case 6:
+            case 7:
+                if(remaining >= 2 && written <= 7)
+                {
+                    buffer.putShort((short)((_value >> ((7-written)<<3)) & 0xFFFF ));
+                    remaining -= 2;
+                    written += 2;
+                }
+            case 8:
+                if(remaining >=1 && written != 9)
+                {
+                    buffer.put((byte)((_value >> ((8-written)<<3)) & 0xFF ));
+                    written++;
+                }
+
+
+        }
+        _written = written;
+
+        return 9;
+    }
+
+    abstract byte getFormatCode();
+
+    public final void setValue(T value)
+    {
+        _written = 0;
+        _value = convertValueToLong(value);
+    }
+
+    abstract long convertValueToLong(T value);
+
+    public boolean isCacheable()
+    {
+        return true;
+    }
+
+    public final boolean isComplete()
+    {
+        return _written == 9;
+    }
+
+
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FixedFourWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FixedFourWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FixedFourWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FixedFourWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,122 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import java.nio.ByteBuffer;
+
+public abstract class FixedFourWriter<T extends Object> implements ValueWriter<T>
+{
+    private int _written = 5;
+    private int _value;
+
+    public final int writeToBuffer(ByteBuffer buffer)
+    {
+        int remaining = buffer.remaining();
+        int written = _written;
+        switch(written)
+        {
+            case 0:
+                if(remaining-- != 0)
+                {
+                    buffer.put(getFormatCode());
+                    written = 1;
+                }
+                else
+                {
+                    break;
+                }
+            case 1:
+                if(remaining>=4)
+                {
+                    buffer.putInt(_value);
+                    written = 5;
+                    break;
+                }
+                else if(remaining-- != 0)
+                {
+                    buffer.put((byte)((_value >> 24)&0xFF));
+                    written = 2;
+                }
+                else
+                {
+                    break;
+                }
+            case 2:
+                if(remaining-- != 0)
+                {
+                    buffer.put((byte)((_value >> 16)&0xFF));
+                    written = 3;
+                }
+                else
+                {
+                    break;
+                }
+            case 3:
+                if(remaining-- != 0)
+                {
+                    buffer.put((byte)((_value >> 8)&0xFF));
+                    written = 4;
+                }
+                else
+                {
+                    break;
+                }
+            case 4:
+                if(remaining-- != 0)
+                {
+                    buffer.put((byte)(_value&0xFF));
+                    written = 5;
+                }
+
+        }
+        _written = written;
+
+        return 5;
+    }
+
+    abstract byte getFormatCode();
+
+    public final void setValue(T value)
+    {
+        if(_written==1)
+        {
+            // TODO - remove
+            System.out.println("Remove");
+        }
+        _written = 0;
+        _value = convertValueToInt(value);
+    }
+
+    abstract int convertValueToInt(T value);
+
+    public boolean isCacheable()
+    {
+        return true;
+    }
+
+    public final boolean isComplete()
+    {
+        return _written == 5;
+    }
+
+
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FixedOneWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FixedOneWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FixedOneWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FixedOneWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.qpid.amqp_1_0.codec;
+
+import java.nio.ByteBuffer;
+
+
+public abstract class FixedOneWriter<T> implements ValueWriter<T>
+{
+    protected int _written = 2;
+    protected byte _value;
+
+    public int writeToBuffer(ByteBuffer buffer)
+    {
+
+        switch(_written)
+        {
+            case 0:
+                if(buffer.hasRemaining())
+                {
+                    buffer.put(getFormatCode());
+                }
+                else
+                {
+                    break;
+                }
+            case 1:
+                if(buffer.hasRemaining())
+                {
+                    buffer.put(_value);
+                    _written = 2;
+                }
+                else
+                {
+                    _written = 1;
+                }
+
+        }
+
+        return 2;
+    }
+
+    protected abstract byte getFormatCode();
+
+    public boolean isComplete()
+    {
+        return _written == 2;
+    }
+
+    public boolean isCacheable()
+    {
+        return true;
+    }
+
+    public void setValue(final T value)
+    {
+        _written = 0;
+        _value = convertToByte(value);
+    }
+
+    protected abstract byte convertToByte(final T value);
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FixedSixteenWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FixedSixteenWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FixedSixteenWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FixedSixteenWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,150 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import java.nio.ByteBuffer;
+
+public abstract class FixedSixteenWriter<T extends Object> implements ValueWriter<T>
+{
+    private int _written = 17;
+    private long _msb;
+    private long _lsb;
+
+    public final int writeToBuffer(ByteBuffer buffer)
+    {
+        int remaining = buffer.remaining();
+        int written = _written;
+        switch(written)
+        {
+            case 0:
+                if(buffer.hasRemaining())
+                {
+                    buffer.put(getFormatCode());
+                    remaining--;
+                    written = 1;
+                }
+                else
+                {
+                    break;
+                }
+            case 1:
+                if(remaining>=8)
+                {
+                    buffer.putLong(_msb);
+                    written = 9;
+                    break;
+                }
+            case 2:
+            case 3:
+            case 4:
+            case 5:
+                if(remaining >= 4)
+                {
+                    buffer.putInt((int)((_msb >> ((5-written)<<3)) & 0xFFFFFFFF ));
+                    remaining-=4;
+                    written+=4;
+                }
+            case 6:
+            case 7:
+                if(remaining >= 2 && written <= 7)
+                {
+                    buffer.putShort((short)((_msb >> ((7-written)<<3)) & 0xFFFF ));
+                    remaining -= 2;
+                    written += 2;
+                }
+            case 8:
+                if(remaining >=1 && written != 9)
+                {
+                    buffer.put((byte)((_msb >> ((8-written)<<3)) & 0xFF ));
+                    written++;
+                }
+
+
+        }
+        if(remaining != 0)
+        {
+            switch(written)
+            {
+                case 9:
+                    if(remaining>=8)
+                    {
+                        buffer.putLong(_lsb);
+                        written = 17;
+                        break;
+                    }
+                case 10:
+                case 11:
+                case 12:
+                case 13:
+                    if(remaining >= 4)
+                    {
+                        buffer.putInt((int)((_lsb >> ((13-written)<<3)) & 0xFFFFFFFF ));
+                        remaining-=4;
+                        written+=4;
+                    }
+                case 14:
+                case 15:
+                    if(remaining >= 2 && written <= 15)
+                    {
+                        buffer.putShort((short)((_lsb >> ((15-written)<<3)) & 0xFFFF ));
+                        remaining -= 2;
+                        written += 2;
+                    }
+                case 16:
+                    if(remaining >=1 && written != 17)
+                    {
+                        buffer.put((byte)((_msb >> ((16-written)<<3)) & 0xFF ));
+                        written++;
+                    }
+            }
+
+        }
+
+        _written = written;
+
+        return 17;
+    }
+
+    abstract byte getFormatCode();
+
+    public final void setValue(T value)
+    {
+        _written = 0;
+        _msb = convertValueToMSB(value);
+        _lsb = convertValueToLSB(value);
+    }
+
+    abstract long convertValueToMSB(T value);
+    abstract long convertValueToLSB(T value);
+
+    public boolean isCacheable()
+    {
+        return true;
+    }
+
+    public final boolean isComplete()
+    {
+        return _written == 17;
+    }
+
+
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FixedTwoWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FixedTwoWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FixedTwoWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FixedTwoWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,96 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import java.nio.ByteBuffer;
+
+public abstract class FixedTwoWriter <T extends Object> implements ValueWriter<T>
+{
+    private int _written = 3;
+    private short _value;
+
+    public int writeToBuffer(ByteBuffer buffer)
+    {
+
+        switch(_written)
+        {
+            case 0:
+                if(buffer.hasRemaining())
+                {
+                    buffer.put(getFormatCode());
+                }
+                else
+                {
+                    break;
+                }
+            case 1:
+
+                if(buffer.remaining()>1)
+                {
+                    buffer.putShort(_value);
+                    _written = 3;
+                }
+                else if(buffer.hasRemaining())
+                {
+                    buffer.put((byte) (0xFF & (_value >> 8)));
+                    _written = 2;
+                }
+                else
+                {
+                    _written = 1;
+                }
+                break;
+            case 2:
+                if(buffer.hasRemaining())
+                {
+                    buffer.put((byte)(0xFF & _value));
+                }
+
+
+        }
+
+        return 3;
+    }
+
+
+    public final void setValue(T value)
+    {
+        _written = 0;
+        _value = convertValueToShort(value);
+    }
+
+    abstract short convertValueToShort(T value);
+
+    public boolean isCacheable()
+    {
+        return true;
+    }
+
+    public boolean isComplete()
+    {
+        return _written == 3;
+    }
+
+    abstract byte getFormatCode();
+
+
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FloatTypeConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FloatTypeConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FloatTypeConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FloatTypeConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,58 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.*;
+import org.apache.qpid.amqp_1_0.type.transport.ConnectionError;
+import org.apache.qpid.amqp_1_0.type.transport.Error;
+
+import java.nio.ByteBuffer;
+
+public class FloatTypeConstructor implements TypeConstructor
+{
+    private static final FloatTypeConstructor INSTANCE = new FloatTypeConstructor();
+
+
+    public static FloatTypeConstructor getInstance()
+    {
+        return INSTANCE;
+    }
+
+    private FloatTypeConstructor()
+    {
+    }
+
+    public Object construct(final ByteBuffer in, ValueHandler handler) throws AmqpErrorException
+    {
+        if(in.remaining()>=4)
+        {
+            return in.getFloat();
+        }
+        else
+        {
+            org.apache.qpid.amqp_1_0.type.transport.Error error = new Error();
+            error.setCondition(ConnectionError.FRAMING_ERROR);
+            error.setDescription("Cannot construct float: insufficient input data");
+            throw new AmqpErrorException(error);
+        }
+    }
+
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FloatWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FloatWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FloatWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FloatWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,54 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+public class FloatWriter extends FixedFourWriter<Float>
+{
+    private static final byte FORMAT_CODE = (byte)0x72;
+
+
+    @Override
+    byte getFormatCode()
+    {
+        return FORMAT_CODE;
+    }
+
+    @Override
+    int convertValueToInt(Float value)
+    {
+        return Float.floatToIntBits(value.floatValue());
+    }
+
+    private static Factory<Float> FACTORY = new Factory<Float>()
+                                            {
+
+                                                public ValueWriter<Float> newInstance(Registry registry)
+                                                {
+                                                    return new FloatWriter();
+                                                }
+                                            };
+
+    public static void register(ValueWriter.Registry registry)
+    {
+        registry.register(Float.class, FACTORY);
+    }
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FrameWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FrameWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FrameWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/FrameWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,245 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.framing.AMQFrame;
+
+import java.nio.ByteBuffer;
+
+public class FrameWriter implements ValueWriter<AMQFrame>
+{
+    private Registry _registry;
+    private AMQFrame _frame;
+    private State _state = State.DONE;
+    private ValueWriter _typeWriter;
+    private int _size = -1;
+    private static final byte[] EMPTY_BYTE_ARRAY = new byte[] {};
+    private ByteBuffer _payload;
+
+    enum State
+    {
+        SIZE_0,
+        SIZE_1,
+        SIZE_2,
+        SIZE_3,
+        DOFF,
+        TYPE,
+        CHANNEL_0,
+        CHANNEL_1,
+        DELEGATE,
+        PAYLOAD,
+        DONE
+    }
+
+    public FrameWriter(final Registry registry)
+    {
+        _registry = registry;
+    }
+
+    public boolean isComplete()
+    {
+        return _state == State.DONE;
+    }
+
+    public boolean isCacheable()
+    {
+        return false;
+    }
+
+    public int writeToBuffer(ByteBuffer buffer)
+    {
+        int remaining;
+
+
+
+        while((remaining = buffer.remaining()) != 0 && _state != State.DONE)
+        {
+            switch(_state)
+            {
+                case SIZE_0:
+
+                    _typeWriter.setValue(_frame.getFrameBody());
+
+                    int payloadLength = _payload == null ? 0 : _payload.remaining();
+
+                    _size = _typeWriter.writeToBuffer(remaining > 8
+                                                      ? (ByteBuffer)buffer.duplicate().position(buffer.position()+8)
+                                                      : ByteBuffer.wrap(EMPTY_BYTE_ARRAY)) + 8 + payloadLength;
+                    if(remaining >= 4)
+                    {
+                        buffer.putInt(_size);
+
+                        if(remaining >= 8)
+                        {
+                            buffer.put((byte)2); // DOFF
+                            buffer.put(_frame.getFrameType()); // AMQP Frame Type
+                            buffer.putShort(_frame.getChannel());
+
+                            if(_size - payloadLength > remaining)
+                            {
+                                buffer.position(buffer.limit());
+                                _state = State.DELEGATE;
+                            }
+                            else if(_size > remaining )
+                            {
+                                buffer.position(buffer.position()+_size-8-payloadLength);
+                                if(payloadLength > 0)
+                                {
+
+                                    ByteBuffer dup = _payload.slice();
+                                    int payloadUsed = buffer.remaining();
+                                    dup.limit(payloadUsed);
+                                    buffer.put(dup);
+                                    _payload.position(_payload.position()+payloadUsed);
+                                }
+                                _state = State.PAYLOAD;
+                            }
+                            else
+                            {
+
+                                buffer.position(buffer.position()+_size-8-payloadLength);
+                                if(payloadLength > 0)
+                                {
+                                    buffer.put(_payload);
+                                }
+                                _state = State.DONE;
+                            }
+
+                        }
+                        else
+                        {
+                            _state = State.DOFF;
+                        }
+                        break;
+                    }
+                    else
+                    {
+                        buffer.put((byte)((_size >> 24) & 0xFF));
+                        if(!buffer.hasRemaining())
+                        {
+                            _state = State.SIZE_1;
+                            break;
+                        }
+                    }
+
+                case SIZE_1:
+                    buffer.put((byte)((_size >> 16) & 0xFF));
+                    if(!buffer.hasRemaining())
+                    {
+                        _state = State.SIZE_2;
+                        break;
+                    }
+                case SIZE_2:
+                    buffer.put((byte)((_size >> 8) & 0xFF));
+                    if(!buffer.hasRemaining())
+                    {
+                        _state = State.SIZE_3;
+                        break;
+                    }
+                case SIZE_3:
+                    buffer.put((byte)(_size & 0xFF));
+                    if(!buffer.hasRemaining())
+                    {
+                        _state = State.DOFF;
+                        break;
+                    }
+                case DOFF:
+                    buffer.put((byte)2); // Always 2 (8 bytes)
+                    if(!buffer.hasRemaining())
+                    {
+                        _state = State.TYPE;
+                        break;
+                    }
+                case TYPE:
+                    buffer.put((byte)0);
+                    if(!buffer.hasRemaining())
+                    {
+                        _state = State.CHANNEL_0;
+                        break;
+                    }
+                case CHANNEL_0:
+                    buffer.put((byte)((_frame.getChannel() >> 8) & 0xFF));
+                    if(!buffer.hasRemaining())
+                    {
+                        _state = State.CHANNEL_1;
+                        break;
+                    }
+                case CHANNEL_1:
+                    buffer.put((byte)(_frame.getChannel() & 0xFF));
+                    if(!buffer.hasRemaining())
+                    {
+                        _state = State.DELEGATE;
+                        break;
+                    }
+                case DELEGATE:
+                    _typeWriter.writeToBuffer(buffer);
+                    if(_typeWriter.isComplete())
+                    {
+                        _state = State.PAYLOAD;
+                        _frame = null;
+                        _typeWriter = null;
+                    }
+                    else
+                    {
+                        break;
+                    }
+                case PAYLOAD:
+                    if(_payload == null || _payload.remaining() == 0)
+                    {
+                        _state = State.DONE;
+                        _frame = null;
+                        _typeWriter = null;
+                        _payload = null;
+
+                    }
+                    else if(buffer.hasRemaining())
+                    {
+                        buffer.put(_payload);
+                        if(_payload.remaining() == 0)
+                        {
+                            _state = State.DONE;
+                            _frame = null;
+                            _typeWriter = null;
+                            _payload = null;
+                        }
+                    }
+
+            }
+        }
+        if(_size == -1)
+        {
+            _size =  _typeWriter.writeToBuffer(ByteBuffer.wrap(EMPTY_BYTE_ARRAY)) + 8 + (_payload == null ? 0 : _payload.remaining());
+        }
+        return _size;
+    }
+
+    public void setValue(AMQFrame frame)
+    {
+        _frame = frame;
+        _state = State.SIZE_0;
+        _size = -1;
+        _payload = null;
+        final Object frameBody = frame.getFrameBody();
+        _typeWriter = _registry.getValueWriter(frameBody);
+        _payload = frame.getPayload() == null ? null : frame.getPayload().duplicate();
+    }
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/IntTypeConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/IntTypeConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/IntTypeConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/IntTypeConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,58 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.*;
+import org.apache.qpid.amqp_1_0.type.transport.ConnectionError;
+
+import java.nio.ByteBuffer;
+
+public class IntTypeConstructor implements TypeConstructor
+{
+    private static final IntTypeConstructor INSTANCE = new IntTypeConstructor();
+
+
+    public static IntTypeConstructor getInstance()
+    {
+        return INSTANCE;
+    }
+
+    private IntTypeConstructor()
+    {
+    }
+
+    public Object construct(final ByteBuffer in, ValueHandler handler) throws AmqpErrorException
+    {
+        if(in.remaining()>=4)
+        {
+            return in.getInt();
+        }
+        else
+        {
+            org.apache.qpid.amqp_1_0.type.transport.Error error = new org.apache.qpid.amqp_1_0.type.transport.Error();
+            error.setCondition(ConnectionError.FRAMING_ERROR);
+            error.setDescription("Cannot construct int: insufficient input data");
+            throw new AmqpErrorException(error);
+
+        }
+    }
+
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/IntegerWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/IntegerWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/IntegerWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/IntegerWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,106 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import java.nio.ByteBuffer;
+
+public class IntegerWriter implements ValueWriter<Integer>
+{
+    private static final byte EIGHT_BYTE_FORMAT_CODE = (byte)0x71;
+    private static final byte ONE_BYTE_FORMAT_CODE = (byte) 0x54;
+
+    private ValueWriter<Integer> _delegate;
+
+    private final FixedFourWriter<Integer> _eightByteWriter = new FixedFourWriter<Integer>()
+    {
+
+        @Override
+        byte getFormatCode()
+        {
+            return EIGHT_BYTE_FORMAT_CODE;
+        }
+
+        @Override
+        int convertValueToInt(Integer value)
+        {
+            return value.intValue();
+        }
+    };
+
+    private final ValueWriter<Integer> _oneByteWriter = new FixedOneWriter<Integer>()
+    {
+
+        @Override protected byte getFormatCode()
+        {
+            return ONE_BYTE_FORMAT_CODE;
+        }
+
+        @Override protected byte convertToByte(final Integer value)
+        {
+            return value.byteValue();
+        }
+    };
+
+
+    public int writeToBuffer(final ByteBuffer buffer)
+    {
+        return _delegate.writeToBuffer(buffer);
+    }
+
+    public void setValue(final Integer i)
+    {
+        if(i >= -128 && i <= 127)
+        {
+            _delegate = _oneByteWriter;
+        }
+        else
+        {
+            _delegate = _eightByteWriter;
+        }
+        _delegate.setValue(i);
+    }
+
+    public boolean isComplete()
+    {
+        return _delegate.isComplete();
+    }
+
+    public boolean isCacheable()
+    {
+        return false;
+    }
+
+
+    private static Factory<Integer> FACTORY = new Factory<Integer>()
+                                            {
+
+                                                public ValueWriter<Integer> newInstance(Registry registry)
+                                                {
+                                                    return new IntegerWriter();
+                                                }
+                                            };
+
+    public static void register(ValueWriter.Registry registry)
+    {
+        registry.register(Integer.class, FACTORY);
+    }
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ListWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ListWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ListWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ListWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,171 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import java.nio.ByteBuffer;
+import java.util.List;
+
+public class ListWriter implements ValueWriter<List>
+{
+    private static class NonEmptyListWriter extends AbstractListWriter<List>
+    {
+        private List _list;
+        private int _position = 0;
+
+        public NonEmptyListWriter(final Registry registry)
+        {
+            super(registry);
+        }
+
+        @Override
+        protected void onSetValue(final List value)
+        {
+            _list = value;
+            _position = 0;
+
+        }
+
+        @Override
+        protected int getCount()
+        {
+            return _list.size();
+        }
+
+        @Override
+        protected boolean hasNext()
+        {
+            return _position < getCount();
+        }
+
+        @Override
+        protected Object next()
+        {
+            return _list.get(_position++);
+        }
+
+        @Override
+        protected void clear()
+        {
+            _list = null;
+            _position = 0;
+        }
+
+        @Override
+        protected void reset()
+        {
+            _position = 0;
+        }
+
+    }
+
+    private final NonEmptyListWriter _nonEmptyListWriter;
+    private static final byte ZERO_BYTE_FORMAT_CODE = (byte) 0x45;
+
+    private final ValueWriter<List> _emptyListWriter = new EmptyListValueWriter();
+
+
+    private ValueWriter<List> _delegate;
+
+    public ListWriter(final Registry registry)
+    {
+        _nonEmptyListWriter = new NonEmptyListWriter(registry);
+
+    }
+
+
+    public int writeToBuffer(ByteBuffer buffer)
+    {
+        return _delegate.writeToBuffer(buffer);
+    }
+
+    public void setValue(List frameBody)
+    {
+        if(frameBody.isEmpty())
+        {
+            _delegate = _emptyListWriter;
+        }
+        else
+        {
+            _delegate = _nonEmptyListWriter;
+        }
+    }
+
+    public boolean isComplete()
+    {
+        return _delegate.isComplete();
+    }
+
+    public boolean isCacheable()
+    {
+        return false;
+    }
+
+
+
+    private static Factory<List> FACTORY = new Factory<List>()
+                                            {
+
+                                                public ValueWriter<List> newInstance(Registry registry)
+                                                {
+                                                    return new ListWriter(registry);
+                                                }
+                                            };
+
+    public static void register(ValueWriter.Registry registry)
+    {
+        registry.register(List.class, FACTORY);
+    }
+
+    public static class EmptyListValueWriter implements ValueWriter<List>
+    {
+        private boolean _complete;
+
+
+        public int writeToBuffer(ByteBuffer buffer)
+        {
+
+            if(!_complete && buffer.hasRemaining())
+            {
+                buffer.put(ZERO_BYTE_FORMAT_CODE);
+                _complete = true;
+            }
+
+            return 1;
+        }
+
+        public void setValue(List list)
+        {
+            _complete = false;
+        }
+
+        public boolean isCacheable()
+        {
+            return true;
+        }
+
+        public boolean isComplete()
+        {
+            return _complete;
+        }
+
+    }
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/LongTypeConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/LongTypeConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/LongTypeConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/LongTypeConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,58 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.*;
+import org.apache.qpid.amqp_1_0.type.transport.ConnectionError;
+
+import java.nio.ByteBuffer;
+
+public class LongTypeConstructor implements TypeConstructor
+{
+    private static final LongTypeConstructor INSTANCE = new LongTypeConstructor();
+
+
+    public static LongTypeConstructor getInstance()
+    {
+        return INSTANCE;
+    }
+
+    private LongTypeConstructor()
+    {
+    }
+
+    public Object construct(final ByteBuffer in, ValueHandler handler) throws AmqpErrorException
+    {
+        if(in.remaining()>=8)
+        {
+            return in.getLong();
+        }
+        else
+        {
+            org.apache.qpid.amqp_1_0.type.transport.Error error = new org.apache.qpid.amqp_1_0.type.transport.Error();
+            error.setCondition(ConnectionError.FRAMING_ERROR);
+            error.setDescription("Cannot construct long: insufficient input data");
+            throw new AmqpErrorException(error);
+
+        }
+    }
+
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/LongWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/LongWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/LongWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/LongWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,111 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import java.nio.ByteBuffer;
+
+public class LongWriter implements ValueWriter<Long>
+{
+    private static final byte EIGHT_BYTE_FORMAT_CODE = (byte) 0x81;
+
+
+    private static final byte ONE_BYTE_FORMAT_CODE = (byte) 0x55;
+
+    private ValueWriter<Long> _delegate;
+
+    private final FixedEightWriter<Long> _eightByteWriter = new FixedEightWriter<Long>()
+    {
+
+        @Override
+        byte getFormatCode()
+        {
+            return EIGHT_BYTE_FORMAT_CODE;
+        }
+
+        @Override
+        long convertValueToLong(Long value)
+        {
+            return value;
+        }
+
+    };
+
+    private final ValueWriter<Long> _oneByteWriter = new FixedOneWriter<Long>()
+    {
+
+        @Override protected byte getFormatCode()
+        {
+            return ONE_BYTE_FORMAT_CODE;
+        }
+
+        @Override protected byte convertToByte(final Long value)
+        {
+            return value.byteValue();
+        }
+    };
+
+    public int writeToBuffer(final ByteBuffer buffer)
+    {
+        return _delegate.writeToBuffer(buffer);
+    }
+
+    public void setValue(final Long l)
+    {
+        if(l >= -128 && l <= 127)
+        {
+            _delegate = _oneByteWriter;
+        }
+        else
+        {
+            _delegate = _eightByteWriter;
+        }
+        _delegate.setValue(l);
+    }
+
+    public boolean isComplete()
+    {
+        return _delegate.isComplete();
+    }
+
+    public boolean isCacheable()
+    {
+        return false;
+    }
+
+
+
+
+    private static Factory<Long> FACTORY = new Factory<Long>()
+                                            {
+
+                                                public ValueWriter<Long> newInstance(Registry registry)
+                                                {
+                                                    return new LongWriter();
+                                                }
+                                            };
+
+    public static void register(ValueWriter.Registry registry)
+    {
+        registry.register(Long.class, FACTORY);
+    }
+
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/MapWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/MapWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/MapWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/MapWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,102 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import java.util.Iterator;
+import java.util.Map;
+
+public class MapWriter extends AbstractMapWriter<Map>
+{
+    private Map _map;
+    private Object _value;
+    private Iterator<Map.Entry> _iterator;
+
+    public MapWriter(final Registry registry)
+    {
+        super(registry);
+    }
+
+    @Override
+    protected void onSetValue(final Map value)
+    {
+        _map = value;
+        _iterator = value.entrySet().iterator();
+    }
+
+    @Override
+    protected int getMapCount()
+    {
+        return _map.size();
+    }
+
+    @Override
+    protected boolean hasMapNext()
+    {
+        return _iterator.hasNext();
+    }
+
+    @Override
+    protected Object nextKey()
+    {
+        Map.Entry entry = _iterator.next();
+        _value = entry.getValue();
+        return entry.getKey();
+    }
+    @Override
+    protected Object nextValue()
+    {
+        Object value = _value;
+        _value = null;
+        return value;
+    }
+
+
+    @Override
+    protected void onClear()
+    {
+        _map = null;
+        _iterator = null;
+        _value = null;
+    }
+
+    @Override
+    protected void onReset()
+    {
+        _iterator = _map.entrySet().iterator();
+        _value = null;
+    }
+
+
+    private static Factory<Map> FACTORY = new Factory<Map>()
+                                            {
+
+                                                public ValueWriter<Map> newInstance(Registry registry)
+                                                {
+                                                    return new MapWriter(registry);
+                                                }
+                                            };
+
+    public static void register(ValueWriter.Registry registry)
+    {
+        registry.register(Map.class, FACTORY);
+    }
+}
\ No newline at end of file

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/NullTypeConstructor.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/NullTypeConstructor.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/NullTypeConstructor.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/NullTypeConstructor.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,44 @@
+/*
+ * 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.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.AmqpErrorException;
+
+import java.nio.ByteBuffer;
+
+class NullTypeConstructor implements TypeConstructor<Void>
+{
+    private static final NullTypeConstructor INSTANCE = new NullTypeConstructor();
+
+    NullTypeConstructor()
+    {
+    }
+
+    public Void construct(final ByteBuffer in, final ValueHandler handler) throws AmqpErrorException
+    {
+        return null;
+    }
+
+    public static NullTypeConstructor getInstance()
+    {
+        return INSTANCE;
+    }
+
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/NullWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/NullWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/NullWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/NullWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,70 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import java.nio.ByteBuffer;
+
+public class NullWriter implements ValueWriter<Void>
+{
+    private boolean _complete = true;
+
+    public int writeToBuffer(ByteBuffer buffer)
+    {
+
+        if(!_complete && buffer.hasRemaining())
+        {
+            buffer.put((byte)0x40);
+            _complete = true;
+        }
+
+        return 1;
+    }
+
+    public void setValue(Void frameBody)
+    {
+        _complete = false;
+    }
+
+    public boolean isCacheable()
+    {
+        return true;
+    }
+
+    public boolean isComplete()
+    {
+        return _complete;
+    }
+
+    private static Factory<Void> FACTORY = new Factory<Void>()
+                                            {
+
+                                                public ValueWriter<Void> newInstance(Registry registry)
+                                                {
+                                                    return new NullWriter();
+                                                }
+                                            };
+
+    public static void register(ValueWriter.Registry registry)
+    {
+        registry.register(Void.TYPE, FACTORY);
+    }
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ProtocolHandler.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ProtocolHandler.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ProtocolHandler.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ProtocolHandler.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,30 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import java.nio.ByteBuffer;
+
+public interface ProtocolHandler
+{
+    ProtocolHandler parse(ByteBuffer in);
+
+    boolean isDone();
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ProtocolHeaderHandler.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ProtocolHeaderHandler.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ProtocolHeaderHandler.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/ProtocolHeaderHandler.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,146 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.framing.AMQPProtocolHeaderHandler;
+import org.apache.qpid.amqp_1_0.framing.SASLProtocolHeaderHandler;
+
+import org.apache.qpid.amqp_1_0.transport.ConnectionEndpoint;
+
+import java.nio.ByteBuffer;
+
+public class ProtocolHeaderHandler implements ProtocolHandler
+{
+    private final ConnectionEndpoint _connection;
+    private ProtocolHandler[] _protocolHandlers = new ProtocolHandler[4];
+    private boolean _done;
+
+    enum State {
+        AWAITING_A,
+        AWAITING_M,
+        AWAITING_Q,
+        AWAITING_P,
+        AWAITING_PROTOCOL_ID,
+        ERROR
+    }
+
+    private State _state = State.AWAITING_A;
+
+    public ProtocolHeaderHandler(final ConnectionEndpoint connection)
+    {
+        _connection = connection;
+        _protocolHandlers[0] = new AMQPProtocolHeaderHandler(connection);
+        _protocolHandlers[1] = null ; // historic apache.qpid.amqp_1_0
+        _protocolHandlers[2] = null ; // TLS
+        _protocolHandlers[3] = new SASLProtocolHeaderHandler(connection); // SASL
+
+
+    }
+
+    public ProtocolHandler parse(final ByteBuffer in)
+    {
+        if(!in.hasRemaining())
+        {
+            return this;
+        }
+
+        switch(_state)
+        {
+            case AWAITING_A:
+                if(transition(in, (byte)'A', State.AWAITING_M))
+                {
+                    break;
+                }
+            case AWAITING_M:
+                if(transition(in, (byte)'M', State.AWAITING_Q))
+                {
+                    break;
+                }
+            case AWAITING_Q:
+                if(transition(in, (byte)'Q', State.AWAITING_P))
+                {
+                    break;
+                }
+
+            case AWAITING_P:
+                if(transition(in, (byte)'P', State.AWAITING_PROTOCOL_ID))
+                {
+                    break;
+                }
+            case AWAITING_PROTOCOL_ID:
+                int protocolId = ((int) in.get()) & 0xff;
+                ProtocolHandler delegate;
+
+                try
+                {
+                    delegate = _protocolHandlers[protocolId];
+                }
+                catch(IndexOutOfBoundsException e)
+                {
+                    delegate = null;
+                }
+
+                if(delegate == null)
+                {
+                    _state = State.ERROR;
+                }
+                else
+                {
+                    return delegate.parse(in);
+                }
+        }
+        if(_state == State.ERROR)
+        {
+            _connection.invalidHeaderReceived();
+            _done = true;
+        }
+        return this;
+
+    }
+
+    boolean transition(ByteBuffer in, byte expected, State next)
+    {
+        byte b = in.get();
+        if(b == expected)
+        {
+            if(!in.hasRemaining())
+            {
+                _state =  next;
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+        else
+        {
+            _state = State.ERROR;
+            return true;
+        }
+    }
+
+
+    public boolean isDone()
+    {
+        return _done;
+    }
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/RestrictedTypeValueWriter.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/RestrictedTypeValueWriter.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/RestrictedTypeValueWriter.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/codec/RestrictedTypeValueWriter.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,55 @@
+/*
+ *
+ * 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.amqp_1_0.codec;
+
+import org.apache.qpid.amqp_1_0.type.RestrictedType;
+
+public class RestrictedTypeValueWriter<V> extends DelegatingValueWriter<RestrictedType<V>>
+{
+    public RestrictedTypeValueWriter(final Registry registry)
+    {
+        super(registry);
+    }
+
+    @Override
+    protected Object getUnderlyingValue(final RestrictedType<V> restrictedType)
+    {
+        return restrictedType.getValue();
+    }
+
+    private static Factory FACTORY = new Factory()
+    {
+
+        public ValueWriter newInstance(Registry registry)
+        {
+            return new RestrictedTypeValueWriter(registry);
+        }
+    };
+
+    public boolean isCacheable()
+    {
+        return true;
+    }
+
+    public static void register(ValueWriter.Registry registry, Class clazz)
+    {
+        registry.register(clazz, FACTORY);
+    }}



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org