private byte[] EnCodeAnswer(FPData data) { System.Text.ASCIIEncoding encoder = new System.Text.ASCIIEncoding(); MemoryStream ms = this.BuildHeader(data, 16 + data.GetPsize()); ms.WriteByte((byte)data.GetSS()); byte[] psizeBytes = BitConverter.GetBytes(data.GetPsize()); ms.Write(psizeBytes, 0, psizeBytes.Length); byte[] seqBytes = BitConverter.GetBytes(data.GetSeq()); ms.Write(seqBytes, 0, seqBytes.Length); byte[] payloadBytes = null; if (this.IsJson(data)) { payloadBytes = encoder.GetBytes(data.JsonPayload()); } if (this.IsMsgPack(data)) { payloadBytes = data.MsgpackPayload(); } ms.Write(payloadBytes, 0, payloadBytes.Length); return(this.StreamToBytes(ms)); }
private void PushService(FPData quest) { lock (self_locker) { FPClient self = this; this._psr.Service(quest, (payload, exception) => { FPData data = new FPData(); data.SetFlag(quest.GetFlag()); data.SetMtype(0x2); data.SetSeq(quest.GetSeq()); data.SetSS(exception ? 1 : 0); if (quest.GetFlag() == 0) { data.SetPayload(Convert.ToString(payload)); } if (quest.GetFlag() == 1) { data.SetPayload((byte[])payload); } self.SendQuest(data); }); } }
public string GetKeyCallback(FPData data) { StringBuilder sb = new StringBuilder(10); sb.Append("FPNN_"); sb.Append(Convert.ToString(data.GetSeq())); return(sb.ToString()); }
public string GetKeyCallback(FPData data) { string seq = "0"; if (data != null) { seq = Convert.ToString(data.GetSeq()); } StringBuilder sb = new StringBuilder(10); sb.Append("FPNN_"); sb.Append(seq); return(sb.ToString()); }
public void SendQuest(FPData data, CallbackDelegate callback, int timeout) { if (data != null && data.GetSeq() == 0) { data.SetSeq(this.AddSeq()); } byte[] buf = this._pkg.EnCode(data); buf = this._cry.EnCode(buf); if (callback != null) { this._callback.AddCallback(this._pkg.GetKeyCallback(data), callback, timeout); } if (buf != null) { this._sock.Write(buf); } }
private byte[] EnCodeTwoway(FPData data) { if (data != null) { System.Text.ASCIIEncoding encoder = new System.Text.ASCIIEncoding(); MemoryStream ms = this.BuildHeader(data, 16 + data.GetSS() + data.GetPsize()); ms.WriteByte((byte)data.GetSS()); byte[] psizeBytes = BitConverter.GetBytes(data.GetPsize()); ms.Write(psizeBytes, 0, psizeBytes.Length); byte[] seqBytes = BitConverter.GetBytes(data.GetSeq()); ms.Write(seqBytes, 0, seqBytes.Length); string method = (data.GetMethod() != null) ? data.GetMethod() : ""; byte[] methodBytes = encoder.GetBytes(method); ms.Write(methodBytes, 0, methodBytes.Length); byte[] payloadBytes = null; if (this.IsJson(data)) { string json = (data.JsonPayload() != null) ? data.JsonPayload() : ""; payloadBytes = encoder.GetBytes(json); } if (this.IsMsgPack(data)) { payloadBytes = data.MsgpackPayload(); } if (payloadBytes != null) { ms.Write(payloadBytes, 0, payloadBytes.Length); } return(this.StreamToBytes(ms)); } return(null); }