Exemple #1
0
        public static TLVFixed wrapLong(long l)
        {
            byte[]   value = convertLong(l);
            AMQPType code  = value.Length > 1 ? AMQPType.LONG : AMQPType.SMALL_LONG;

            return(new TLVFixed(code, value));
        }
Exemple #2
0
        public static TLVFixed wrapInt(int i)
        {
            byte[]   value = convertInt(i);
            AMQPType code  = value.Length > 1 ? AMQPType.INT : AMQPType.SMALL_INT;

            return(new TLVFixed(code, value));
        }
Exemple #3
0
        public static TLVFixed wrapULong(BigInteger l)
        {
            if (l == null)
            {
                throw new ArgumentException("Wrapper cannot wrap ulong null");
            }
            if (l < BigInteger.Zero)
            {
                throw new ArgumentException("negative value of " + l + " cannot be assignet to ULONG type");
            }
            byte[]   value = convertULong(l);
            AMQPType code  = AMQPType.NULL;

            if (value.Length == 0)
            {
                code = AMQPType.ULONG_0;
            }
            else if (value.Length == 1)
            {
                code = AMQPType.SMALL_ULONG;
            }
            else
            {
                code = AMQPType.ULONG;
            }
            return(new TLVFixed(code, value));
        }
Exemple #4
0
        public static TLVFixed wrapBool(Boolean b)
        {
            byte[]   value = new byte[0];
            AMQPType code  = b ? AMQPType.BOOLEAN_TRUE : AMQPType.BOOLEAN_FALSE;

            return(new TLVFixed(code, value));
        }
        public static TLVFixed wrapUInt(long i)
        {
            if (i < 0)
            {
                throw new ArgumentException("negative value of " + i + " cannot be assignet to UINT type");
            }
            byte[]   value = convertUInt(i);
            AMQPType code  = AMQPType.NULL;

            if (value.Length == 0)
            {
                code = AMQPType.UINT_0;
            }
            else if (value.Length == 1)
            {
                code = AMQPType.SMALL_UINT;
            }
            else if (value.Length > 1)
            {
                code = AMQPType.UINT;
            }

            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(value);
            }

            return(new TLVFixed(code, value));
        }
        public static String unwrapString(TLVAmqp tlv)
        {
            AMQPType code = tlv.Code;

            if (code != AMQPType.STRING_8 && code != AMQPType.STRING_32)
            {
                throw new ArgumentException(new DateTime() + ": " + "Error trying to parse STRING: received " + code);
            }
            return(Encoding.UTF8.GetString(tlv.getValue()));
        }
        public static AMQPDecimal unwrapDecimal(TLVAmqp tlv)
        {
            AMQPType code = tlv.Code;

            if (code != AMQPType.DECIMAL_32 && code != AMQPType.DECIMAL_64 && code != AMQPType.DECIMAL_128)
            {
                throw new ArgumentException(new DateTime() + ": " + "Error trying to parse DECIMAL: received " + tlv.Code);
            }

            return(new AMQPDecimal(tlv.getValue()));
        }
 public TLVList(AMQPType code, List <TLVAmqp> elements) : base(new SimpleConstructor(code))
 {
     this.elements = elements;
     _width        = code == AMQPType.LIST_8 ? 1 : 4;
     _size        += _width;
     foreach (TLVAmqp tlv in elements)
     {
         _size += tlv.getLength();
     }
     _count = elements.Count;
 }
        public static byte[] unwrapBinary(TLVAmqp tlv)
        {
            AMQPType code = tlv.Code;

            if (code != AMQPType.BINARY_8 && code != AMQPType.BINARY_32)
            {
                throw new ArgumentException(new DateTime() + ": " + "Error trying to parse BINARY: received " + code);
            }

            return(tlv.getValue());
        }
Exemple #10
0
        public static TLVVariable wrapBinary(byte[] b)
        {
            if (b == null)
            {
                throw new ArgumentException("Wrapper cannot wrap binary null");
            }

            AMQPType code = b.Length > 255 ? AMQPType.BINARY_32 : AMQPType.BINARY_8;

            return(new TLVVariable(code, b));
        }
Exemple #11
0
        public static TLVVariable wrapSymbol(AMQPSymbol symbol)
        {
            if (symbol == null)
            {
                throw new ArgumentException("Wrapper cannot wrap null symbol");
            }

            byte[]   value = Encoding.ASCII.GetBytes(symbol.Value);
            AMQPType code  = value.Length > 255 ? AMQPType.SYMBOL_32 : AMQPType.SYMBOL_8;

            return(new TLVVariable(code, value));
        }
