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);
                }
            }
        }
        //-----------------------------------------------------------------------------------------------------
        private void PreProcessNseExchFeed(ushort dataId, byte[] data)
        {
            var dataLen      = data.Length;
            var processedLen = 0;

            using (var dstream = new MemoryStream(data))
            {
                var reader = new BinaryReader(dstream);
                var header = new structNNFHeader();

                header.MarketType = reader.ReadByte();
                header.Res1       = reader.ReadByte();
                var int16Bytes = reader.ReadBytes(2);
                header.Records = ExchDataNse.SwapBytes2Int16(int16Bytes);
                processedLen   = 4;
                for (var i = 0; i < header.Records; i++)
                {
                    if (dstream.Position > dataLen - 2)
                    {
                        var errorDesc = "Wrong RecordCount " + header.Records + "," + dstream.Position + "," +
                                        dataLen;
                        LogText(dataId.ToString(), errorDesc, true);
                        logger.Warn(dataId + "," + errorDesc);
                        break;
                    }

                    header.Posi     = (short)(i + 1);
                    int16Bytes      = reader.ReadBytes(2);
                    processedLen   += 2;
                    header.CompSize = ExchDataNse.SwapBytes2Int16(int16Bytes);

                    if (header.CompSize >= 0 && header.CompSize <= 506 && processedLen + header.CompSize <= dataLen)
                    {
                        if (header.CompSize == 0)
                        {
                            header.DeCompSize = (short)(dataLen - processedLen);
                            try
                            {
                                header.Packet = reader.ReadBytes(header.DeCompSize);
                                processedLen += header.DeCompSize;
                                ProcessPacket(header, header.Packet, false);
                            }
                            catch (Exception e)
                            {
                                LogText("errorN" + dataId, e.Message, true);
                                logger.Warn(dataId.ToString);
                                logger.Error(e);
                                break;
                            }
                        }
                        else
                        {
                            header.Packet = reader.ReadBytes(header.CompSize);
                            processedLen += header.CompSize;
                            var    decompLen = 0;
                            byte[] decompData;
                            try
                            {
                                decompData        = _decompressor.DecompressZ(header.Packet, ref decompLen);
                                header.DeCompSize = (short)decompLen;
                            }
                            catch (Exception e)
                            {
                                LogText("errorC" + dataId, e.Message, true);
                                logger.Error(e);
                                break;
                            }

                            try
                            {
                                ProcessPacket(header, decompData, true);
                            }
                            catch (Exception e)
                            {
                                LogText("errorP" + dataId, e.Message, true);
                                logger.Error(e);
                                break;
                            }
                        }
                    }
                    else
                    {
                        LogText("BadHeader", dataId + "," + header.ToDisplay(), true);
                        break;
                    }
                }
            }
        }