diff options
Diffstat (limited to 'dotnet/Qpid.Common')
-rw-r--r-- | dotnet/Qpid.Common/AMQInvalidArgumentException.cs | 92 | ||||
-rw-r--r-- | dotnet/Qpid.Common/AMQInvalidRoutingKeyException.cs | 92 | ||||
-rw-r--r-- | dotnet/Qpid.Common/Collections/ConsumerProducerQueue.cs | 226 | ||||
-rw-r--r-- | dotnet/Qpid.Common/Framing/AMQType.cs | 1400 | ||||
-rw-r--r-- | dotnet/Qpid.Common/Framing/AMQTypeMap.cs | 150 | ||||
-rw-r--r-- | dotnet/Qpid.Common/Framing/AMQTypedValue.cs | 152 | ||||
-rw-r--r-- | dotnet/Qpid.Common/Protocol/AMQConstant.cs | 200 |
7 files changed, 1156 insertions, 1156 deletions
diff --git a/dotnet/Qpid.Common/AMQInvalidArgumentException.cs b/dotnet/Qpid.Common/AMQInvalidArgumentException.cs index 0fb4ddae99..831f7bab0e 100644 --- a/dotnet/Qpid.Common/AMQInvalidArgumentException.cs +++ b/dotnet/Qpid.Common/AMQInvalidArgumentException.cs @@ -1,46 +1,46 @@ -/*
- *
- * 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.
- *
- */
-
-using System;
-using System.Runtime.Serialization;
-
-using Apache.Qpid.Protocol;
-
-namespace Apache.Qpid
-{
- /// <summary>
- /// Thrown when an invalid argument was supplied to the broker
- /// </summary>
- [Serializable]
- public class AMQInvalidArgumentException : AMQException
- {
- public AMQInvalidArgumentException(string message)
- : base(AMQConstant.INVALID_ARGUMENT.Code, message, null)
- {
- }
-
- protected AMQInvalidArgumentException(SerializationInfo info, StreamingContext ctxt)
- : base(info, ctxt)
- {
- }
-
- }
-}
+/* + * + * 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. + * + */ + +using System; +using System.Runtime.Serialization; + +using Apache.Qpid.Protocol; + +namespace Apache.Qpid +{ + /// <summary> + /// Thrown when an invalid argument was supplied to the broker + /// </summary> + [Serializable] + public class AMQInvalidArgumentException : AMQException + { + public AMQInvalidArgumentException(string message) + : base(AMQConstant.INVALID_ARGUMENT.Code, message, null) + { + } + + protected AMQInvalidArgumentException(SerializationInfo info, StreamingContext ctxt) + : base(info, ctxt) + { + } + + } +} diff --git a/dotnet/Qpid.Common/AMQInvalidRoutingKeyException.cs b/dotnet/Qpid.Common/AMQInvalidRoutingKeyException.cs index 3f8dead94d..a3ce813d1b 100644 --- a/dotnet/Qpid.Common/AMQInvalidRoutingKeyException.cs +++ b/dotnet/Qpid.Common/AMQInvalidRoutingKeyException.cs @@ -1,46 +1,46 @@ -/*
- *
- * 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.
- *
- */
-
-using System;
-using System.Runtime.Serialization;
-
-using Apache.Qpid.Protocol;
-
-namespace Apache.Qpid
-{
- /// <summary>
- /// Thrown when an invalid routing key was sent to the broker
- /// </summary>
- [Serializable]
- public class AMQInvalidRoutingKeyException : AMQException
- {
- public AMQInvalidRoutingKeyException(string message)
- : base(AMQConstant.INVALID_ROUTING_KEY.Code, message, null)
- {
- }
-
- protected AMQInvalidRoutingKeyException(SerializationInfo info, StreamingContext ctxt)
- : base(info, ctxt)
- {
- }
-
- }
-}
+/* + * + * 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. + * + */ + +using System; +using System.Runtime.Serialization; + +using Apache.Qpid.Protocol; + +namespace Apache.Qpid +{ + /// <summary> + /// Thrown when an invalid routing key was sent to the broker + /// </summary> + [Serializable] + public class AMQInvalidRoutingKeyException : AMQException + { + public AMQInvalidRoutingKeyException(string message) + : base(AMQConstant.INVALID_ROUTING_KEY.Code, message, null) + { + } + + protected AMQInvalidRoutingKeyException(SerializationInfo info, StreamingContext ctxt) + : base(info, ctxt) + { + } + + } +} diff --git a/dotnet/Qpid.Common/Collections/ConsumerProducerQueue.cs b/dotnet/Qpid.Common/Collections/ConsumerProducerQueue.cs index ea4526faaf..131f316da6 100644 --- a/dotnet/Qpid.Common/Collections/ConsumerProducerQueue.cs +++ b/dotnet/Qpid.Common/Collections/ConsumerProducerQueue.cs @@ -1,113 +1,113 @@ -/*
- *
- * 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.
- *
- */
-using System;
-using System.Collections;
-using System.Threading;
-
-
-namespace Apache.Qpid.Collections
-{
- /// <summary>
- /// Simple FIFO queue to support multi-threaded consumer
- /// and producers. It supports timeouts in dequeue operations.
- /// </summary>
- public sealed class ConsumerProducerQueue
- {
- private Queue _queue = new Queue();
- private WaitSemaphore _semaphore = new WaitSemaphore();
-
- /// <summary>
- /// Put an item into the tail of the queue
- /// </summary>
- /// <param name="item"></param>
- public void Enqueue(object item)
- {
- lock ( _queue.SyncRoot )
- {
- _queue.Enqueue(item);
- _semaphore.Increment();
- }
- }
-
- /// <summary>
- /// Wait indefinitely for an item to be available
- /// on the queue.
- /// </summary>
- /// <returns>The object at the head of the queue</returns>
- public object Dequeue()
- {
- return Dequeue(Timeout.Infinite);
- }
-
- /// <summary>
- /// Wait up to the number of milliseconds specified
- /// for an item to be available on the queue
- /// </summary>
- /// <param name="timeout">Number of milliseconds to wait</param>
- /// <returns>The object at the head of the queue, or null
- /// if the timeout expires</returns>
- public object Dequeue(long timeout)
- {
- if ( _semaphore.Decrement(timeout) )
- {
- lock ( _queue.SyncRoot )
- {
- return _queue.Dequeue();
- }
- }
- return null;
- }
-
- #region Simple Semaphore
- //
- // Simple Semaphore
- //
-
- class WaitSemaphore
- {
- private int _count;
- private AutoResetEvent _event = new AutoResetEvent(false);
-
- public void Increment()
- {
- Interlocked.Increment(ref _count);
- _event.Set();
- }
-
- public bool Decrement(long timeout)
- {
- if ( timeout > int.MaxValue )
- throw new ArgumentOutOfRangeException("timeout", timeout, "Must be <= Int32.MaxValue");
-
- int millis = (int) (timeout & 0x7FFFFFFF);
- if ( Interlocked.Decrement(ref _count) > 0 )
- {
- // there are messages in queue, so no need to wait
- return true;
- } else
- {
- return _event.WaitOne(millis, false);
- }
- }
- }
- #endregion // Simple Semaphore
- }
-}
+/* + * + * 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. + * + */ +using System; +using System.Collections; +using System.Threading; + + +namespace Apache.Qpid.Collections +{ + /// <summary> + /// Simple FIFO queue to support multi-threaded consumer + /// and producers. It supports timeouts in dequeue operations. + /// </summary> + public sealed class ConsumerProducerQueue + { + private Queue _queue = new Queue(); + private WaitSemaphore _semaphore = new WaitSemaphore(); + + /// <summary> + /// Put an item into the tail of the queue + /// </summary> + /// <param name="item"></param> + public void Enqueue(object item) + { + lock ( _queue.SyncRoot ) + { + _queue.Enqueue(item); + _semaphore.Increment(); + } + } + + /// <summary> + /// Wait indefinitely for an item to be available + /// on the queue. + /// </summary> + /// <returns>The object at the head of the queue</returns> + public object Dequeue() + { + return Dequeue(Timeout.Infinite); + } + + /// <summary> + /// Wait up to the number of milliseconds specified + /// for an item to be available on the queue + /// </summary> + /// <param name="timeout">Number of milliseconds to wait</param> + /// <returns>The object at the head of the queue, or null + /// if the timeout expires</returns> + public object Dequeue(long timeout) + { + if ( _semaphore.Decrement(timeout) ) + { + lock ( _queue.SyncRoot ) + { + return _queue.Dequeue(); + } + } + return null; + } + + #region Simple Semaphore + // + // Simple Semaphore + // + + class WaitSemaphore + { + private int _count; + private AutoResetEvent _event = new AutoResetEvent(false); + + public void Increment() + { + Interlocked.Increment(ref _count); + _event.Set(); + } + + public bool Decrement(long timeout) + { + if ( timeout > int.MaxValue ) + throw new ArgumentOutOfRangeException("timeout", timeout, "Must be <= Int32.MaxValue"); + + int millis = (int) (timeout & 0x7FFFFFFF); + if ( Interlocked.Decrement(ref _count) > 0 ) + { + // there are messages in queue, so no need to wait + return true; + } else + { + return _event.WaitOne(millis, false); + } + } + } + #endregion // Simple Semaphore + } +} diff --git a/dotnet/Qpid.Common/Framing/AMQType.cs b/dotnet/Qpid.Common/Framing/AMQType.cs index 618ab31d32..95da72b907 100644 --- a/dotnet/Qpid.Common/Framing/AMQType.cs +++ b/dotnet/Qpid.Common/Framing/AMQType.cs @@ -1,700 +1,700 @@ -/*
- *
- * 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.
- *
- */
-using System;
-using System.Text;
-using Apache.Qpid.Buffer;
-
-namespace Apache.Qpid.Framing
-{
- /// <summary>
- /// Base class for the Field Table Type system.
- /// Ported over from the Java AMQType enumeration
- /// </summary>
- public abstract class AMQType
- {
- private byte _identifier;
-
- /// <summary>
- /// Type code identifier for this type
- /// </summary>
- public byte Identifier
- {
- get { return _identifier; }
- }
-
- protected AMQType(char identifier)
- {
- _identifier = (byte)identifier;
- }
-
- /// <summary>
- /// Create a new <see cref="AMQTypedValue"/> instance
- /// </summary>
- /// <param name="value">Value to initialize with</param>
- /// <returns>A new typed value instance</returns>
- public AMQTypedValue AsTypedValue(object value)
- {
- return new AMQTypedValue(this, ToNativeValue(value));
- }
-
- /// <summary>
- /// Write the specified value to the buffer using the encoding
- /// specified for this type
- /// </summary>
- /// <param name="value">Value to write</param>
- /// <param name="buffer">Buffer to write to</param>
- public void WriteToBuffer(object value, ByteBuffer buffer)
- {
- buffer.Put(Identifier);
- WriteValueImpl(value, buffer);
- }
-
- public override string ToString()
- {
- return ((Char) Identifier).ToString();
- }
-
- /// <summary>
- /// Get the encoding size for the specified value in this type format
- /// </summary>
- /// <param name="value">Value to find encoded size for</param>
- /// <returns>The encoded size</returns>
- public abstract uint GetEncodingSize(object value);
- /// <summary>
- /// Convert the specified value to this type
- /// </summary>
- /// <param name="value">Value to convert</param>
- /// <returns>The converted value</returns>
- public abstract object ToNativeValue(object value);
-
- /// <summary>
- /// Read a value from the specified buffer using the encoding for
- /// this type
- /// </summary>
- /// <param name="buffer">Buffer to read from</param>
- /// <returns>The value read</returns>
- public abstract object ReadValueFromBuffer(ByteBuffer buffer);
-
- protected abstract void WriteValueImpl(Object value, ByteBuffer buffer);
-
-
- #region Known Types
- //
- // Known Types
- //
-
- // long string is not defined in the proposed specification,
- // and the 'S' discriminator is left for unsigned short (16-bit) values
- public static readonly AMQType LONG_STRING = new AMQLongStringType();
- public static readonly AMQType UINT32 = new AMQUInt32Type();
- public static readonly AMQType DECIMAL = new AMQDecimalType();
- public static readonly AMQType TIMESTAMP = new AMQTimeStampType();
- public static readonly AMQType FIELD_TABLE = new AMQFieldTableType();
- public static readonly AMQType VOID = new AMQVoidType();
- public static readonly AMQType BINARY = new AMQBinaryType();
- public static readonly AMQType ASCII_STRING = new AMQAsciiStringType();
- public static readonly AMQType WIDE_STRING = new AMQWideStringType();
- public static readonly AMQType BOOLEAN = new AMQBooleanType();
- public static readonly AMQType ASCII_CHARACTER = new AMQAsciiCharType();
- public static readonly AMQType BYTE = new AMQByteType();
- public static readonly AMQType SBYTE = new AMQSByteType();
- public static readonly AMQType INT16 = new AMQInt16Type();
- public static readonly AMQType UINT16 = new AMQUInt16Type();
- public static readonly AMQType INT32 = new AMQInt32Type();
- public static readonly AMQType INT64 = new AMQInt64Type();
- public static readonly AMQType UINT64 = new AMQUInt64Type();
- public static readonly AMQType FLOAT = new AMQFloatType();
- public static readonly AMQType DOUBLE = new AMQDoubleType();
-
- #endregion // Known Types
-
- #region Type Implementation
- //
- // Type Implementation
- //
-
- sealed class AMQLongStringType : AMQType
- {
- public AMQLongStringType() : base('S')
- {
- }
-
- public override uint GetEncodingSize(object value)
- {
- return EncodingUtils.EncodedLongStringLength((string) value);
- }
-
- public override object ToNativeValue(object value)
- {
- if ( value == null )
- throw new ArgumentNullException("value");
- return value.ToString();
- }
-
- public override object ReadValueFromBuffer(ByteBuffer buffer)
- {
- return EncodingUtils.ReadLongString(buffer);
- }
-
- protected override void WriteValueImpl(object value, ByteBuffer buffer)
- {
- EncodingUtils.WriteLongStringBytes(buffer, (string) value);
- }
-
- }
-
- sealed class AMQUInt32Type : AMQType
- {
- public AMQUInt32Type() : base('i')
- {
- }
-
- public override uint GetEncodingSize(object value)
- {
- return EncodingUtils.UnsignedIntegerLength();
- }
-
- public override object ToNativeValue(object value)
- {
- return Convert.ToUInt32(value);
- }
-
- public override object ReadValueFromBuffer(ByteBuffer buffer)
- {
- return EncodingUtils.ReadUnsignedInteger(buffer);
- }
-
- protected override void WriteValueImpl(object value, ByteBuffer buffer)
- {
- EncodingUtils.WriteUnsignedInteger(buffer, (uint) value);
- }
-
- }
-
- sealed class AMQDecimalType : AMQType
- {
- public AMQDecimalType() : base('D')
- {
- }
-
- public override uint GetEncodingSize(object value)
- {
- throw new NotImplementedException();
- }
-
- public override object ToNativeValue(object value)
- {
- throw new NotImplementedException();
- }
-
- public override object ReadValueFromBuffer(ByteBuffer buffer)
- {
- throw new NotImplementedException();
- }
-
- protected override void WriteValueImpl(object value, ByteBuffer buffer)
- {
- throw new NotImplementedException();
- }
- }
-
- sealed class AMQTimeStampType : AMQType
- {
- public AMQTimeStampType() : base('T')
- {
- }
-
- public override uint GetEncodingSize(object value)
- {
- throw new NotImplementedException();
- }
-
- public override object ToNativeValue(object value)
- {
- throw new NotImplementedException();
- }
-
- public override object ReadValueFromBuffer(ByteBuffer buffer)
- {
- throw new NotImplementedException();
- }
-
- protected override void WriteValueImpl(object value, ByteBuffer buffer)
- {
- throw new NotImplementedException();
- }
- }
-
- sealed class AMQFieldTableType : AMQType
- {
- public AMQFieldTableType() : base('F')
- {
- }
-
- public override uint GetEncodingSize(object value)
- {
- throw new NotImplementedException();
- }
-
- public override object ToNativeValue(object value)
- {
- throw new NotImplementedException();
- }
-
- public override object ReadValueFromBuffer(ByteBuffer buffer)
- {
- throw new NotImplementedException();
- }
-
- protected override void WriteValueImpl(object value, ByteBuffer buffer)
- {
- throw new NotImplementedException();
- }
- }
-
- sealed class AMQVoidType : AMQType
- {
- public AMQVoidType() : base('V')
- {
- }
-
- public override uint GetEncodingSize(object value)
- {
- return 0;
- }
-
- public override object ToNativeValue(object value)
- {
- if ( value != null )
- throw new FormatException(string.Format("Cannot convert {0} to VOID type", value));
- return null;
- }
-
- public override object ReadValueFromBuffer(ByteBuffer buffer)
- {
- return null;
- }
-
- protected override void WriteValueImpl(object value, ByteBuffer buffer)
- {
- }
- }
-
- // Extended Types
-
- sealed class AMQBinaryType : AMQType
- {
- public AMQBinaryType() : base('x')
- {
- }
-
- public override uint GetEncodingSize(object value)
- {
- return EncodingUtils.EncodedLongstrLength((byte[]) value);
- }
-
- public override object ToNativeValue(object value)
- {
- if ( value is byte[] || value == null )
- {
- return value;
- }
- throw new ArgumentException("Value cannot be converted to byte[]");
- }
-
- public override object ReadValueFromBuffer(ByteBuffer buffer)
- {
- return EncodingUtils.ReadLongstr(buffer);
- }
-
- protected override void WriteValueImpl(object value, ByteBuffer buffer)
- {
- EncodingUtils.WriteLongstr(buffer, (byte[])value);
- }
- }
-
- sealed class AMQAsciiStringType : AMQType
- {
- public AMQAsciiStringType() : base('c')
- {
- }
-
- public override uint GetEncodingSize(object value)
- {
- return EncodingUtils.EncodedAsciiStringLength((string)value);
- }
-
- public override object ToNativeValue(object value)
- {
- if ( value == null )
- throw new ArgumentNullException("value");
- return value.ToString();
- }
-
- public override object ReadValueFromBuffer(ByteBuffer buffer)
- {
- return EncodingUtils.ReadAsciiString(buffer);
- }
-
- protected override void WriteValueImpl(object value, ByteBuffer buffer)
- {
- EncodingUtils.WriteAsciiString(buffer, (string)value);
- }
- }
-
- sealed class AMQWideStringType : AMQType
- {
- // todo: Change encoding to UTF16 (java code still uses default
- // ascii encoding for wide strings
- private static readonly Encoding ENCODING = Encoding.ASCII;
-
- public AMQWideStringType()
- : base('C')
- {
- }
-
- public override uint GetEncodingSize(object value)
- {
- return EncodingUtils.EncodedLongStringLength((string)value, ENCODING);
- }
-
- public override object ToNativeValue(object value)
- {
- if ( value == null )
- throw new ArgumentNullException("value");
- return value.ToString();
- }
-
- public override object ReadValueFromBuffer(ByteBuffer buffer)
- {
- return EncodingUtils.ReadLongString(buffer, ENCODING);
- }
-
- protected override void WriteValueImpl(object value, ByteBuffer buffer)
- {
- EncodingUtils.WriteLongStringBytes(buffer, (string)value, ENCODING);
- }
- }
-
- sealed class AMQBooleanType : AMQType
- {
- public AMQBooleanType() : base('t')
- {
- }
-
- public override uint GetEncodingSize(object value)
- {
- return EncodingUtils.EncodedBooleanLength();
- }
-
- public override object ToNativeValue(object value)
- {
- return Convert.ToBoolean(value);
- }
-
- public override object ReadValueFromBuffer(ByteBuffer buffer)
- {
- return EncodingUtils.ReadBoolean(buffer);
- }
-
- protected override void WriteValueImpl(object value, ByteBuffer buffer)
- {
- EncodingUtils.WriteBoolean(buffer, (bool)value);
- }
- }
-
- sealed class AMQAsciiCharType : AMQType
- {
- public AMQAsciiCharType() : base('k')
- {
- }
-
- public override uint GetEncodingSize(object value)
- {
- return EncodingUtils.EncodedCharLength();
- }
-
- public override object ToNativeValue(object value)
- {
- return Convert.ToChar(value);
- }
-
- public override object ReadValueFromBuffer(ByteBuffer buffer)
- {
- return EncodingUtils.ReadChar(buffer);
- }
-
- protected override void WriteValueImpl(object value, ByteBuffer buffer)
- {
- EncodingUtils.WriteChar(buffer, (char)value);
- }
- }
-
- sealed class AMQByteType : AMQType
- {
- public AMQByteType() : base('B')
- {
- }
-
- public override uint GetEncodingSize(object value)
- {
- return EncodingUtils.EncodedByteLength();
- }
-
- public override object ToNativeValue(object value)
- {
- return Convert.ToByte(value);
- }
-
- public override object ReadValueFromBuffer(ByteBuffer buffer)
- {
- return EncodingUtils.ReadByte(buffer);
- }
-
- protected override void WriteValueImpl(object value, ByteBuffer buffer)
- {
- EncodingUtils.WriteByte(buffer, (byte)value);
- }
- }
-
- sealed class AMQSByteType : AMQType
- {
- public AMQSByteType()
- : base('b')
- {
- }
-
- public override uint GetEncodingSize(object value)
- {
- return EncodingUtils.EncodedSByteLength();
- }
-
- public override object ToNativeValue(object value)
- {
- return Convert.ToSByte(value);
- }
-
- public override object ReadValueFromBuffer(ByteBuffer buffer)
- {
- return EncodingUtils.ReadSByte(buffer);
- }
-
- protected override void WriteValueImpl(object value, ByteBuffer buffer)
- {
- EncodingUtils.WriteSByte(buffer, (sbyte)value);
- }
- }
-
- sealed class AMQInt16Type : AMQType
- {
- public AMQInt16Type() : base('s')
- {
- }
-
- public override uint GetEncodingSize(object value)
- {
- return EncodingUtils.EncodedShortLength();
- }
-
- public override object ToNativeValue(object value)
- {
- return Convert.ToInt16(value);
- }
-
- public override object ReadValueFromBuffer(ByteBuffer buffer)
- {
- return EncodingUtils.ReadShort(buffer);
- }
-
- protected override void WriteValueImpl(object value, ByteBuffer buffer)
- {
- EncodingUtils.WriteShort(buffer, (short)value);
- }
- }
-
- sealed class AMQUInt16Type : AMQType
- {
- public AMQUInt16Type()
- : base('S')
- {
- }
-
- public override uint GetEncodingSize(object value)
- {
- return EncodingUtils.EncodedUnsignedShortLength();
- }
-
- public override object ToNativeValue(object value)
- {
- return Convert.ToUInt16(value);
- }
-
- public override object ReadValueFromBuffer(ByteBuffer buffer)
- {
- return EncodingUtils.ReadUnsignedShort(buffer);
- }
-
- protected override void WriteValueImpl(object value, ByteBuffer buffer)
- {
- EncodingUtils.WriteUnsignedShort(buffer, (ushort)value);
- }
- }
-
- sealed class AMQInt32Type : AMQType
- {
- public AMQInt32Type() : base('I')
- {
- }
-
- public override uint GetEncodingSize(object value)
- {
- return EncodingUtils.EncodedIntegerLength();
- }
-
- public override object ToNativeValue(object value)
- {
- return Convert.ToInt32(value);
- }
-
- public override object ReadValueFromBuffer(ByteBuffer buffer)
- {
- return EncodingUtils.ReadInteger(buffer);
- }
-
- protected override void WriteValueImpl(object value, ByteBuffer buffer)
- {
- EncodingUtils.WriteInteger(buffer, (int)value);
- }
- }
-
- sealed class AMQInt64Type : AMQType
- {
- public AMQInt64Type() : base('l')
- {
- }
-
- public override uint GetEncodingSize(object value)
- {
- return EncodingUtils.EncodedLongLength();
- }
-
- public override object ToNativeValue(object value)
- {
- return Convert.ToInt64(value);
- }
-
- public override object ReadValueFromBuffer(ByteBuffer buffer)
- {
- return EncodingUtils.ReadLong(buffer);
- }
-
- protected override void WriteValueImpl(object value, ByteBuffer buffer)
- {
- EncodingUtils.WriteLong(buffer, (long)value);
- }
- }
-
- sealed class AMQUInt64Type : AMQType
- {
- public AMQUInt64Type()
- : base('L')
- {
- }
-
- public override uint GetEncodingSize(object value)
- {
- return EncodingUtils.EncodedUnsignedLongLength();
- }
-
- public override object ToNativeValue(object value)
- {
- return Convert.ToUInt64(value);
- }
-
- public override object ReadValueFromBuffer(ByteBuffer buffer)
- {
- return EncodingUtils.ReadUnsignedLong(buffer);
- }
-
- protected override void WriteValueImpl(object value, ByteBuffer buffer)
- {
- EncodingUtils.WriteUnsignedLong(buffer, (ulong)value);
- }
- }
-
- sealed class AMQFloatType : AMQType
- {
- public AMQFloatType() : base('f')
- {
- }
-
- public override uint GetEncodingSize(object value)
- {
- return EncodingUtils.EncodedFloatLength();
- }
-
- public override object ToNativeValue(object value)
- {
- return Convert.ToSingle(value);
- }
-
- public override object ReadValueFromBuffer(ByteBuffer buffer)
- {
- return EncodingUtils.ReadFloat(buffer);
- }
-
- protected override void WriteValueImpl(object value, ByteBuffer buffer)
- {
- EncodingUtils.WriteFloat(buffer, (float)value);
- }
- }
-
- sealed class AMQDoubleType : AMQType
- {
- public AMQDoubleType() : base('d')
- {
- }
-
- public override uint GetEncodingSize(object value)
- {
- return EncodingUtils.EncodedDoubleLength();
- }
-
- public override object ToNativeValue(object value)
- {
- return Convert.ToDouble(value);
- }
-
- public override object ReadValueFromBuffer(ByteBuffer buffer)
- {
- return EncodingUtils.ReadDouble(buffer);
- }
-
- protected override void WriteValueImpl(object value, ByteBuffer buffer)
- {
- EncodingUtils.WriteDouble(buffer, (double)value);
- }
- }
-
- #endregion // Type Implementation
-
- } // class AMQType
-}
+/* + * + * 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. + * + */ +using System; +using System.Text; +using Apache.Qpid.Buffer; + +namespace Apache.Qpid.Framing +{ + /// <summary> + /// Base class for the Field Table Type system. + /// Ported over from the Java AMQType enumeration + /// </summary> + public abstract class AMQType + { + private byte _identifier; + + /// <summary> + /// Type code identifier for this type + /// </summary> + public byte Identifier + { + get { return _identifier; } + } + + protected AMQType(char identifier) + { + _identifier = (byte)identifier; + } + + /// <summary> + /// Create a new <see cref="AMQTypedValue"/> instance + /// </summary> + /// <param name="value">Value to initialize with</param> + /// <returns>A new typed value instance</returns> + public AMQTypedValue AsTypedValue(object value) + { + return new AMQTypedValue(this, ToNativeValue(value)); + } + + /// <summary> + /// Write the specified value to the buffer using the encoding + /// specified for this type + /// </summary> + /// <param name="value">Value to write</param> + /// <param name="buffer">Buffer to write to</param> + public void WriteToBuffer(object value, ByteBuffer buffer) + { + buffer.Put(Identifier); + WriteValueImpl(value, buffer); + } + + public override string ToString() + { + return ((Char) Identifier).ToString(); + } + + /// <summary> + /// Get the encoding size for the specified value in this type format + /// </summary> + /// <param name="value">Value to find encoded size for</param> + /// <returns>The encoded size</returns> + public abstract uint GetEncodingSize(object value); + /// <summary> + /// Convert the specified value to this type + /// </summary> + /// <param name="value">Value to convert</param> + /// <returns>The converted value</returns> + public abstract object ToNativeValue(object value); + + /// <summary> + /// Read a value from the specified buffer using the encoding for + /// this type + /// </summary> + /// <param name="buffer">Buffer to read from</param> + /// <returns>The value read</returns> + public abstract object ReadValueFromBuffer(ByteBuffer buffer); + + protected abstract void WriteValueImpl(Object value, ByteBuffer buffer); + + + #region Known Types + // + // Known Types + // + + // long string is not defined in the proposed specification, + // and the 'S' discriminator is left for unsigned short (16-bit) values + public static readonly AMQType LONG_STRING = new AMQLongStringType(); + public static readonly AMQType UINT32 = new AMQUInt32Type(); + public static readonly AMQType DECIMAL = new AMQDecimalType(); + public static readonly AMQType TIMESTAMP = new AMQTimeStampType(); + public static readonly AMQType FIELD_TABLE = new AMQFieldTableType(); + public static readonly AMQType VOID = new AMQVoidType(); + public static readonly AMQType BINARY = new AMQBinaryType(); + public static readonly AMQType ASCII_STRING = new AMQAsciiStringType(); + public static readonly AMQType WIDE_STRING = new AMQWideStringType(); + public static readonly AMQType BOOLEAN = new AMQBooleanType(); + public static readonly AMQType ASCII_CHARACTER = new AMQAsciiCharType(); + public static readonly AMQType BYTE = new AMQByteType(); + public static readonly AMQType SBYTE = new AMQSByteType(); + public static readonly AMQType INT16 = new AMQInt16Type(); + public static readonly AMQType UINT16 = new AMQUInt16Type(); + public static readonly AMQType INT32 = new AMQInt32Type(); + public static readonly AMQType INT64 = new AMQInt64Type(); + public static readonly AMQType UINT64 = new AMQUInt64Type(); + public static readonly AMQType FLOAT = new AMQFloatType(); + public static readonly AMQType DOUBLE = new AMQDoubleType(); + + #endregion // Known Types + + #region Type Implementation + // + // Type Implementation + // + + sealed class AMQLongStringType : AMQType + { + public AMQLongStringType() : base('S') + { + } + + public override uint GetEncodingSize(object value) + { + return EncodingUtils.EncodedLongStringLength((string) value); + } + + public override object ToNativeValue(object value) + { + if ( value == null ) + throw new ArgumentNullException("value"); + return value.ToString(); + } + + public override object ReadValueFromBuffer(ByteBuffer buffer) + { + return EncodingUtils.ReadLongString(buffer); + } + + protected override void WriteValueImpl(object value, ByteBuffer buffer) + { + EncodingUtils.WriteLongStringBytes(buffer, (string) value); + } + + } + + sealed class AMQUInt32Type : AMQType + { + public AMQUInt32Type() : base('i') + { + } + + public override uint GetEncodingSize(object value) + { + return EncodingUtils.UnsignedIntegerLength(); + } + + public override object ToNativeValue(object value) + { + return Convert.ToUInt32(value); + } + + public override object ReadValueFromBuffer(ByteBuffer buffer) + { + return EncodingUtils.ReadUnsignedInteger(buffer); + } + + protected override void WriteValueImpl(object value, ByteBuffer buffer) + { + EncodingUtils.WriteUnsignedInteger(buffer, (uint) value); + } + + } + + sealed class AMQDecimalType : AMQType + { + public AMQDecimalType() : base('D') + { + } + + public override uint GetEncodingSize(object value) + { + throw new NotImplementedException(); + } + + public override object ToNativeValue(object value) + { + throw new NotImplementedException(); + } + + public override object ReadValueFromBuffer(ByteBuffer buffer) + { + throw new NotImplementedException(); + } + + protected override void WriteValueImpl(object value, ByteBuffer buffer) + { + throw new NotImplementedException(); + } + } + + sealed class AMQTimeStampType : AMQType + { + public AMQTimeStampType() : base('T') + { + } + + public override uint GetEncodingSize(object value) + { + throw new NotImplementedException(); + } + + public override object ToNativeValue(object value) + { + throw new NotImplementedException(); + } + + public override object ReadValueFromBuffer(ByteBuffer buffer) + { + throw new NotImplementedException(); + } + + protected override void WriteValueImpl(object value, ByteBuffer buffer) + { + throw new NotImplementedException(); + } + } + + sealed class AMQFieldTableType : AMQType + { + public AMQFieldTableType() : base('F') + { + } + + public override uint GetEncodingSize(object value) + { + throw new NotImplementedException(); + } + + public override object ToNativeValue(object value) + { + throw new NotImplementedException(); + } + + public override object ReadValueFromBuffer(ByteBuffer buffer) + { + throw new NotImplementedException(); + } + + protected override void WriteValueImpl(object value, ByteBuffer buffer) + { + throw new NotImplementedException(); + } + } + + sealed class AMQVoidType : AMQType + { + public AMQVoidType() : base('V') + { + } + + public override uint GetEncodingSize(object value) + { + return 0; + } + + public override object ToNativeValue(object value) + { + if ( value != null ) + throw new FormatException(string.Format("Cannot convert {0} to VOID type", value)); + return null; + } + + public override object ReadValueFromBuffer(ByteBuffer buffer) + { + return null; + } + + protected override void WriteValueImpl(object value, ByteBuffer buffer) + { + } + } + + // Extended Types + + sealed class AMQBinaryType : AMQType + { + public AMQBinaryType() : base('x') + { + } + + public override uint GetEncodingSize(object value) + { + return EncodingUtils.EncodedLongstrLength((byte[]) value); + } + + public override object ToNativeValue(object value) + { + if ( value is byte[] || value == null ) + { + return value; + } + throw new ArgumentException("Value cannot be converted to byte[]"); + } + + public override object ReadValueFromBuffer(ByteBuffer buffer) + { + return EncodingUtils.ReadLongstr(buffer); + } + + protected override void WriteValueImpl(object value, ByteBuffer buffer) + { + EncodingUtils.WriteLongstr(buffer, (byte[])value); + } + } + + sealed class AMQAsciiStringType : AMQType + { + public AMQAsciiStringType() : base('c') + { + } + + public override uint GetEncodingSize(object value) + { + return EncodingUtils.EncodedAsciiStringLength((string)value); + } + + public override object ToNativeValue(object value) + { + if ( value == null ) + throw new ArgumentNullException("value"); + return value.ToString(); + } + + public override object ReadValueFromBuffer(ByteBuffer buffer) + { + return EncodingUtils.ReadAsciiString(buffer); + } + + protected override void WriteValueImpl(object value, ByteBuffer buffer) + { + EncodingUtils.WriteAsciiString(buffer, (string)value); + } + } + + sealed class AMQWideStringType : AMQType + { + // todo: Change encoding to UTF16 (java code still uses default + // ascii encoding for wide strings + private static readonly Encoding ENCODING = Encoding.ASCII; + + public AMQWideStringType() + : base('C') + { + } + + public override uint GetEncodingSize(object value) + { + return EncodingUtils.EncodedLongStringLength((string)value, ENCODING); + } + + public override object ToNativeValue(object value) + { + if ( value == null ) + throw new ArgumentNullException("value"); + return value.ToString(); + } + + public override object ReadValueFromBuffer(ByteBuffer buffer) + { + return EncodingUtils.ReadLongString(buffer, ENCODING); + } + + protected override void WriteValueImpl(object value, ByteBuffer buffer) + { + EncodingUtils.WriteLongStringBytes(buffer, (string)value, ENCODING); + } + } + + sealed class AMQBooleanType : AMQType + { + public AMQBooleanType() : base('t') + { + } + + public override uint GetEncodingSize(object value) + { + return EncodingUtils.EncodedBooleanLength(); + } + + public override object ToNativeValue(object value) + { + return Convert.ToBoolean(value); + } + + public override object ReadValueFromBuffer(ByteBuffer buffer) + { + return EncodingUtils.ReadBoolean(buffer); + } + + protected override void WriteValueImpl(object value, ByteBuffer buffer) + { + EncodingUtils.WriteBoolean(buffer, (bool)value); + } + } + + sealed class AMQAsciiCharType : AMQType + { + public AMQAsciiCharType() : base('k') + { + } + + public override uint GetEncodingSize(object value) + { + return EncodingUtils.EncodedCharLength(); + } + + public override object ToNativeValue(object value) + { + return Convert.ToChar(value); + } + + public override object ReadValueFromBuffer(ByteBuffer buffer) + { + return EncodingUtils.ReadChar(buffer); + } + + protected override void WriteValueImpl(object value, ByteBuffer buffer) + { + EncodingUtils.WriteChar(buffer, (char)value); + } + } + + sealed class AMQByteType : AMQType + { + public AMQByteType() : base('B') + { + } + + public override uint GetEncodingSize(object value) + { + return EncodingUtils.EncodedByteLength(); + } + + public override object ToNativeValue(object value) + { + return Convert.ToByte(value); + } + + public override object ReadValueFromBuffer(ByteBuffer buffer) + { + return EncodingUtils.ReadByte(buffer); + } + + protected override void WriteValueImpl(object value, ByteBuffer buffer) + { + EncodingUtils.WriteByte(buffer, (byte)value); + } + } + + sealed class AMQSByteType : AMQType + { + public AMQSByteType() + : base('b') + { + } + + public override uint GetEncodingSize(object value) + { + return EncodingUtils.EncodedSByteLength(); + } + + public override object ToNativeValue(object value) + { + return Convert.ToSByte(value); + } + + public override object ReadValueFromBuffer(ByteBuffer buffer) + { + return EncodingUtils.ReadSByte(buffer); + } + + protected override void WriteValueImpl(object value, ByteBuffer buffer) + { + EncodingUtils.WriteSByte(buffer, (sbyte)value); + } + } + + sealed class AMQInt16Type : AMQType + { + public AMQInt16Type() : base('s') + { + } + + public override uint GetEncodingSize(object value) + { + return EncodingUtils.EncodedShortLength(); + } + + public override object ToNativeValue(object value) + { + return Convert.ToInt16(value); + } + + public override object ReadValueFromBuffer(ByteBuffer buffer) + { + return EncodingUtils.ReadShort(buffer); + } + + protected override void WriteValueImpl(object value, ByteBuffer buffer) + { + EncodingUtils.WriteShort(buffer, (short)value); + } + } + + sealed class AMQUInt16Type : AMQType + { + public AMQUInt16Type() + : base('S') + { + } + + public override uint GetEncodingSize(object value) + { + return EncodingUtils.EncodedUnsignedShortLength(); + } + + public override object ToNativeValue(object value) + { + return Convert.ToUInt16(value); + } + + public override object ReadValueFromBuffer(ByteBuffer buffer) + { + return EncodingUtils.ReadUnsignedShort(buffer); + } + + protected override void WriteValueImpl(object value, ByteBuffer buffer) + { + EncodingUtils.WriteUnsignedShort(buffer, (ushort)value); + } + } + + sealed class AMQInt32Type : AMQType + { + public AMQInt32Type() : base('I') + { + } + + public override uint GetEncodingSize(object value) + { + return EncodingUtils.EncodedIntegerLength(); + } + + public override object ToNativeValue(object value) + { + return Convert.ToInt32(value); + } + + public override object ReadValueFromBuffer(ByteBuffer buffer) + { + return EncodingUtils.ReadInteger(buffer); + } + + protected override void WriteValueImpl(object value, ByteBuffer buffer) + { + EncodingUtils.WriteInteger(buffer, (int)value); + } + } + + sealed class AMQInt64Type : AMQType + { + public AMQInt64Type() : base('l') + { + } + + public override uint GetEncodingSize(object value) + { + return EncodingUtils.EncodedLongLength(); + } + + public override object ToNativeValue(object value) + { + return Convert.ToInt64(value); + } + + public override object ReadValueFromBuffer(ByteBuffer buffer) + { + return EncodingUtils.ReadLong(buffer); + } + + protected override void WriteValueImpl(object value, ByteBuffer buffer) + { + EncodingUtils.WriteLong(buffer, (long)value); + } + } + + sealed class AMQUInt64Type : AMQType + { + public AMQUInt64Type() + : base('L') + { + } + + public override uint GetEncodingSize(object value) + { + return EncodingUtils.EncodedUnsignedLongLength(); + } + + public override object ToNativeValue(object value) + { + return Convert.ToUInt64(value); + } + + public override object ReadValueFromBuffer(ByteBuffer buffer) + { + return EncodingUtils.ReadUnsignedLong(buffer); + } + + protected override void WriteValueImpl(object value, ByteBuffer buffer) + { + EncodingUtils.WriteUnsignedLong(buffer, (ulong)value); + } + } + + sealed class AMQFloatType : AMQType + { + public AMQFloatType() : base('f') + { + } + + public override uint GetEncodingSize(object value) + { + return EncodingUtils.EncodedFloatLength(); + } + + public override object ToNativeValue(object value) + { + return Convert.ToSingle(value); + } + + public override object ReadValueFromBuffer(ByteBuffer buffer) + { + return EncodingUtils.ReadFloat(buffer); + } + + protected override void WriteValueImpl(object value, ByteBuffer buffer) + { + EncodingUtils.WriteFloat(buffer, (float)value); + } + } + + sealed class AMQDoubleType : AMQType + { + public AMQDoubleType() : base('d') + { + } + + public override uint GetEncodingSize(object value) + { + return EncodingUtils.EncodedDoubleLength(); + } + + public override object ToNativeValue(object value) + { + return Convert.ToDouble(value); + } + + public override object ReadValueFromBuffer(ByteBuffer buffer) + { + return EncodingUtils.ReadDouble(buffer); + } + + protected override void WriteValueImpl(object value, ByteBuffer buffer) + { + EncodingUtils.WriteDouble(buffer, (double)value); + } + } + + #endregion // Type Implementation + + } // class AMQType +} diff --git a/dotnet/Qpid.Common/Framing/AMQTypeMap.cs b/dotnet/Qpid.Common/Framing/AMQTypeMap.cs index ed38c203a9..8497c283f9 100644 --- a/dotnet/Qpid.Common/Framing/AMQTypeMap.cs +++ b/dotnet/Qpid.Common/Framing/AMQTypeMap.cs @@ -1,75 +1,75 @@ -/*
- *
- * 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.
- *
- */
-using System;
-using System.Collections;
-
-namespace Apache.Qpid.Framing
-{
- public sealed class AMQTypeMap
- {
- private static Hashtable _reverseTypeMap;
-
- private AMQTypeMap()
- {
- }
-
- static AMQTypeMap()
- {
- _reverseTypeMap = Hashtable.Synchronized(new Hashtable());
-
- Add(AMQType.LONG_STRING);
- Add(AMQType.BOOLEAN);
- Add(AMQType.BYTE);
- Add(AMQType.SBYTE);
- Add(AMQType.INT16);
- // not supported for now as type code conflicts
- // with LONG_STRING
- //Add(AMQType.UINT16);
- Add(AMQType.INT32);
- Add(AMQType.UINT32);
- Add(AMQType.INT64);
- Add(AMQType.UINT64);
- Add(AMQType.FLOAT);
- Add(AMQType.DOUBLE);
- Add(AMQType.DECIMAL);
- Add(AMQType.BINARY);
- Add(AMQType.ASCII_STRING);
- Add(AMQType.WIDE_STRING);
- Add(AMQType.ASCII_CHARACTER);
- Add(AMQType.TIMESTAMP);
- Add(AMQType.FIELD_TABLE);
- Add(AMQType.VOID);
- }
-
- public static AMQType GetType(byte identifier)
- {
- AMQType type = (AMQType)_reverseTypeMap[identifier];
- if ( type == null )
- throw new ArgumentOutOfRangeException(string.Format("No such type code: {0:x}", identifier));
- return type;
- }
-
- private static void Add(AMQType type)
- {
- _reverseTypeMap.Add(type.Identifier, type);
- }
- }
-}
+/* + * + * 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. + * + */ +using System; +using System.Collections; + +namespace Apache.Qpid.Framing +{ + public sealed class AMQTypeMap + { + private static Hashtable _reverseTypeMap; + + private AMQTypeMap() + { + } + + static AMQTypeMap() + { + _reverseTypeMap = Hashtable.Synchronized(new Hashtable()); + + Add(AMQType.LONG_STRING); + Add(AMQType.BOOLEAN); + Add(AMQType.BYTE); + Add(AMQType.SBYTE); + Add(AMQType.INT16); + // not supported for now as type code conflicts + // with LONG_STRING + //Add(AMQType.UINT16); + Add(AMQType.INT32); + Add(AMQType.UINT32); + Add(AMQType.INT64); + Add(AMQType.UINT64); + Add(AMQType.FLOAT); + Add(AMQType.DOUBLE); + Add(AMQType.DECIMAL); + Add(AMQType.BINARY); + Add(AMQType.ASCII_STRING); + Add(AMQType.WIDE_STRING); + Add(AMQType.ASCII_CHARACTER); + Add(AMQType.TIMESTAMP); + Add(AMQType.FIELD_TABLE); + Add(AMQType.VOID); + } + + public static AMQType GetType(byte identifier) + { + AMQType type = (AMQType)_reverseTypeMap[identifier]; + if ( type == null ) + throw new ArgumentOutOfRangeException(string.Format("No such type code: {0:x}", identifier)); + return type; + } + + private static void Add(AMQType type) + { + _reverseTypeMap.Add(type.Identifier, type); + } + } +} diff --git a/dotnet/Qpid.Common/Framing/AMQTypedValue.cs b/dotnet/Qpid.Common/Framing/AMQTypedValue.cs index 8d21a60831..3d2e313fa6 100644 --- a/dotnet/Qpid.Common/Framing/AMQTypedValue.cs +++ b/dotnet/Qpid.Common/Framing/AMQTypedValue.cs @@ -1,76 +1,76 @@ -/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-using System;
-using Apache.Qpid.Buffer;
-
-namespace Apache.Qpid.Framing
-{
- public class AMQTypedValue
- {
- private readonly AMQType _type;
- private readonly object _value;
-
- public AMQType Type
- {
- get { return _type; }
- }
-
- public object Value
- {
- get { return _value; }
- }
-
- public uint EncodingLength
- {
- get { return _type.GetEncodingSize(_value); }
- }
-
- public AMQTypedValue(AMQType type, object value)
- {
- if ( type == null )
- throw new ArgumentNullException("type");
- _type = type;
- _value = type.ToNativeValue(value);
- }
-
- public AMQTypedValue(AMQType type, ByteBuffer buffer)
- {
- _type = type;
- _value = type.ReadValueFromBuffer(buffer);
- }
-
- public void WriteToBuffer(ByteBuffer buffer)
- {
- _type.WriteToBuffer(_value, buffer);
- }
-
- public static AMQTypedValue ReadFromBuffer(ByteBuffer buffer)
- {
- AMQType type = AMQTypeMap.GetType(buffer.GetByte());
- return new AMQTypedValue(type, buffer);
- }
-
- public override string ToString()
- {
- return string.Format("{0}: {1}", Type, Value);
- }
- }
-}
+/* + * + * 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. + * + */ +using System; +using Apache.Qpid.Buffer; + +namespace Apache.Qpid.Framing +{ + public class AMQTypedValue + { + private readonly AMQType _type; + private readonly object _value; + + public AMQType Type + { + get { return _type; } + } + + public object Value + { + get { return _value; } + } + + public uint EncodingLength + { + get { return _type.GetEncodingSize(_value); } + } + + public AMQTypedValue(AMQType type, object value) + { + if ( type == null ) + throw new ArgumentNullException("type"); + _type = type; + _value = type.ToNativeValue(value); + } + + public AMQTypedValue(AMQType type, ByteBuffer buffer) + { + _type = type; + _value = type.ReadValueFromBuffer(buffer); + } + + public void WriteToBuffer(ByteBuffer buffer) + { + _type.WriteToBuffer(_value, buffer); + } + + public static AMQTypedValue ReadFromBuffer(ByteBuffer buffer) + { + AMQType type = AMQTypeMap.GetType(buffer.GetByte()); + return new AMQTypedValue(type, buffer); + } + + public override string ToString() + { + return string.Format("{0}: {1}", Type, Value); + } + } +} diff --git a/dotnet/Qpid.Common/Protocol/AMQConstant.cs b/dotnet/Qpid.Common/Protocol/AMQConstant.cs index fcf94c29f4..9400b1bd80 100644 --- a/dotnet/Qpid.Common/Protocol/AMQConstant.cs +++ b/dotnet/Qpid.Common/Protocol/AMQConstant.cs @@ -1,100 +1,100 @@ -/*
- *
- * 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.
- *
- */
-using System;
-using System.Collections;
-
-namespace Apache.Qpid.Protocol
-{
- public sealed class AMQConstant
- {
- private int _code;
- private string _name;
- private static Hashtable _codeMap = new Hashtable();
-
- public int Code
- {
- get { return _code; }
- }
-
- public string Name
- {
- get { return _name; }
- }
-
- private AMQConstant(int code, string name, bool map)
- {
- _code = code;
- _name = name;
-
- if ( map )
- {
- _codeMap.Add(code, this);
- }
- }
-
- public override string ToString()
- {
- return string.Format("{0}: {1}", Code, Name);
- }
-
- public static AMQConstant GetConstant(int code)
- {
- AMQConstant c = (AMQConstant)_codeMap[code];
- if ( c == null )
- {
- c = new AMQConstant(code, "unknown code", false);
- }
- return c;
- }
-
- #region Constants
- //
- // Constants
- //
- public static readonly AMQConstant FRAME_MIN_SIZE = new AMQConstant(4096, "frame min size", true);
- public static readonly AMQConstant FRAME_END = new AMQConstant(206, "frame end", true);
- public static readonly AMQConstant REPLY_SUCCESS = new AMQConstant(200, "reply success", true);
- public static readonly AMQConstant NOT_DELIVERED = new AMQConstant(310, "not delivered", true);
- public static readonly AMQConstant MESSAGE_TOO_LARGE = new AMQConstant(311, "message too large", true);
- public static readonly AMQConstant NO_ROUTE = new AMQConstant(312, "no route", true);
- public static readonly AMQConstant NO_CONSUMERS = new AMQConstant(313, "no consumers", true);
- public static readonly AMQConstant CONTEXT_IN_USE = new AMQConstant(320, "context in use", true);
- public static readonly AMQConstant INVALID_PATH = new AMQConstant(402, "invalid path", true);
- public static readonly AMQConstant ACCESS_REFUSED = new AMQConstant(403, "access refused", true);
- public static readonly AMQConstant NOT_FOUND = new AMQConstant(404, "not found", true);
- public static readonly AMQConstant ALREADY_EXISTS = new AMQConstant(405, "already exists", true);
- public static readonly AMQConstant IN_USE = new AMQConstant(406, "in use", true);
- public static readonly AMQConstant INVALID_ROUTING_KEY = new AMQConstant(407, "routing key invalid", true);
- public static readonly AMQConstant REQUEST_TIMEOUT = new AMQConstant(408, "request timeout", true);
- public static readonly AMQConstant INVALID_ARGUMENT = new AMQConstant(409, "argument invalid", true);
- public static readonly AMQConstant FRAME_ERROR = new AMQConstant(501, "frame error", true);
- public static readonly AMQConstant SYNTAX_ERROR = new AMQConstant(502, "syntax error", true);
- public static readonly AMQConstant COMMAND_INVALID = new AMQConstant(503, "command invalid", true);
- public static readonly AMQConstant CHANNEL_ERROR = new AMQConstant(504, "channel error", true);
- public static readonly AMQConstant RESOURCE_ERROR = new AMQConstant(506, "resource error", true);
- public static readonly AMQConstant NOT_ALLOWED = new AMQConstant(530, "not allowed", true);
- public static readonly AMQConstant NOT_IMPLEMENTED = new AMQConstant(540, "not implemented", true);
- public static readonly AMQConstant INTERNAL_ERROR = new AMQConstant(541, "internal error", true);
-
- #endregion // Constants
-
- }
-}
+/* + * + * 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. + * + */ +using System; +using System.Collections; + +namespace Apache.Qpid.Protocol +{ + public sealed class AMQConstant + { + private int _code; + private string _name; + private static Hashtable _codeMap = new Hashtable(); + + public int Code + { + get { return _code; } + } + + public string Name + { + get { return _name; } + } + + private AMQConstant(int code, string name, bool map) + { + _code = code; + _name = name; + + if ( map ) + { + _codeMap.Add(code, this); + } + } + + public override string ToString() + { + return string.Format("{0}: {1}", Code, Name); + } + + public static AMQConstant GetConstant(int code) + { + AMQConstant c = (AMQConstant)_codeMap[code]; + if ( c == null ) + { + c = new AMQConstant(code, "unknown code", false); + } + return c; + } + + #region Constants + // + // Constants + // + public static readonly AMQConstant FRAME_MIN_SIZE = new AMQConstant(4096, "frame min size", true); + public static readonly AMQConstant FRAME_END = new AMQConstant(206, "frame end", true); + public static readonly AMQConstant REPLY_SUCCESS = new AMQConstant(200, "reply success", true); + public static readonly AMQConstant NOT_DELIVERED = new AMQConstant(310, "not delivered", true); + public static readonly AMQConstant MESSAGE_TOO_LARGE = new AMQConstant(311, "message too large", true); + public static readonly AMQConstant NO_ROUTE = new AMQConstant(312, "no route", true); + public static readonly AMQConstant NO_CONSUMERS = new AMQConstant(313, "no consumers", true); + public static readonly AMQConstant CONTEXT_IN_USE = new AMQConstant(320, "context in use", true); + public static readonly AMQConstant INVALID_PATH = new AMQConstant(402, "invalid path", true); + public static readonly AMQConstant ACCESS_REFUSED = new AMQConstant(403, "access refused", true); + public static readonly AMQConstant NOT_FOUND = new AMQConstant(404, "not found", true); + public static readonly AMQConstant ALREADY_EXISTS = new AMQConstant(405, "already exists", true); + public static readonly AMQConstant IN_USE = new AMQConstant(406, "in use", true); + public static readonly AMQConstant INVALID_ROUTING_KEY = new AMQConstant(407, "routing key invalid", true); + public static readonly AMQConstant REQUEST_TIMEOUT = new AMQConstant(408, "request timeout", true); + public static readonly AMQConstant INVALID_ARGUMENT = new AMQConstant(409, "argument invalid", true); + public static readonly AMQConstant FRAME_ERROR = new AMQConstant(501, "frame error", true); + public static readonly AMQConstant SYNTAX_ERROR = new AMQConstant(502, "syntax error", true); + public static readonly AMQConstant COMMAND_INVALID = new AMQConstant(503, "command invalid", true); + public static readonly AMQConstant CHANNEL_ERROR = new AMQConstant(504, "channel error", true); + public static readonly AMQConstant RESOURCE_ERROR = new AMQConstant(506, "resource error", true); + public static readonly AMQConstant NOT_ALLOWED = new AMQConstant(530, "not allowed", true); + public static readonly AMQConstant NOT_IMPLEMENTED = new AMQConstant(540, "not implemented", true); + public static readonly AMQConstant INTERNAL_ERROR = new AMQConstant(541, "internal error", true); + + #endregion // Constants + + } +} |