using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace FObjBase { class Transaction { #region 成员变量 /// /// 客户端发起的 源ID /// public UInt32 SrcObjID; /// /// 通讯模块 /// public IFConn Conn; /// /// 包总大小, -1 ,大小未知 /// public int Size = -1; /// /// 数据游标:每次吐出大包后, 剩下数据的开始位置 /// public int Position = 0; /// /// 交易号, 服务器分配的 /// public UInt32 Magic; /// /// 数据 /// public byte[] Buf; /// /// callfunction 返回时, 异步回调函数 /// public object AsyncDelegate; /// /// callfunction 返回时, 异步状态 /// public object AsyncState; /// /// 动作号 /// public UInt16 InfoId; /// /// 功能号 /// public UInt16 FuncID; /// /// 大包 最大体积 /// public const UInt16 PackSize = 0x4000; #endregion public Transaction() { //Size = 0; //Position = 0; //Magic = 0; //Buf = null; } byte[] GetBuf() { int len = Buf.Length - Position; if (len > PackSize) len = PackSize; byte[] buf = new byte[len]; Array.Copy(Buf, Position, buf, 0, len); return buf; } public bool GetBigSize(out Pack_BigSize p) { p = new Pack_BigSize(); p.infoid = InfoId; p.funcid = FuncID; p.size = Size; p.position = Position; p.buf = GetBuf(); Position += p.buf.Length; if (Position == Size) return true; else return false; } public bool Reset() { Buf = null; Size = -1; Position = 0; if ((AsyncDelegate == null) && (AsyncState == null)) { return true; } return false; } /// /// 把大包解析放入数据缓存, 全部接收完,返回 true /// /// /// public bool ToBuf(Pack_BigSize p) { if (Buf == null) { InfoId = p.infoid; FuncID = p.funcid; Size = p.size; Buf = new byte[Size]; Array.Copy(p.buf, 0, Buf, p.position, p.buf.Length); Position = p.position + p.buf.Length; return false; } else { Array.Copy(p.buf, 0, Buf, p.position, p.buf.Length); Position = p.position + p.buf.Length; if (Position == Size) { return true; } return false; } } } }