Ejemplo n.º 1
0
        public static long Read(UnsafeBuffer termBuffer, int offset, FragmentHandler handler, int fragmentsLimit, Header header, ErrorHandler errorHandler)
        {
            int fragmentsRead = 0;
            int capacity      = termBuffer.Capacity;

            try
            {
                do
                {
                    int frameLength = FrameDescriptor.FrameLengthVolatile(termBuffer, offset);
                    if (frameLength <= 0)
                    {
                        break;
                    }

                    int termOffset = offset;
                    offset += BitUtil.Align(frameLength, FrameDescriptor.FRAME_ALIGNMENT);

                    if (!FrameDescriptor.IsPaddingFrame(termBuffer, termOffset))
                    {
                        header.SetBuffer(termBuffer, termOffset);

                        handler(termBuffer, termOffset + DataHeaderFlyweight.HEADER_LENGTH, frameLength - DataHeaderFlyweight.HEADER_LENGTH, header);

                        ++fragmentsRead;
                    }
                } while (fragmentsRead < fragmentsLimit && offset < capacity);
            }
            catch (Exception t)
            {
                errorHandler(t);
            }

            return(Pack(offset, fragmentsRead));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Scan a term buffer for a block of message fragments from and offset up to a limitOffset.
        ///
        /// A scan will terminate if a padding frame is encountered. If first frame in a scan is padding then a block
        /// for the padding is notified. If the padding comes after the first frame in a scan then the scan terminates
        /// at the offset the padding frame begins. Padding frames are delivered singularly in a block.
        ///
        /// Padding frames may be for a greater range than the limit offset but only the header needs to be valid so
        /// relevant length of the frame is <see cref="DataHeaderFlyweight.HEADER_LENGTH"/>
        /// </summary>
        /// <param name="termBuffer"> to scan for message fragments. </param>
        /// <param name="termOffset">     at which the scan should begin. </param>
        /// <param name="limitOffset">      at which the scan should stop. </param>
        /// <returns> the offset at which the scan terminated. </returns>
        public static int Scan(IAtomicBuffer termBuffer, int termOffset, int limitOffset)
        {
            var offset = termOffset;

            while (offset < limitOffset)
            {
                int frameLength = FrameDescriptor.FrameLengthVolatile(termBuffer, offset);
                if (frameLength <= 0)
                {
                    break;
                }

                int alignedFrameLength = BitUtil.Align(frameLength, FrameDescriptor.FRAME_ALIGNMENT);

                if (FrameDescriptor.IsPaddingFrame(termBuffer, offset))
                {
                    if (termOffset == offset)
                    {
                        offset += alignedFrameLength;
                    }

                    break;
                }

                if (offset + alignedFrameLength > limitOffset)
                {
                    break;
                }

                offset += alignedFrameLength;
            }


            return(offset);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Scan a term buffer for a block of message fragments from and offset up to a limit.
        /// </summary>
        /// <param name="termBuffer"> to scan for message fragments. </param>
        /// <param name="termOffset">     at which the scan should begin. </param>
        /// <param name="limit">      at which the scan should stop. </param>
        /// <returns> the offset at which the scan terminated. </returns>
        public static int Scan(IAtomicBuffer termBuffer, int termOffset, int limit)
        {
            var offset = termOffset;

            do
            {
                int frameLength = FrameDescriptor.FrameLengthVolatile(termBuffer, offset);
                if (frameLength <= 0)
                {
                    break;
                }

                int alignedFrameLength = BitUtil.Align(frameLength, FrameDescriptor.FRAME_ALIGNMENT);
                offset += alignedFrameLength;
                if (offset >= limit)
                {
                    if (offset > limit)
                    {
                        offset -= alignedFrameLength;
                    }

                    break;
                }
            } while (true);

            return(offset);
        }
Ejemplo n.º 4
0
        public static int Read(
            UnsafeBuffer termBuffer,
            int termOffset,
            IFragmentHandler handler,
            int fragmentsLimit,
            Header header,
            ErrorHandler errorHandler,
            long currentPosition,
            IPosition subscriberPosition)
        {
            int fragmentsRead = 0;
            int offset        = termOffset;
            int capacity      = termBuffer.Capacity;

            header.Buffer = termBuffer;

            try
            {
                while (fragmentsRead < fragmentsLimit && offset < capacity)
                {
                    int frameLength = FrameDescriptor.FrameLengthVolatile(termBuffer, offset);
                    if (frameLength <= 0)
                    {
                        break;
                    }

                    int frameOffset = offset;
                    offset += BitUtil.Align(frameLength, FrameDescriptor.FRAME_ALIGNMENT);

                    if (!FrameDescriptor.IsPaddingFrame(termBuffer, frameOffset))
                    {
                        header.Offset = frameOffset;
                        handler.OnFragment(termBuffer, frameOffset + DataHeaderFlyweight.HEADER_LENGTH, frameLength - DataHeaderFlyweight.HEADER_LENGTH, header);

                        ++fragmentsRead;
                    }
                }
            }

            catch (Exception t)
            {
                errorHandler(t);
            }
            finally
            {
                long newPosition = currentPosition + (offset - termOffset);
                if (newPosition > currentPosition)
                {
                    subscriberPosition.SetOrdered(newPosition);
                }
            }

            return(fragmentsRead);
        }