网络数据处理缓冲区和缓冲池实现

  • 时间:
  • 浏览:0

            Data = new byte[length];

            mCount = count;

public class DataBuffer : IDisposable

            }

            {

        }

        public byte[] Data;

        internal int mCount = 0;

            mPostion += end;

        private int mPostion = 0;

        private int mLength;

            else

            {

                Array.Copy(data, index, Data, mPostion, count);

        public ArraySegment<byte> GetSegment()

            mCount = data.Length;

        {

        {

        }

            if (mPostion + count > mCount)

            mPostion = 0;

            }

                mPostion = 0;

        public int Write(byte[] data, int index)

            return result;

            return count;

        {

            Data = data;

            int end = count;

                mCount += count;

            mPostion = 0;

        {

                mCount = 0;

        }

            mLength = data.Length;

            {

            }

            set;

            return new ArraySegment<byte>(Data, 0, mCount);

        }

        {

        }

            {

        public DataBuffer(byte[] data)

            if (Pool != null)

        {

            ArraySegment<byte> result= new ArraySegment<byte>(Data, mPostion, end);

                mPostion += count;

        public int Write(byte[] data)

        public void Dispose()

            mPostion = 0;

            Seek(0);

        public DataBuffer(int length)

        }

        }

        }

            return Write(data, 0);

        {

        public void Seek()

    {

                count = data.Length - index;

        internal BufferPool Pool

        {

        {

            mLength = length;

        {

        }

            Array.Copy(source, index, Data, 0, count);

        public void From(Array source, int index, int count)

    }

        public ArraySegment<byte> Read(int count)

                count = mLength - mPostion;

        public void Seek(int postion)

            if (mPostion + (data.Length-index) > mLength)

        {

        }

            get;

                end = mCount - mPostion;

            if (count > 0)

                Pool.Push(this);

            int count = 0;

            }

        }