//====================================== // Copyright (C) 2014-2015 xkMob Technology Co., Ltd. // All rights reserved // // filename :CircleBuffer.cs // description : //====================================== using System; using System.Collections; public class CircleBuffer { public static int MAX_RECEIVE_BUFFER_SIZE = 1024 * 2 * 1024; // 32k public int Length { get; internal set; } public byte[] DataBuffer { get; internal set; } public int LeftSpaceSize { get { return MAX_RECEIVE_BUFFER_SIZE - Length; } } public CircleBuffer() { DataBuffer = new byte[MAX_RECEIVE_BUFFER_SIZE]; //Offset = 0; Length = 0; } public void Enlarge(int bufLength) { //Helpers.DebugAssert(Length + bufLength <= MAX_RECEIVE_BUFFER_SIZE); //if(Length + bufLength > SocketMgr.MAX_RECEIVE_BUFFER_SIZE) // Debug.LogError("CircleBuffer Enlarge Out of Range "); //Array.Copy(buf, 0, DataBuffer, Length, bufLength); Length += bufLength; } public void Shrink(int size) { if (size >= Length) Length = 0; else { Array.Copy(DataBuffer, size, DataBuffer, 0, Length - size); Length -= size; } } }