Exemple #12
0
        public static TLVVariable wrapString(String s)
        {
            if (s == null)
            {
                throw new ArgumentException("Wrapper cannot wrap null String");
            }

            byte[]   value = Encoding.UTF8.GetBytes(s);
            AMQPType code  = value.Length > 255 ? AMQPType.STRING_32 : AMQPType.STRING_8;

            return(new TLVVariable(code, value));
        }
        public static TLVFixed wrapLong(long l)
        {
            byte[]   value = convertLong(l);
            AMQPType code  = value.Length > 1 ? AMQPType.LONG : AMQPType.SMALL_LONG;

            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(value);
            }

            return(new TLVFixed(code, value));
        }
        public static TLVFixed wrapInt(int i)
        {
            byte[]   value = convertInt(i);
            AMQPType code  = value.Length > 1 ? AMQPType.INT : AMQPType.SMALL_INT;

            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(value);
            }

            return(new TLVFixed(code, value));
        }
Exemple #15
0
        public TLVMap(AMQPType code, Dictionary <TLVAmqp, TLVAmqp> map) : base(new SimpleConstructor(code))
        {
            this.map = map;
            _width   = code == AMQPType.MAP_8 ? 1 : 4;
            _size   += _width;
            foreach (KeyValuePair <TLVAmqp, TLVAmqp> entry in map)
            {
                _size += entry.Key.getLength();
                _size += entry.Value.getLength();
            }

            _count = map.Count;
        }
Exemple #16
0
        public override void fillArguments(TLVList list)
        {
            int size = list.getList().Count;

            if (size == 0)
            {
                throw new MalformedMessageException("Received malformed Detach header: handle can't be null");
            }

            if (size > 3)
            {
                throw new MalformedMessageException("Received malformed Detach header. Invalid number of arguments: " + size);
            }

            if (size > 0)
            {
                TLVAmqp element = list.getList()[0];
                if (element.isNull())
                {
                    throw new MalformedMessageException("Received malformed Detach header: handle can't be null");
                }

                _handle = AMQPUnwrapper <AMQPSymbol> .unwrapUInt(element);
            }

            if (size > 1)
            {
                TLVAmqp element = list.getList()[1];
                if (!element.isNull())
                {
                    _closed = AMQPUnwrapper <AMQPSymbol> .unwrapBool(element);
                }
            }

            if (size > 2)
            {
                TLVAmqp element = list.getList()[2];
                if (!element.isNull())
                {
                    AMQPType code = element.Code;
                    if (code != AMQPType.LIST_0 && code != AMQPType.LIST_8 && code != AMQPType.LIST_32)
                    {
                        throw new MalformedMessageException("Expected type 'ERROR' - received: " + element.Code);
                    }

                    _error = new AMQPError();
                    _error.fill((TLVList)element);
                }
            }
        }
        public TLVArray(AMQPType code, List <TLVAmqp> elements) : base(new SimpleConstructor(code))
        {
            this.elements = elements;
            _width        = code == AMQPType.ARRAY_8 ? 1 : 4;
            _size        += _width;
            foreach (TLVAmqp element in elements)
            {
                _size += element.getLength() - element.Constructor.getLength();
                if (elementConstructor == null && element != null)
                {
                    elementConstructor = element.Constructor;
                }
            }

            _size += elementConstructor.getLength();
            _count = elements.Count;
        }
        public new Boolean isNull()
        {
            AMQPType code = Constructor.Code;

            if (code == AMQPType.NULL)
            {
                return(true);
            }
            if (code == AMQPType.ARRAY_8 || code == AMQPType.ARRAY_32)
            {
                if (elements.Count == 0)
                {
                    return(true);
                }
            }
            return(false);
        }
        public static List <T> unwrapArray(TLVAmqp tlv)
        {
            AMQPType code = tlv.Code;

            if (code != AMQPType.ARRAY_8 && code != AMQPType.ARRAY_32)
            {
                throw new ArgumentException(new DateTime() + ": " + "Error trying to parse ARRAY: received " + tlv.Code);
            }

            List <T> result = new List <T>();

            foreach (TLVAmqp element in ((TLVArray)tlv).getElements())
            {
                result.Add((T)unwrap(element));
            }
            return(result);
        }
