private void SendMsgC(NseMsg nseMsg) { nseMsg.SerializeType = Convert.ToByte('C'); // Chunk lock (_thisLock) { _chunk.CWriter.Write(nseMsg.SerializeType); _chunk.CWriter.Write(nseMsg.MarketType); _chunk.CWriter.Write(nseMsg.LogTime); _chunk.CWriter.Write(nseMsg.BcSeqNo); _chunk.CWriter.Write(nseMsg.TransCode); _chunk.CWriter.Write(nseMsg.DataLength); _chunk.CWriter.Write(nseMsg.Data); } CheckAndSendChunk(); }
private void SendMsgR(NseMsg nseMsg) { nseMsg.SerializeType = Convert.ToByte('R'); // single Record byte[] serializedMsg; using (var stream = new MemoryStream()) { var writer = new BinaryWriter(stream); writer.Write(nseMsg.SerializeType); writer.Write(nseMsg.MarketType); writer.Write(nseMsg.LogTime); writer.Write(nseMsg.BcSeqNo); writer.Write(nseMsg.TransCode); writer.Write(nseMsg.DataLength); writer.Write(nseMsg.Data); serializedMsg = stream.ToArray(); } _formMCastSender.SendRaw(serializedMsg, serializedMsg.Length); }
private void DumpNseMsg(NseMsg nseMsg) { nseMsg.SerializeType = Convert.ToByte('R'); // single Record byte[] serializedMsg; using (var stream = new MemoryStream()) { var writer = new BinaryWriter(stream); writer.Write(nseMsg.SerializeType); writer.Write(nseMsg.MarketType); writer.Write(nseMsg.LogTime); writer.Write(nseMsg.BcSeqNo); writer.Write(nseMsg.TransCode); writer.Write(nseMsg.DataLength); writer.Write(nseMsg.Data); serializedMsg = stream.ToArray(); } var recType = new byte[1]; recType[0] = nseMsg.MarketType; // send nseMsg }
private void ProcessPacket(structNNFHeader header, byte[] packetData, bool decompressed) { var dataLen = packetData.Length; var processedLen = 0; using (var dstream = new MemoryStream(packetData)) { var reader = new BinaryReader(dstream); var msgHeader = new StructMsgHeader(); var res = reader.ReadBytes(8); if (decompressed && res[0] != header.MarketType) { LogText("Error", res[0] + "," + header.MarketType); } processedLen += 8; msgHeader.Res1 = reader.ReadBytes(4); var intBytes = reader.ReadBytes(4); msgHeader.LogTime = ExchDataNse.SwapBytes2Int32(intBytes); msgHeader.Alpha1 = reader.ReadByte(); msgHeader.Alpha2 = reader.ReadByte(); intBytes = reader.ReadBytes(2); msgHeader.TransCode = ExchDataNse.SwapBytes2Int16(intBytes); intBytes = reader.ReadBytes(2); msgHeader.ErrorCode = ExchDataNse.SwapBytes2Int16(intBytes); intBytes = reader.ReadBytes(4); msgHeader.BcSeqNo = ExchDataNse.SwapBytes2Int32(intBytes); msgHeader.Res3 = reader.ReadBytes(4); msgHeader.TimeStamp2 = reader.ReadBytes(8); msgHeader.Filler = reader.ReadBytes(8); intBytes = reader.ReadBytes(2); msgHeader.Length = ExchDataNse.SwapBytes2Int16(intBytes); processedLen += 40; var readSize = Math.Min(msgHeader.Length - 40, dataLen - processedLen); if (msgHeader.LogTime > 0) { if (header.MarketType == 4) // CM { _lastLogTimeCm = msgHeader.LogTime; } else if (header.MarketType == 2) // FO { _lastLogTimeFo = msgHeader.LogTime; } else if (header.MarketType == 6) // CF { _lastLogTimeCF = msgHeader.LogTime; } } else { if (header.MarketType == 2) // FO { msgHeader.LogTime = _lastLogTimeFo; } else if (header.MarketType == 4) // CM { msgHeader.LogTime = _lastLogTimeCm; } else if (header.MarketType == 6) // CF { msgHeader.LogTime = _lastLogTimeCF; } } var nseMsg = new NseMsg(); if (readSize >= 0) { nseMsg.MarketType = header.MarketType; nseMsg.LogTime = msgHeader.LogTime; nseMsg.BcSeqNo = msgHeader.BcSeqNo; // local seqNo? nseMsg.TransCode = msgHeader.TransCode; nseMsg.DataLength = (short)readSize; nseMsg.Data = reader.ReadBytes(readSize); if (_chunkMode) { SendMsgC(nseMsg); } else { SendMsgR(nseMsg); } if (_saveDump) { DumpNseMsg(nseMsg); } if (checkBoxShow.Checked) { LogText("Msg", header.ToDisplay() + "," + nseMsg.ToDisplay()); } } else { LogText("Error", header.ToDisplay() + "," + msgHeader.ToDisplay() + "," + readSize, true); } } }