public override void fillArguments(TLVList list)
        {
            int size = list.getList().Count;

            if (size == 0)
            {
                throw new MalformedMessageException("Received malformed SASL-Init header: mechanism can't be null");
            }

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

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

                _mechanism = AMQPUnwrapper <AMQPSymbol> .unwrapSymbol(element);
            }

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

            if (size > 2)
            {
                TLVAmqp element = list.getList()[2];
                if (!element.isNull())
                {
                    _hostName = AMQPUnwrapper <AMQPSymbol> .unwrapString(element);
                }
            }
        }
        public void ProcessSASLMechanism(List <AMQPSymbol> _mechanisms, int channel, int headerType)
        {
            AMQPSymbol plainMechanism = null;

            foreach (AMQPSymbol mechanism in _mechanisms)
            {
                if (mechanism.Value.ToLower() == "plain")
                {
                    plainMechanism = mechanism;
                    break;
                }
            }

            //currently supporting only plain
            if (plainMechanism == null)
            {
                _timers.StopAllTimers();
                _client.Shutdown();
                SetState(ConnectionState.CONNECTION_FAILED);
                return;
            }

            SASLInit saslInit = new SASLInit();

            saslInit.HeaderType = headerType;
            saslInit.Channel    = channel;
            saslInit.Mechanism  = plainMechanism.Value;

            byte[] userBytes     = Encoding.UTF8.GetBytes(_username);
            byte[] passwordBytes = Encoding.UTF8.GetBytes(_password);
            byte[] challenge     = new byte[userBytes.Length + 1 + userBytes.Length + 1 + passwordBytes.Length];
            Array.Copy(userBytes, 0, challenge, 0, userBytes.Length);
            challenge[userBytes.Length] = 0x00;
            Array.Copy(userBytes, 0, challenge, userBytes.Length + 1, userBytes.Length);
            challenge[userBytes.Length + 1 + userBytes.Length] = 0x00;
            Array.Copy(passwordBytes, 0, challenge, userBytes.Length + 1 + userBytes.Length + 1, passwordBytes.Length);

            saslInit.InitialResponse = challenge;
            _client.Send(saslInit);
        }