private byte[] EnCodeOneway(FPData data) { if (data != null) { System.Text.ASCIIEncoding encoder = new System.Text.ASCIIEncoding(); MemoryStream ms = this.BuildHeader(data, 12 + data.GetSS() + data.GetPsize()); ms.WriteByte((byte)data.GetSS()); byte[] psizeBytes = BitConverter.GetBytes(data.GetPsize()); ms.Write(psizeBytes, 0, psizeBytes.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); }
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())); } }
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) { string method = null; if (data != null) { method = data.GetMethod(); } if (string.IsNullOrEmpty(method)) { return; } IProcessor psr = null; lock (self_locker) { if (this._destroyed) { return; } if (this._processor == null) { this._processor = new BaseProcessor(); } psr = this._processor; if (!psr.HasPushService(method)) { if (method != "ping") { return; } } } this.AddService(() => { lock (self_locker) { if (psr != null) { psr.Service(data, answer); } } }); }