private object defaultUnpackMsg(USocket s, MemoryStream buffer) { object ret = null; long oldPos = buffer.Position; long tatalLen = buffer.Length; long needLen = B2InputStream.readInt(buffer); if (needLen <= 0 || needLen > __maxLen) { // 网络Number据错误。断isOpen网络 outofLine(s, false); s.close(); return(null); } long usedLen = buffer.Position; if (usedLen + needLen <= tatalLen) { ret = B2InputStream.readObject(buffer); } else { //说明长度不够 buffer.Position = oldPos; } return(ret); }
public static void readFullyBIO2Length(Stream ns) { int len = B2InputStream.readInt(ns); byte[] b = new byte[len]; readFully(ns, b); }
// bio to int public static int bio2Int(byte[] buff) { if (buff == null) { return(0); } MemoryStream ms = null; try { if (buff == null) { return(0); } ms = msPool.borrowObject(""); ms.Write(buff, 0, buff.Length); ms.Position = 0; int ret = B2InputStream.readInt(ms); msPool.returnObject(ms); return(ret); } catch (System.Exception e) { //Debug.LogError (e); if (ms != null) { msPool.returnObject(ms); } return(0); } }
/// <summary> /// Parses the recived data.解析接收的数据,解析成功后发送给dispatcher /// </summary> /// <returns>The recived data.</returns> /// <param name="buffer">Buffer.</param> public virtual object parseRecivedData(MemoryStream buffer) { object ret = null; long oldPos = buffer.Position; buffer.Position = 0; long tatolLen = buffer.Length; long needLen = B2InputStream.readInt(buffer); if (needLen <= 0 || needLen > __maxLen) { // 网络Number据错误。断isOpen网络 outofLine(this.socket, false); //this.stop(); return(null); } long usedLen = buffer.Position; if (usedLen + needLen <= tatolLen) { ret = B2InputStream.readObject(buffer); } else { //说明长度不够 buffer.Position = oldPos; } return(ret); }