コード例 #1
0
        public static AMQPHeader Decode(IByteBuffer buf)
        {
            long length  = buf.ReadInt() & 0xffffffffL;
            int  doff    = buf.ReadByte() & 0xff;
            int  type    = buf.ReadByte() & 0xff;
            int  channel = buf.ReadShort() & 0xffff;

            // TODO check condition
            if (length == 8 && doff == 2 && (type == 0 || type == 1) && channel == 0)
            {
                if (buf.ReadableBytes == 0)
                {
                    return(new AMQPPing());
                }
                else
                {
                    throw new MalformedMessageException("Received malformed ping-header with invalid length");
                }
            }

            // PTOROCOL-HEADER
            if (length == 1095586128 && (doff == 3 || doff == 0) && type == 1 && channel == 0)
            {
                if (buf.ReadableBytes == 0)
                {
                    return(new AMQPProtoHeader(doff));
                }
                else
                {
                    throw new MalformedMessageException("Received malformed protocol-header with invalid length");
                }
            }

            if (length != buf.ReadableBytes + 8)
            {
                throw new MalformedMessageException("Received malformed header with invalid length");
            }

            AMQPHeader header = null;

            if (type == 0)
            {
                header = AMQPFactory.getAMQP(buf);
            }
            else if (type == 1)
            {
                header = AMQPFactory.getSASL(buf);
            }
            else
            {
                throw new MalformedMessageException("Received malformed header with invalid type: " + type);
            }

            header.Dott       = doff;
            header.HeaderType = type;
            header.Channel    = channel;

            if (header.Code.HasValue && header.Code.Value == HeaderCodes.TRANSFER)
            {
                List <AMQPSection> sections = new List <AMQPSection>();
                while (buf.ReadableBytes > 0)
                {
                    sections.Add(AMQPFactory.getSection(buf));
                }

                ((AMQPTransfer)header).addSections(sections.ToArray());
            }

            return(header);
        }
コード例 #2
0
        public override void fillArguments(TLVList list)
        {
            int size = list.getList().Count;

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

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

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

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

            if (size > 1)
            {
                TLVAmqp element = list.getList()[1];
                if (!element.isNull())
                {
                    _deliveryId = AMQPUnwrapper <SectionCodes> .unwrapUInt(element);
                }
            }

            if (size > 2)
            {
                TLVAmqp element = list.getList()[2];
                if (!element.isNull())
                {
                    _deliveryTag = AMQPUnwrapper <SectionCodes> .unwrapBinary(element);
                }
            }

            if (size > 3)
            {
                TLVAmqp element = list.getList()[3];
                if (!element.isNull())
                {
                    _messageFormat = new AMQPMessageFormat(AMQPUnwrapper <SectionCodes> .unwrapUInt(element));
                }
            }
            if (size > 4)
            {
                TLVAmqp element = list.getList()[4];
                if (!element.isNull())
                {
                    _settled = AMQPUnwrapper <SectionCodes> .unwrapBool(element);
                }
            }

            if (size > 5)
            {
                TLVAmqp element = list.getList()[5];
                if (!element.isNull())
                {
                    _more = AMQPUnwrapper <SectionCodes> .unwrapBool(element);
                }
            }

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

            if (size > 7)
            {
                TLVAmqp element = list.getList()[7];
                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 'STATE' - received: " + element.Code);
                    }

                    _state = AMQPFactory.getState((TLVList)element);
                    _state.fill((TLVList)element);
                }
            }

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

            if (size > 9)
            {
                TLVAmqp element = list.getList()[9];
                if (!element.isNull())
                {
                    _aborted = AMQPUnwrapper <SectionCodes> .unwrapBool(element);
                }
            }
            if (size > 10)
            {
                TLVAmqp element = list.getList()[10];
                if (!element.isNull())
                {
                    _batchable = AMQPUnwrapper <SectionCodes> .unwrapBool(element);
                }
            }
        }
