RemoveFirst() 공개 메소드

public RemoveFirst ( int n ) : byte[]
n int
리턴 byte[]
        bool ProcessData()
        {
            string s         = recvBuffer.GetString(encoding);
            int    headerEnd = s.IndexOf('\n');

            if (headerEnd < 0)
            {
                return(false);
            }

            string header = s.Substring(0, headerEnd);

            if (header[0] != '#')
            {
                throw new Exception("Broken header:" + header);
            }
            var bodySize = int.Parse(header.Substring(1));

            // 헤더는 모두 0~127 아스키 문자로만 이루어지기 때문에
            // 문자열 길이로 계산했을 때와 바이트 개수로 계산했을 때의 결과가 같다.
            if (recvBuffer.Length < headerEnd + 1 + bodySize)
            {
                return(false);
            }

            recvBuffer.RemoveFirst(headerEnd + 1);
            byte[] bodyBytes = recvBuffer.RemoveFirst(bodySize);

            string body = encoding.GetString(bodyBytes);

            //MessageBox.OK(body);

            debuggeeListener.X_FromDebuggee(bodyBytes);
            return(true);
        }
예제 #2
0
        // ---- private ------------------------------------------------------------------------

        private void ProcessData()
        {
            while (true)
            {
                if (_bodyLength >= 0)
                {
                    if (_rawData.Length >= _bodyLength)
                    {
                        var buf = _rawData.RemoveFirst(_bodyLength);

                        _bodyLength = -1;
                        var str = Encoding.GetString(buf);
                        Task.Run(() => {
                            Dispatch(str);
                        }).ContinueWith(t => {
                            if (t.IsFaulted)
                            {
                                Console.WriteLine(t.Exception);
                            }
                        });

                        continue;                           // there may be more complete messages to process
                    }
                }
                else
                {
                    string s   = _rawData.GetString(Encoding);
                    var    idx = s.IndexOf(TWO_CRLF, StringComparison.Ordinal);
                    if (idx != -1)
                    {
                        Match m = CONTENT_LENGTH_MATCHER.Match(s);
                        if (m.Success && m.Groups.Count == 2)
                        {
                            _bodyLength = Convert.ToInt32(m.Groups[1].ToString());

                            _rawData.RemoveFirst(idx + TWO_CRLF.Length);

                            continue;                               // try to handle a complete message
                        }
                    }
                }
                break;
            }
        }
예제 #3
0
        bool ProcessData(ref ByteBuffer recvBuffer)
        {
            string s         = recvBuffer.GetString(encoding);
            int    headerEnd = s.IndexOf('\n');

            if (headerEnd < 0)
            {
                return(false);
            }

            string header = s.Substring(0, headerEnd);

            if (header[0] != '#')
            {
                throw new Exception("Broken header:" + header);
            }
            var bodySize = int.Parse(header.Substring(1));

            // Because the headers are all 0 - 127 ASCII characters only
                        // The results are the same when calculated as string length and as number of bytes.
            if (recvBuffer.Length < headerEnd + 1 + bodySize)
            {
                return(false);
            }

            recvBuffer.RemoveFirst(headerEnd + 1);
            byte[] bodyBytes = recvBuffer.RemoveFirst(bodySize);

            string body = encoding.GetString(bodyBytes);

            //MessageBox.OK(body);

            if (debuglogProtocol)
            {
                Utilities.LogMessageToFile(" < " + body);
            }
            debuggeeListener.VSDebuggeeMessage(this, bodyBytes);
            return(true);
        }
예제 #4
0
        // ---- private ------------------------------------------------------------------------

        private void ProcessData()
        {
            while (true)
            {
                if (_bodyLength >= 0)
                {
                    if (_rawData.Length >= _bodyLength)
                    {
                        var buf = _rawData.RemoveFirst(_bodyLength);

                        _bodyLength = -1;

                        Dispatch(Encoding.GetString(buf));

                        continue; // there may be more complete messages to process
                    }
                }
                else
                {
                    string s   = _rawData.GetString(Encoding);
                    var    idx = s.IndexOf(TWO_CRLF);
                    if (idx != -1)
                    {
                        Match m = CONTENT_LENGTH_MATCHER.Match(s);
                        if (m.Success && m.Groups.Count == 2)
                        {
                            _bodyLength = Convert.ToInt32(m.Groups[1].ToString());

                            _rawData.RemoveFirst(idx + TWO_CRLF.Length);

                            continue; // try to handle a complete message
                        }
                    }
                }

                break;
            }
        }