Esempio n. 1
0
        public MatchInfo FindInBuffer(byte[] pattern, int maxSkip, bool consume, TimeSpan? wait, bool extractSkipped, out DataChunk skippedChunk)
        {
            int totalCount = 0;
            int maxScan = maxSkip + pattern.Length;
            DateTime startTime = DateTime.Now;
            int patternPos = 0;
            bool matchstarted = false;

            MatchInfo info = new MatchInfo();

            DataChunk skipped;

            if (extractSkipped)
                skipped = new DataChunk(maxSkip);
            else
                skipped = null;

            skippedChunk = skipped;

            int bytesRequired = pattern.Length + maxSkip;

            if (bytesRequired > BytesAvailable + BytesUsed)
                ShiftOrReallocateBuffer(bytesRequired);

            bool skippedExceeded = false;

            while (totalCount < maxScan && !info.Matched && !skippedExceeded)
            {
                int remaining = maxScan - totalCount;
                if ((BytesUsed - totalCount) == 0)
                {
                    int readCount;
                    bool timeOut;

                    readCount = ReadFromStreamToBuffer(remaining, out timeOut);

                    if (timeOut)
                    {
                        info.Timeout = true;
                        LogMessage("FindInBuffer", "Timeout: " + wait.Value.ToString(), LogEntryType.MeterMessage);

                        break;
                    }
                }
                else if ((BytesUsed - totalCount) < 0)
                {
                    LogMessage("FindInBuffer", "Logic error - totalCount exceeds buffer content", LogEntryType.ErrorMessage);
                    totalCount = 0;
                    info.Matched = false;
                    info.BytesSkipped = 0;
                    info.BytesConsumed = 0;
                    break;
                }

                if ((BytesUsed - totalCount) > 0)
                {
                    while ((FirstByteUsed + totalCount) < NextByteAvail)
                    {
                        matchstarted = (pattern[patternPos] == LocalBuffer[FirstByteUsed + totalCount++]);

                        if (matchstarted)
                        {
                            if (++patternPos == pattern.Length)
                            {
                                info.Matched = true;
                                break;
                            }
                        }
                        else
                        {
                            if (totalCount > maxSkip)
                            {
                                skippedExceeded = true;
                                break;
                            }
                            info.BytesSkipped = totalCount;
                            if (extractSkipped)
                            {
                                // increment skipped size
                                skipped.ChunkSize = totalCount;
                                // copy up to mismatch character
                                int offset = (totalCount - 1) - patternPos;
                                while (offset < totalCount)
                                {
                                    skipped.ChunkBytes[offset] = LocalBuffer[FirstByteUsed + offset];
                                    offset++;
                                }
                            }
                            //reset to start of pattern
                            patternPos = 0;
                        }
                    }
                }
            }

            if (consume)
            {
                BytesUsed -= totalCount;
                if (BytesUsed == 0)
                    NextByteAvail = 0;

                info.BytesConsumed = totalCount; // total bytes matched or skipped
            }

            BytesRead += info.BytesConsumed;
            info.TotalBytesRead = totalCount;

            if (SystemServices.LogMessageContent)
            {
                if (info.BytesSkipped > 0)
                {
                    LogMessage("FindInBuffer", "Skipped[" + info.BytesSkipped + "] next line", LogEntryType.MeterMessage);
                    FormatDump(skippedChunk.ChunkBytes, 0, skippedChunk.ChunkSize, SystemServices);
                }

                LogMessage("FindInBuffer", "Matched: " + info.Matched + " - Timeout: " + info.Timeout +
                    " - BytesRead: " + info.BytesRead + " - TotalBytesRead: " + info.TotalBytesRead + " - Pattern[" + pattern.Length + "] next line", LogEntryType.MeterMessage);

                FormatDump(pattern, 0, pattern.Length, SystemServices);
            }

            return info;
        }
        public MatchInfo FindInBuffer(byte[] pattern, int maxSkip, bool extractSkipped, out DataChunk skipped, TimeSpan? wait = null, bool consume = true)
        {
            DataChunk chunk;

            MatchInfo info = ByteBuffer.FindInBuffer(pattern, maxSkip, consume, wait, extractSkipped, out chunk);

            skipped = chunk;
            return info;
        }
Esempio n. 3
0
        private static void LoadDynamic(MessageRecord msgRecord, DataChunk chunk)
        {
            Element element = msgRecord.Message.Elements[0];  // Dynamic must be first element

            Variable var = null;

            if (element.GetType() == typeof(UseVariable))
                var = ((UseVariable)element).Variable;
            else
                return;

            if (var.GetType() != typeof(DynamicByteVar))
                return;

            DynamicByteVar byteVar = (DynamicByteVar)var;

            byteVar.SetBytes(chunk.ChunkBytes, 0, chunk.ChunkSize);
            //byteVar.ValueSet = true;
        }