Ejemplo n.º 1
0
        // EndTemp

        /// <summary>
        /// parse the byte array as a data stream containing a sequence of SCS control
        /// functions. ( text data is a
        /// </summary>
        /// <param name="InputArray"></param>
        /// <returns></returns>
        public static Tuple <ControlFunctionList, string> ParseDataStream(InputByteArray InputArray)
        {
            ControlFunctionList funcList = null;
            string errmsg = null;

            while (InputArray.IsEof() == false)
            {
                // check for IAC EOR
                var telCode = InputArray.PeekTelnetCommandCode(CommandCode.EOR);
                if (telCode != null)
                {
                    break;
                }

                var func = ControlFunction.Factory(InputArray);
                if ((func == null) || (func.Errmsg != null))
                {
                    errmsg = "invalid control function. Postion:" + InputArray.Index +
                             " invalid bytes:" + InputArray.PeekToEnd().Head(16).ToHex(' ');
                    break;
                }

                if (funcList == null)
                {
                    funcList = new ControlFunctionList();
                }
                funcList.Add(func);
            }

            return(new Tuple <ControlFunctionList, string>(funcList, errmsg));
        }