コード例 #3
0
        public override void fillArguments(TLVList list)
        {
            int size = list.getList().Count;

            if (size < 2)
            {
                throw new MalformedMessageException("Received malformed Disposition header: role and first can't be null");
            }

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

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

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

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

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

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

            if (size > 2)
            {
                TLVAmqp element = list.getList()[2];
                if (!element.isNull())
                {
                    _last = AMQPUnwrapper <AMQPSymbol> .unwrapUInt(element);
                }
            }

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

            if (size > 4)
            {
                TLVAmqp element = list.getList()[4];
                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 'STATE' - received: " + element.Code);
                    }

                    _state = AMQPFactory.getState((TLVList)element);
                    _state.fill((TLVList)element);
                }
            }

            if (size > 5)
            {
                TLVAmqp element = list.getList()[5];
                if (!element.isNull())
                {
                    _batchable = AMQPUnwrapper <AMQPSymbol> .unwrapBool(element);
                }
            }
        }
コード例 #4
0
        public void fill(TLVList list)
        {
            if (list.getList().Count > 0)
            {
                TLVAmqp element = list.getList()[0];
                if (!element.isNull())
                {
                    _address = AMQPUnwrapper <AMQPSymbol> .unwrapString(element);
                }
            }
            if (list.getList().Count > 1)
            {
                TLVAmqp element = list.getList()[1];
                if (!element.isNull())
                {
                    _durable = (TerminusDurability)AMQPUnwrapper <AMQPSymbol> .unwrapUInt(element);
                }
            }
            if (list.getList().Count > 2)
            {
                TLVAmqp element = list.getList()[2];
                if (!element.isNull())
                {
                    _expiryPeriod = (TerminusExpiryPolicy)StringEnum.Parse(typeof(TerminusExpiryPolicy), AMQPUnwrapper <AMQPSymbol> .unwrapSymbol(element).Value);
                }
            }
            if (list.getList().Count > 3)
            {
                TLVAmqp element = list.getList()[3];
                if (!element.isNull())
                {
                    _timeout = AMQPUnwrapper <AMQPSymbol> .unwrapUInt(element);
                }
            }
            if (list.getList().Count > 4)
            {
                TLVAmqp element = list.getList()[4];
                if (!element.isNull())
                {
                    _dynamic = AMQPUnwrapper <AMQPSymbol> .unwrapBool(element);
                }
            }
            if (list.getList().Count > 5)
            {
                TLVAmqp element = list.getList()[5];
                if (!element.isNull())
                {
                    if (_dynamic != null)
                    {
                        if (_dynamic.Value)
                        {
                            _dynamicNodeProperties = AMQPUnwrapper <AMQPSymbol> .unwrapMap(element);
                        }
                        else
                        {
                            throw new MalformedMessageException("Received malformed Source: dynamic-node-properties can't be specified when dynamic flag is false");
                        }
                    }
                    else
                    {
                        throw new MalformedMessageException("Received malformed Source: dynamic-node-properties can't be specified when dynamic flag is not set");
                    }
                }
            }
            if (list.getList().Count > 6)
            {
                TLVAmqp element = list.getList()[6];
                if (!element.isNull())
                {
                    _distributionMode = (DistributionMode)StringEnum.Parse(typeof(DistributionMode), AMQPUnwrapper <AMQPSymbol> .unwrapSymbol(element).Value);
                }
            }
            if (list.getList().Count > 7)
            {
                TLVAmqp element = list.getList()[7];
                if (!element.isNull())
                {
                    _filter = AMQPUnwrapper <AMQPSymbol> .unwrapMap(element);
                }
            }
            if (list.getList().Count > 8)
            {
                TLVAmqp element = list.getList()[8];
                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 'OUTCOME' - received: " + element.Code);
                    }

                    _defaultOutcome = AMQPFactory.getOutcome((TLVList)element);
                    _defaultOutcome.fill((TLVList)element);
                }
            }
            if (list.getList().Count > 9)
            {
                TLVAmqp element = list.getList()[9];
                if (!element.isNull())
                {
                    _outcomes = AMQPUnwrapper <AMQPSymbol> .unwrapArray(element);
                }
            }
            if (list.getList().Count > 10)
            {
                TLVAmqp element = list.getList()[10];
                if (!element.isNull())
                {
                    _capabilities = AMQPUnwrapper <AMQPSymbol> .unwrapArray(element);
                }
            }
        }