public ResponseInfo Dispatch(byte[] buffer) { buffer = this.spack.unpack(buffer); PackageType.Package package = new PackageType.Package(); int offset = package.init(buffer); int session = (int)package.session; int tag; if (!this.sessionDictionary.TryGetValue(session, out tag)) { tag = (int)package.type; ResponseInfo info1; info1.Obj = ProtocolFunctionDictionary.GenRequest(tag, buffer, offset); info1.Session = (int)package.session; info1.Tag = tag; return(info1); //throw new Exception ("Unknown session: " + session); } else { this.sessionDictionary.Remove(session); } ResponseInfo info; info.Obj = ProtocolFunctionDictionary.GenResponse(tag, buffer, offset); info.Session = (int)package.session; info.Tag = tag; return(info); }
public RequestInfo Dispatch(byte[] buffer) { buffer = this.spack.unpack(buffer); PackageType.Package package = new PackageType.Package(); int offset = package.init(buffer); int tag = (int)package.type; ProtocolFunctionDictionary.ProtocolInfo pinfo = ProtocolFunctionDictionary.GetProtocolInfo(tag); RequestInfo info; info.Tag = tag; info.Obj = ProtocolFunctionDictionary.GenRequest((int)package.type, buffer, offset); info.Session = (int)package.session; if (pinfo.Response == null) { info.Response = null; } else { info.Response = delegate(SprotoProtocolBase protocol) { if (pinfo.Response != protocol.GetResponse().GetType()) { throw new Exception("response type: " + protocol.GetType().ToString() + " not is expected. [" + pinfo.Response.ToString() + "]"); } this.stream.Seek(0, System.IO.SeekOrigin.Begin); PackageType.Package pkg = new PackageType.Package(); pkg.session = package.session; pkg.encode(this.stream); protocol.GetResponse().encode(this.stream); int len = stream.Position; byte[] data = new byte[len]; stream.Seek(0, System.IO.SeekOrigin.Begin); stream.Read(data, 0, len); return(this.spack.pack(data)); }; } return(info); }