public int appendUnfragmentedMessage( final long defaultVersionFlagsType, final long defaultSessionId, final DirectBuffer srcBuffer, final int srcOffset, final int length) { final int frameLength = length + HEADER_LENGTH; final int alignedLength = align(frameLength, FRAME_ALIGNMENT); final int termOffset = metaDataBuffer.getAndAddInt(TERM_TAIL_COUNTER_OFFSET, alignedLength); final UnsafeBuffer termBuffer = this.termBuffer; final int capacity = termBuffer.capacity(); int resultingOffset = termOffset + alignedLength; if (resultingOffset > (capacity - HEADER_LENGTH)) { resultingOffset = handleEndOfLogCondition( termBuffer, termOffset, defaultVersionFlagsType, defaultSessionId, capacity); } else { applyDefaultHeader( termBuffer, termOffset, frameLength, defaultVersionFlagsType, defaultSessionId); termBuffer.putBytes(termOffset + HEADER_LENGTH, srcBuffer, srcOffset, length); frameLengthOrdered(termBuffer, termOffset, frameLength); } return resultingOffset; }
public int appendFragmentedMessage( final long defaultVersionFlagsType, final long defaultSessionId, final DirectBuffer srcBuffer, final int srcOffset, final int length, final int maxPayloadLength) { 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; int termOffset = metaDataBuffer.getAndAddInt(TERM_TAIL_COUNTER_OFFSET, requiredLength); final UnsafeBuffer termBuffer = this.termBuffer; final int capacity = termBuffer.capacity(); int resultingOffset = termOffset + requiredLength; if (resultingOffset > (capacity - HEADER_LENGTH)) { resultingOffset = handleEndOfLogCondition( termBuffer, termOffset, defaultVersionFlagsType, defaultSessionId, capacity); } else { byte flags = BEGIN_FRAG_FLAG; int remaining = length; do { final int bytesToWrite = Math.min(remaining, maxPayloadLength); final int frameLength = bytesToWrite + HEADER_LENGTH; final int alignedLength = align(frameLength, FRAME_ALIGNMENT); applyDefaultHeader( termBuffer, termOffset, frameLength, defaultVersionFlagsType, defaultSessionId); termBuffer.putBytes( termOffset + HEADER_LENGTH, srcBuffer, srcOffset + (length - remaining), bytesToWrite); if (remaining <= maxPayloadLength) { flags |= END_FRAG_FLAG; } frameFlags(termBuffer, termOffset, flags); frameLengthOrdered(termBuffer, termOffset, frameLength); flags = 0; termOffset += alignedLength; remaining -= bytesToWrite; } while (remaining > 0); } return resultingOffset; }
private void addSentDataFrame() { rcvBuffer.putBytes(0, DATA); termAppender.append(rcvBuffer, 0, DATA.length); }