internal static NetMsg GenNetMsg(int len) { if (len < 0) { return(null); } int capacity = 0; int cap = 1024; int capacityIndex = -1; for (int i = 0, count = sizes.Count; i < count; i++) { cap = sizes[i]; if (cap >= len) { capacity = cap; capacityIndex = i; break; } } if (capacity == 0) { return(null); } SecurityQueue <NetMsg> idle = idlePool[capacityIndex]; NetMsg msg; bool re = idle.Dequeue(out msg); if (!re) { msg = new NetMsg(); msg.init_data(capacity); } return(msg); }
public DeserializeData Deserialize(byte[] datas, int dataLen) { DeserializeData result = null; if (datas != null) { using (MemoryStream memoryStream = new MemoryStream(datas, 0, dataLen)) using (BinaryReader binaryReader = new BinaryReader(memoryStream)) { byte tID = binaryReader.ReadByte(); int bodyLength = binaryReader.ReadInt32(); if (!littleEnd) { bodyLength = bodyLength.SwapInt32(); } byte gID = binaryReader.ReadByte(); byte uID = binaryReader.ReadByte(); if (Config.Detail_Debug_Log()) { Debug.Log("---------net adapter deserialize msg data->" + dataLen + "^" + (bodyLength + NetUtils.MSG_HEADER_LEN)); } if (dataLen == (bodyLength + NetUtils.MSG_HEADER_LEN)) { result = new DeserializeData(); NetMsg msg = NetMsgPool.GenNetMsg(bodyLength); if (msg == null) { Debugger.LogError("net adapter gen net msg failed->" + bodyLength); return(null); } msg.set_tgu(tID, gID, uID); if (Config.Detail_Debug_Log()) { Debug.LogError("deserialize msg t g u->" + tID + "^" + gID + "^" + uID + "^" + bodyLength); } msg.copy_data(datas, NetUtils.MSG_HEADER_LEN, bodyLength); result.data = msg; if (gID <= NetUtils.SCRIPTTOP_GROUP) { #if JSSCRIPT sb.Remove(0, sb.Length); //sb.Append(protoNumber.ToString()); sb.Append(gID); sb.Append(">"); sb.Append(uID); sb.Append(">"); sb.Append(Convert.ToBase64String(rawBytes)); // util.Log.Log(sb.ToString()); result = new DeserializationData() { Data = sb.ToString(), toScript = true, gID = gID, uID = uID //protoNumber = protoNumber }; #elif LUASCRIPT result.toScript = true; #endif } else { result.toScript = false; } } } } return(result); }