Example #1
0
        public IWebSocketFragment Filter(byte[] readBuffer, int offset, int length, bool toBeCopied, out int left)
        {
            if (m_Frame == null)
            {
                m_Frame = new WebSocketDataFrame(new ArraySegmentList());
            }

            this.AddArraySegment(m_Frame.InnerData, readBuffer, offset, length, toBeCopied);

            IDataFramePartReader nextPartReader;

            int thisLength = m_PartReader.Process(m_LastPartLength, m_Frame, out nextPartReader);

            if (thisLength < 0)
            {
                left = 0;
                return(null);
            }
            else
            {
                left = thisLength;

                if (left > 0)
                {
                    m_Frame.InnerData.TrimEnd(left);
                }

                //Means this part reader is the last one
                if (nextPartReader == null)
                {
                    m_LastPartLength = 0;
                    m_PartReader     = DataFramePartReader.NewReader;

                    var frame = m_Frame;
                    m_Frame = null;
                    return(frame);
                }
                else
                {
                    m_LastPartLength = m_Frame.InnerData.Count - thisLength;
                    m_PartReader     = nextPartReader;

                    return(null);
                }
            }
        }
Example #2
0
 public void Reset()
 {
     m_Frame = null;
 }
Example #3
0
 public WebSocketDataFrameReceiveFilter()
 {
     m_Frame      = new WebSocketDataFrame(new ArraySegmentList());
     m_PartReader = DataFramePartReader.NewReader;
 }