Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:VDFParser.Machines.VDFSM"/> class.
        /// </summary>
        public VDFSM()
        {
            entries   = new List <VDFEntry>();
            tmpBuffer = new List <byte>();
            mainState = MainSMState.IndexBeginIndicator;

            arraySM  = new VDFIndexedArraySM();
            fieldsSM = new VDFFieldsSM();
        }
Exemple #2
0
        /// <summary>
        /// Feeds a given byte to the SM
        /// </summary>
        /// <param name="b">Incoming byte to be fed to the SM</param>
        public void Feed(byte b)
        {
            switch (mainState)
            {
            case MainSMState.IndexBeginIndicator:
                if (b == 0x00)
                {
                    Flush();
                    mainState = MainSMState.IndexValue;
                    tmpBuffer.Clear();
                    fieldsSM.Reset();
                }
                break;

            case MainSMState.IndexValue:
                if (b == 0x00)      // Okay, next would be IndexEndIndicator,
                                    // but the terminator is also the separator,
                                    // and things would get messy. Let's just
                                    // skip a whole SM step here and pretend
                                    // everything is fine.
                {
                    int indexResult;
                    if (int.TryParse(tmpBuffer.StringFromByteArray(), out indexResult))
                    {
                        currentEntry       = new VDFEntry();
                        currentEntry.Index = indexResult;
                        mainState          = MainSMState.Fields;
                    }

                    // The next is necessary to satisfy the SM pattern.
                    fieldsSM.Feed(b);
                    break;
                }
                tmpBuffer.Add(b);
                break;

            case MainSMState.Fields:
                if (fieldsSM.Feed(b))
                {
                    foreach (KeyValuePair <string, byte[]> k in fieldsSM.Fields)
                    {
                        FillEntry(k.Key, k.Value);
                    }
                    mainState = MainSMState.IndexBeginIndicator;
                }
                break;
            }
        }