示例#1
0
        public override ParseResult ContinuePopulate(byte a_byte)
        {
            try
            {
                switch (m_state)
                {
                case State.Done:
                    m_state = State.Failed;
                    return(ParseResult.Failed);

                case State.WaitForNextListElement:
                    var res = m_actElement.ContinuePopulate(a_byte);
                    switch (res)
                    {
                    case ParseResult.Failed:
                        m_elements = null;
                        m_state    = State.Failed;
                        return(ParseResult.Failed);

                    case ParseResult.Done:
                        m_elements[m_nbElementsRead] = m_actElement.EndPopulate();
                        m_nbElementsRead++;
                        if (m_tl.NbListElements == m_nbElementsRead)
                        {
                            m_state = State.Done;
                            return(ParseResult.Done);
                        }
                        m_actElement = new SmlTypeLengthField(m_encoding);
                        m_actElement.BeginPopulate();
                        return(ParseResult.MoreBytesNeeded);

                    default:
                        return(res);
                    }

                default:
                    return(ParseResult.Failed);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                m_state = State.Failed;
                return(ParseResult.Failed);
            }
        }
示例#2
0
        public SmlList(SmlTypeLengthField a_typeLengthField, Encoding a_encoding)
        {
            m_state    = State.WaitForNextListElement;
            m_encoding = a_encoding;

            if (a_typeLengthField == null)
            {
                throw (new ArgumentNullException());
            }

            m_tl = a_typeLengthField;
            if (a_typeLengthField.SmlFieldType != SmlFieldType.List)
            {
                m_state = State.Failed;
            }
            else
            {
                m_nbElementsRead = 0;
                m_actElement     = new SmlTypeLengthField(m_encoding);
                m_actElement.BeginPopulate();
                m_elements = new SmlBase[m_tl.NbListElements];
                m_state    = State.WaitForNextListElement;
            }
        }
示例#3
0
        internal ParseResult CreateParseResult()
        {
            ParseResult res = ParseResult.Failed;

            switch (m_type)
            {
            case SmlFieldType.EndOfMessage:
                m_parseResult = s_eom;
                res           = ParseResult.Done;
                break;

            case SmlFieldType.Optional:
                m_parseResult = s_optional;
                res           = ParseResult.Done;
                break;

            case SmlFieldType.Boolean:
                m_parseResult = new SmlBool(this);
                res           = m_parseResult.BeginPopulate();
                break;

            case SmlFieldType.Signed8:
                m_parseResult = new SmlSigned8(this);
                res           = m_parseResult.BeginPopulate();
                break;

            case SmlFieldType.Signed16:
                m_parseResult = new SmlSigned16(this);
                res           = m_parseResult.BeginPopulate();
                break;

            case SmlFieldType.Signed32:
                m_parseResult = new SmlSigned32(this);
                res           = m_parseResult.BeginPopulate();
                break;

            case SmlFieldType.Signed64:
                m_parseResult = new SmlSigned64(this);
                res           = m_parseResult.BeginPopulate();
                break;

            case SmlFieldType.Unsigned8:
                m_parseResult = new SmlUnsigned8(this);
                res           = m_parseResult.BeginPopulate();
                break;

            case SmlFieldType.Unsigned16:
                m_parseResult = new SmlUnsigned16(this);
                res           = m_parseResult.BeginPopulate();
                break;

            case SmlFieldType.Unsigned32:
                m_parseResult = new SmlUnsigned32(this);
                res           = m_parseResult.BeginPopulate();
                break;

            case SmlFieldType.Unsigned64:
                m_parseResult = new SmlUnsigned64(this);
                res           = m_parseResult.BeginPopulate();
                break;

            case SmlFieldType.String:
                m_parseResult = new SmlString(this, m_encoding);
                res           = m_parseResult.BeginPopulate();
                break;

            case SmlFieldType.List:
                m_parseResult = new SmlList(this, m_encoding);
                res           = m_parseResult.BeginPopulate();
                break;
            }

            switch (res)
            {
            case ParseResult.Failed:
                m_state = State.Failed;
                break;

            case ParseResult.Done:
                m_state = State.Done;
                break;

            default:
                m_state = State.ForewardToResult;
                break;
            }
            return(res);
        }