private byte[] EnCodeAnswer(FPData data) { if (data != null) { 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)) { 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); }
private byte[] EnCodeTwoway(FPData data) { 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); byte[] methodBytes = encoder.GetBytes(data.GetMethod()); ms.Write(methodBytes, 0, methodBytes.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)); }
public void Service(FPData data, AnswerDelegate answer) { if (data.GetFlag() == 0) { this._event.FireEvent(new EventData(data.GetMethod(), data.JsonPayload())); } if (data.GetFlag() == 1) { this._event.FireEvent(new EventData(data.GetMethod(), data.MsgpackPayload())); } }