コード例 #1
0
        /// <summary>
        /// Raises the <see cref="DataParsed"/> event.
        /// </summary>
        /// <param name="output">The object that was deserialized from binary image.</param>
        protected virtual void OnDataParsed(TOutputType output)
        {
            if ((object)DataParsed != null)
            {
                // Get a reusable event args object to publish output
                EventArgs <TOutputType> outputArgs = FastObjectFactory <EventArgs <TOutputType> > .CreateObjectFunction();

                outputArgs.Argument = output;

                if (output.AllowQueuedPublication)
                {
                    // Queue-up parsed output for publication
                    m_outputQueue.Enqueue(outputArgs);
                }
                else
                {
                    // Publish parsed output immediately
                    DataParsed(this, outputArgs);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Queues a sequence of bytes, from the specified data source, onto the stream for parsing.
        /// </summary>
        /// <param name="source">Identifier of the data source.</param>
        /// <param name="buffer">An array of bytes. This method copies count bytes from buffer to the queue.</param>
        /// <param name="offset">The zero-based byte offset in buffer at which to begin copying bytes to the current stream.</param>
        /// <param name="count">The number of bytes to be written to the current stream.</param>
        /// <remarks>
        /// This method associates a buffer with its data source identifier.
        /// </remarks>
        public virtual void Parse(TSourceIdentifier source, byte[] buffer, int offset, int count)
        {
            SourceIdentifiableBuffer identifiableBuffer = null;

            buffer.ValidateParameters(offset, count);

            if (count > 0)
            {
                // Get an identifiable buffer object
                identifiableBuffer = FastObjectFactory <SourceIdentifiableBuffer> .CreateObjectFunction();

                identifiableBuffer.Source = source;
                identifiableBuffer.Count  = count;

                // Copy buffer data for processing
                Buffer.BlockCopy(buffer, offset, identifiableBuffer.Buffer, 0, count);

                // Add buffer to the queue for parsing. Note that buffer is queued for parsing instead
                // of handling parse on this thread - this has become necessary to reduce UDP data loss
                // that can happen in-process when system has UDP buffers building up for processing.
                m_bufferQueue.Enqueue(new[] { identifiableBuffer });
            }
        }
コード例 #3
0
        /// <summary>
        /// Queues a sequence of bytes, from the specified data source, onto the stream for parsing.
        /// </summary>
        /// <param name="source">Identifier of the data source.</param>
        /// <param name="buffer">An array of bytes. This method copies count bytes from buffer to the queue.</param>
        /// <param name="offset">The zero-based byte offset in buffer at which to begin copying bytes to the current stream.</param>
        /// <param name="count">The number of bytes to be written to the current stream.</param>
        /// <remarks>
        /// This method associates a buffer with its data source identifier.
        /// </remarks>
        public virtual void Parse(TSourceIdentifier source, byte[] buffer, int offset, int count)
        {
            SourceIdentifiableBuffer identifiableBuffer = null;

            buffer.ValidateParameters(offset, count);

            if (count > 0)
            {
                // Get an identifiable buffer object
                identifiableBuffer = FastObjectFactory <SourceIdentifiableBuffer> .CreateObjectFunction();

                identifiableBuffer.Source = source;
                identifiableBuffer.Count  = count;

                // Copy buffer data for processing
                Buffer.BlockCopy(buffer, offset, identifiableBuffer.Buffer, 0, count);

                // Add buffer to the queue for parsing. Note that buffer is queued for parsing instead
                // of handling parse on this thread - this has become necessary to reduce UDP data loss
                // that can happen in-process when system has UDP buffers building up for processing.
                if (OptimizationOptions.DisableAsyncQueueInProtocolParsing)
                {
                    try
                    {
                        ParseQueuedBuffers(new[] { identifiableBuffer });
                    }
                    catch (Exception ex)
                    {
                        ProcessExceptionHandler(this, new EventArgs <Exception>(ex));
                    }
                }
                else
                {
                    m_bufferQueue.Enqueue(new[] { identifiableBuffer });
                }
            }
        }