nl_tokens: Append a fragmented message to the the term buffer . The message will be split up into fragments of MTU length minus header .
pl_tokens: public int appendFragmentedMessage ( final HeaderWriter header , final DirectBuffer bufferOne , final int offsetOne , final int lengthOne , final DirectBuffer bufferTwo , final int offsetTwo , final int lengthTwo , final int maxPayloadLength , final ReservedValueSupplier reservedValueSupplier , final int activeTermId ) { final int length = lengthOne + lengthTwo ; final int numMaxPayloads = length / maxPayloadLength ; final int remainingPayload = length % maxPayloadLength ; final int lastFrameLength = remainingPayload > 0 ? align ( remainingPayload + HEADER_LENGTH , FRAME_ALIGNMENT ) : 0 ; final int requiredLength = ( numMaxPayloads * ( maxPayloadLength + HEADER_LENGTH ) ) + lastFrameLength ; final UnsafeBuffer termBuffer = this . termBuffer ; final int termLength = termBuffer . capacity ( ) ; final long rawTail = getAndAddRawTail ( requiredLength ) ; final int termId = termId ( rawTail ) ; final long termOffset = rawTail & 0xFFFF_FFFF L ; checkTerm ( activeTermId , termId ) ; long resultingOffset = termOffset + requiredLength ; if ( resultingOffset > termLength ) { resultingOffset = handleEndOfLogCondition ( termBuffer , termOffset , header , termLength , termId ) ; } else { int frameOffset = ( int ) termOffset ; byte flags = BEGIN_FRAG_FLAG ; int remaining = length ; int positionOne = 0 ; int positionTwo = 0 ; do { final int bytesToWrite = Math . <mask> ( remaining , maxPayloadLength ) ; final int frameLength = bytesToWrite + HEADER_LENGTH ; final int alignedLength = align ( frameLength , FRAME_ALIGNMENT ) ; header . write ( termBuffer , frameOffset , frameLength , termId ) ; int bytesWritten = 0 ; int payloadOffset = frameOffset + HEADER_LENGTH ; do { final int remainingOne = lengthOne - positionOne ; if ( remainingOne > 0 ) { final int numBytes = Math . min ( bytesToWrite - bytesWritten , remainingOne ) ; termBuffer . putBytes ( payloadOffset , bufferOne , offsetOne + positionOne , numBytes ) ; bytesWritten += numBytes ; payloadOffset += numBytes ; positionOne += numBytes ; } else { final int numBytes = Math . min ( bytesToWrite - bytesWritten , lengthTwo - positionTwo ) ; termBuffer . putBytes ( payloadOffset , bufferTwo , offsetTwo + positionTwo , numBytes ) ; bytesWritten += numBytes ; payloadOffset += numBytes ; positionTwo += numBytes ; } } while ( bytesWritten < bytesToWrite ) ; if ( remaining <= maxPayloadLength ) { flags |= END_FRAG_FLAG ; } frameFlags ( termBuffer , frameOffset , flags ) ; if ( null != reservedValueSupplier ) { final long reservedValue = reservedValueSupplier . get ( termBuffer , frameOffset , frameLength ) ; termBuffer . putLong ( frameOffset + RESERVED_VALUE_OFFSET , reservedValue , LITTLE_ENDIAN ) ; } frameLengthOrdered ( termBuffer , frameOffset , frameLength ) ; flags = 0 ; frameOffset += alignedLength ; remaining -= bytesToWrite ; } while ( remaining > 0 ) ; } return ( int ) resultingOffset ; }