Exemplo n.º 1
0
        public void Accept(byte[] bytes)
        {
            var bytesToRead = _remainingBytes.Concat(bytes).ToArray();

            while (!_currentStateWorker.Done && bytesToRead.Length > 0)
            {
                var worker    = _currentStateWorker;
                var bytesRead = _currentStateWorker.Accept(bytesToRead);

                bytesToRead     = bytesToRead.Skip(bytesRead).ToArray();
                _remainingBytes = bytesToRead;

                if (worker.Done)
                {
                    worker.ApplyContent(ref _content);

                    var next = worker.NextWorker;
                    if (next != null)
                    {
                        _currentStateWorker = next;
                    }
                    else
                    {
                        _messages.Enqueue(_content);
                        ResetStateWorker();
                    }
                }
                else
                {
                    Debug.Assert(bytesToRead.Length <= bytesRead);
                }
            }
        }
Exemplo n.º 2
0
            protected void FlagAsDone(FeedStateWorker next = null)
            {
                Debug.Assert(next != this);

                if (next != null)
                {
                    next.Reset();
                }

                Done       = true;
                NextWorker = next;
            }
Exemplo n.º 3
0
 protected void ResetStateWorker()
 {
     _currentStateWorker = _initialStateFactory();
     _content            = new MessageContent();
 }