private void HandleFragment(UnsafeBuffer buffer, int offset, int length, Header header, byte flags) { if ((flags & FrameDescriptor.BEGIN_FRAG_FLAG) == FrameDescriptor.BEGIN_FRAG_FLAG) { _builder.Reset().Append(buffer, offset, length); } else { _builder.Append(buffer, offset, length); if ((flags & FrameDescriptor.END_FRAG_FLAG) == FrameDescriptor.END_FRAG_FLAG) { int msgLength = _builder.Limit(); _delegate(_builder.Buffer(), 0, msgLength, header); _builder.Reset(); } } }
/// <summary> /// The implementation of <seealso cref="IControlledFragmentHandler"/> that reassembles and forwards whole messages. /// </summary> /// <param name="buffer"> containing the data. </param> /// <param name="offset"> at which the data begins. </param> /// <param name="length"> of the data in bytes. </param> /// <param name="header"> representing the meta data for the data. </param> /// <returns> <see cref="ControlledFragmentHandlerAction"/> to be taken after processing fragment.</returns> public ControlledFragmentHandlerAction OnFragment(IDirectBuffer buffer, int offset, int length, Header header) { var action = ControlledFragmentHandlerAction.CONTINUE; byte flags = header.Flags; if ((flags & FrameDescriptor.UNFRAGMENTED) == FrameDescriptor.UNFRAGMENTED) { action = _delegate.OnFragment(buffer, offset, length, header); } else { if ((flags & FrameDescriptor.BEGIN_FRAG_FLAG) == FrameDescriptor.BEGIN_FRAG_FLAG) { _builder.Reset().Append(buffer, offset, length); } else { int limit = _builder.Limit(); if (limit > 0) { _builder.Append(buffer, offset, length); if ((flags & FrameDescriptor.END_FRAG_FLAG) == FrameDescriptor.END_FRAG_FLAG) { action = _delegate.OnFragment(_builder.Buffer(), 0, _builder.Limit(), header); if (ControlledFragmentHandlerAction.ABORT == action) { _builder.Limit(limit); } else { _builder.Reset(); } } } } } return(action); }