private void RetrunResultData(ReturnResult result) { using (MemoryStream stream = new MemoryStream()) { BinaryWriter bufflist = new BinaryWriter(stream); if (EncodingHandler != null) { bufflist.Write(CmdDef.ReturnResult); byte[] classdata = BufferFormat.SerializeObject(result); bufflist.Write(classdata.Length); bufflist.Write(classdata); byte[] fdata = EncodingHandler(stream.ToArray()); stream.Position = 0; stream.SetLength(0); bufflist.Write(0); bufflist.Write(fdata); } else { bufflist.Write(0); bufflist.Write(CmdDef.ReturnResult); byte[] classdata = BufferFormat.SerializeObject(result); bufflist.Write(classdata.Length); bufflist.Write(classdata); } int l = (int)(stream.Length); byte[] data = BufferFormat.GetSocketBytes(l); stream.Position = 0; bufflist.Write(data); byte[] pdata = stream.ToArray(); #if !COREFX stream.Close(); #endif stream.Dispose(); SendData(pdata); } }
public ResultAwatier CR(int cmdTag, params object[] args) { CallPack buffer = new CallPack() { Id = Common.MakeID, CmdTag = cmdTag, Arguments = new List <byte[]>(args.Length) }; foreach (var item in args) { Type type = item.GetType(); buffer.Arguments.Add(Serialization.PackSingleObject(type, item)); } using (MemoryStream stream = new MemoryStream()) { BinaryWriter bufflist = new BinaryWriter(stream); if (CCloudClient.EncodingHandler != null) { bufflist.Write(CmdDef.CallCmd); byte[] classdata = BufferFormat.SerializeObject(buffer); bufflist.Write(classdata.Length); bufflist.Write(classdata); byte[] fdata = CCloudClient.EncodingHandler(stream.ToArray()); stream.Position = 0; stream.SetLength(0); bufflist.Write(0); bufflist.Write(fdata); } else { bufflist.Write(0); bufflist.Write(CmdDef.CallCmd); byte[] classdata = BufferFormat.SerializeObject(buffer); bufflist.Write(classdata.Length); bufflist.Write(classdata); } int l = (int)(stream.Length); byte[] data = BufferFormat.GetSocketBytes(l); stream.Position = 0; bufflist.Write(data); byte[] pdata = stream.ToArray(); #if !COREFX stream.Close(); #endif stream.Dispose(); CCloudClient.AddAsyncCallBack(this, buffer.Id); if (CallSend != null) { CallSend(pdata); } } return(fiber.Read()); }
public ReturnResult CR(int cmdTag, params object[] args) { CallPack buffer = new CallPack() { Id = Common.MakeID, CmdTag = cmdTag, Arguments = new List <byte[]>(args.Length) }; foreach (var item in args) { Type type = item.GetType(); buffer.Arguments.Add(Serialization.PackSingleObject(type, item)); } using (MemoryStream stream = new MemoryStream()) { BinaryWriter bufflist = new BinaryWriter(stream); if (dataExtra != null) { bufflist.Write(CmdDef.CallCmd); byte[] classdata = BufferFormat.SerializeObject(buffer); bufflist.Write(classdata.Length); bufflist.Write(classdata); byte[] fdata = dataExtra(stream.ToArray()); stream.Position = 0; stream.SetLength(0); bufflist.Write(0); bufflist.Write(fdata); } else { bufflist.Write(0); bufflist.Write(CmdDef.CallCmd); byte[] classdata = BufferFormat.SerializeObject(buffer); bufflist.Write(classdata.Length); bufflist.Write(classdata); } int l = (int)(stream.Length); byte[] data = BufferFormat.GetSocketBytes(l); stream.Position = 0; bufflist.Write(data); byte[] pdata = stream.ToArray(); #if !COREFX stream.Close(); #endif stream.Dispose(); return(SendDataAsWait(buffer.Id, pdata)); } }