Exemple #20
0
        public void fill(TLVList list)
        {
            if (list.getList().Count > 0)
            {
                TLVAmqp element = list.getList()[0];
                if (!element.isNull())
                {
                    AMQPType code = element.Code;
                    if (code != AMQPType.LIST_0 && code != AMQPType.LIST_8 && code != AMQPType.LIST_32)
                    {
                        throw new ArgumentException("Expected type 'ERROR' - received: " + element.Code);
                    }

                    _error = new AMQPError();
                    _error.fill((TLVList)element);
                }
            }
        }
        public static Dictionary <T, Object> unwrapMap(TLVAmqp tlv)
        {
            AMQPType code = tlv.Code;

            if (code != AMQPType.MAP_8 && code != AMQPType.MAP_32)
            {
                throw new ArgumentException(new DateTime() + ": " + "Error trying to parse MAP: received " + tlv.Code);
            }
            Dictionary <T, Object> result = new Dictionary <T, Object>();

            foreach (KeyValuePair <TLVAmqp, TLVAmqp> entry in ((TLVMap)tlv).getMap())
            {
                T      key   = (T)unwrap(entry.Key);
                Object value = unwrap(entry.Value);
                result[key] = value;
            }
            return(result);
        }
        public static List <Object> unwrapList(TLVAmqp tlv)
        {
            AMQPType code = tlv.Code;

            if (code != AMQPType.LIST_0 && code != AMQPType.LIST_8 && code != AMQPType.LIST_32)
            {
                throw new ArgumentException(new DateTime() + ": " + "Error trying to parse LIST: received " + tlv.Code);
            }

            List <Object> result = new List <Object>();

            foreach (TLVAmqp value in ((TLVList)tlv).getList())
            {
                result.Add(unwrap(value));
            }

            return(result);
        }
        private static SimpleConstructor getConstructor(IByteBuffer buf)
        {
            AMQPType          code        = AMQPType.NULL;
            SimpleConstructor constructor = null;
            byte codeByte = buf.ReadByte();

            if (codeByte == 0)
            {
                TLVAmqp descriptor = getTlv(buf);
                code        = (AMQPType)(buf.ReadByte() & 0x0ff);
                constructor = new DescribedConstructor(code, descriptor);
            }
            else
            {
                code        = (AMQPType)(codeByte & 0x0ff);
                constructor = new SimpleConstructor(code);
            }
            return(constructor);
        }
        public static long unwrapUInt(TLVAmqp tlv)
        {
            AMQPType code = tlv.Code;

            if (code != AMQPType.UINT && code != AMQPType.SMALL_UINT && code != AMQPType.UINT_0)
            {
                throw new ArgumentException(new DateTime() + ": " + "Error trying to parse UINT: received " + code);
            }

            byte[] value = tlv.getValue();
            if (value.Length == 0)
            {
                return(0);
            }

            if (value.Length == 1)
            {
                return(tlv.getValue()[0] & 0x00ff);
            }

            return(BitConverter.ToUInt32(tlv.getValue(), 0) & 0x00ffffffffL);
        }
        public static int unwrapInt(TLVAmqp tlv)
        {
            AMQPType code = tlv.Code;

            if (code != AMQPType.INT && code != AMQPType.SMALL_INT)
            {
                throw new ArgumentException(new DateTime() + ": " + "Error trying to parse INT: received " + code);
            }

            byte[] value = tlv.getValue();
            if (value.Length == 0)
            {
                return(0);
            }

            if (value.Length == 1)
            {
                return(tlv.getValue()[0]);
            }

            return(BitConverter.ToInt32(tlv.getValue(), 0));
        }
        public static Int64 unwrapLong(TLVAmqp tlv)
        {
            AMQPType code = tlv.Code;

            if (code != AMQPType.LONG && code != AMQPType.SMALL_LONG)
            {
                throw new ArgumentException(new DateTime() + ": " + "Error trying to parse LONG: received " + code);
            }
            byte[] value = tlv.getValue();

            if (value.Length == 0)
            {
                return(0L);
            }

            if (value.Length == 1)
            {
                return((long)tlv.getValue()[0]);
            }

            return(BitConverter.ToInt64(tlv.getValue(), 0));
        }
        public static BigInteger unwrapULong(TLVAmqp tlv)
        {
            AMQPType code = tlv.Code;

            if (code != AMQPType.ULONG && code != AMQPType.SMALL_ULONG && code != AMQPType.ULONG_0)
            {
                throw new ArgumentException(new DateTime() + ": " + "Error trying to parse ULONG: received " + code);
            }

            byte[] value = tlv.getValue();

            if (value.Length == 0)
            {
                return(new BigInteger(0));
            }

            if (value.Length == 1)
            {
                return(new BigInteger(tlv.getValue()[0] & 0xff));
            }

            return(new BigInteger(BitConverter.ToUInt64(tlv.getValue(), 0)));
        }
        public override void fillArguments(TLVList list)
        {
            int size = list.getList().Count;

            if (size < 3)
            {
                throw new MalformedMessageException("Received malformed Attach header: mandatory " + "fields name, handle and role must not be null");
            }

            if (size > 14)
            {
                throw new MalformedMessageException("Received malformed Attach header. Invalid number of arguments: " + size);
            }

            if (size > 0)
            {
                TLVAmqp element = list.getList()[0];
                if (element.isNull())
                {
                    throw new MalformedMessageException("Received malformed Attach header: name can't be null");
                }

                _name = AMQPUnwrapper <AMQPSymbol> .unwrapString(element);
            }

            if (size > 1)
            {
                TLVAmqp element = list.getList()[1];
                if (element.isNull())
                {
                    throw new MalformedMessageException("Received malformed Attach header: handle can't be null");
                }

                _handle = AMQPUnwrapper <AMQPSymbol> .unwrapUInt(element);
            }

            if (size > 2)
            {
                TLVAmqp element = list.getList()[2];
                if (element.isNull())
                {
                    throw new MalformedMessageException("Received malformed Attach header: role can't be null");
                }

                Boolean value = AMQPUnwrapper <AMQPSymbol> .unwrapBool(element);

                if (value)
                {
                    _role = RoleCodes.RECEIVER;
                }
                else
                {
                    _role = RoleCodes.SENDER;
                }
            }

            if (size > 3)
            {
                TLVAmqp element = list.getList()[3];
                if (!element.isNull())
                {
                    _sndSettleMode = (SendCodes)AMQPUnwrapper <AMQPSymbol> .unwrapUByte(element);
                }
            }

            if (size > 4)
            {
                TLVAmqp element = list.getList()[4];
                if (!element.isNull())
                {
                    _rcvSettleMode = (ReceiveCodes)AMQPUnwrapper <AMQPSymbol> .unwrapUByte(element);
                }
            }

            if (size > 5)
            {
                TLVAmqp element = list.getList()[5];
                if (!element.isNull())
                {
                    AMQPType code = element.Code;
                    if (code != AMQPType.LIST_0 && code != AMQPType.LIST_8 && code != AMQPType.LIST_32)
                    {
                        throw new MalformedMessageException("Expected type SOURCE - received: " + element.Code);
                    }

                    _source = new AMQPSource();
                    _source.fill((TLVList)element);
                }
            }

            if (size > 6)
            {
                TLVAmqp element = list.getList()[6];
                if (!element.isNull())
                {
                    AMQPType code = element.Code;
                    if (code != AMQPType.LIST_0 && code != AMQPType.LIST_8 && code != AMQPType.LIST_32)
                    {
                        throw new MalformedMessageException("Expected type TARGET - received: " + element.Code);
                    }

                    _target = new AMQPTarget();
                    _target.fill((TLVList)element);
                }
            }

            if (size > 7)
            {
                TLVAmqp unsettledMap = list.getList()[7];
                if (!unsettledMap.isNull())
                {
                    _unsettled = AMQPUnwrapper <AMQPSymbol> .unwrapMap(unsettledMap);
                }
            }

            if (size > 8)
            {
                TLVAmqp element = list.getList()[8];
                if (!element.isNull())
                {
                    _incompleteUnsettled = AMQPUnwrapper <AMQPSymbol> .unwrapBool(element);
                }
            }

            if (size > 9)
            {
                TLVAmqp element = list.getList()[9];
                if (!element.isNull())
                {
                    _initialDeliveryCount = AMQPUnwrapper <AMQPSymbol> .unwrapUInt(element);
                }
                else if (_role == RoleCodes.SENDER)
                {
                    throw new MalformedMessageException("Received an attach header with a null initial-delivery-count");
                }
            }

            if (size > 10)
            {
                TLVAmqp element = list.getList()[10];
                if (!element.isNull())
                {
                    _maxMessageSize = AMQPUnwrapper <AMQPSymbol> .unwrapULong(element);
                }
            }

            if (size > 11)
            {
                TLVAmqp element = list.getList()[11];
                if (!element.isNull())
                {
                    _offeredCapabilities = AMQPUnwrapper <AMQPSymbol> .unwrapArray(element);
                }
            }

            if (size > 12)
            {
                TLVAmqp element = list.getList()[12];
                if (!element.isNull())
                {
                    _desiredCapabilities = AMQPUnwrapper <AMQPSymbol> .unwrapArray(element);
                }
            }

            if (size > 13)
            {
                TLVAmqp element = list.getList()[13];
                if (!element.isNull())
                {
                    _properties = AMQPUnwrapper <AMQPSymbol> .unwrapMap(element);
                }
            }
        }
 public SimpleConstructor(AMQPType code)
 {
     this._code = code;
 }
 public TLVVariable(AMQPType code, byte[] value) : base(new SimpleConstructor(code))
 {
     this._value = value;
     _width      = _value.Length > 255 ? 4 : 1;
 }