Exemple #1
0
        public static LineBuffer Pop()
        {
            LineBuffer buffer = null;

            if (!LineBUfferPool.TryPop(out buffer))
            {
                return(new LineBuffer());
            }
            buffer.Reset();
            return(buffer);
        }
Exemple #2
0
        internal bool Import(byte[] data, int offset, int count)
        {
            offset += mImportOffset;
            count  -= mImportOffset;
            while (count > 0)
            {
                if (mHeader == null)
                {
                    if (mLineBuffer.Import(data, ref offset, ref count))
                    {
                        mHeader = mLineBuffer.GetLineString();
                        if (mHeader[0] == '+')
                        {
                            ResultData = mHeader.Substring(1, mHeader.Length - 1);
                            return(true);
                        }
                        else if (mHeader[0] == '-')
                        {
                            throw new Exception(mHeader.Substring(1, mHeader.Length - 1));
                        }
                        else if (mHeader[0] == '$')
                        {
                            mResultCount = 1;
                            mSingle      = true;
                            mItemLength  = int.Parse(mHeader.Substring(1, mHeader.Length - 1));
                        }
                        else if (mHeader[0] == '*')
                        {
                            mResultCount = int.Parse(mHeader.Substring(1, mHeader.Length - 1));
                            mSingle      = false;
                        }
                        else if (mHeader[0] == ':')
                        {
                            ResultData = mHeader.Substring(1, mHeader.Length - 1);
                            return(true);
                        }
                        else
                        {
                            throw new Exception(string.Format("header error:{0}", mHeader));
                        }
                        ResultDataBlock = new List <ArraySegment <byte> >(mResultCount);
                        mLineBuffer.Reset();
                    }
                }
                if (mResultCount == 0)
                {
                    break;
                }
                mValidLength = true;
                //if (mItemLength == 0 && mResultCount >0)
                if (!mSingle && mResultCount > 0 && mReadCompleted)
                {
                    mValidLength = mLineBuffer.Import(data, ref offset, ref count);
                    if (mValidLength)
                    {
                        string line;
                        try
                        {
                            line        = mLineBuffer.GetLineString();
                            mItemLength = int.Parse(line.Substring(1, line.Length - 3));
                            mLineBuffer.Reset();
                        }
                        catch (Exception e_)
                        {
                            throw e_;
                        }
                    }
                }
                if (mValidLength)
                {
                    LoadData(data, ref offset, ref count);
                }
            }

            if (count < 0)
            {
                mImportOffset = Math.Abs(count);
            }
            else
            {
                mImportOffset = 0;
            }
            return(mItemLength == 0 && mResultCount == 0);
        }