/** * Set the value of the header flags field. * * @param flags value to be set in the header. * @return this for a fluent API. * @see io.aeron.protocol.DataHeaderFlyweight */ public ExclusiveBufferClaim flags(final byte flags) { buffer.putByte(FLAGS_FIELD_OFFSET, flags); return this; }
public int putNaturalIntAscii(final int index, final int value) { if (value == 0) { putByte(index, ZERO); return 1; } int i = endOffset(value); final int length = i + 1; if (SHOULD_BOUNDS_CHECK) { boundsCheck0(index, length); } int quotient = value; while (i >= 0) { final int remainder = quotient % 10; quotient = quotient / 10; putByteWithoutBoundsCheck(i + index, (byte)(ZERO + remainder)); i--; } return length; }
@Test public void shouldFragmentMessageOverTwoFrames() { final int msgLength = MAX_PAYLOAD_LENGTH + 1; final int headerLength = DEFAULT_HEADER.capacity(); final int frameLength = headerLength + 1; final int requiredCapacity = align(headerLength + 1, FRAME_ALIGNMENT) + MAX_FRAME_LENGTH; final UnsafeBuffer buffer = new UnsafeBuffer(new byte[msgLength]); int tail = 0; logMetaDataBuffer.putLong(TERM_TAIL_COUNTER_OFFSET, packTail(TERM_ID, tail)); assertThat(termAppender.appendFragmentedMessage( headerWriter, buffer, 0, msgLength, MAX_PAYLOAD_LENGTH, RVS, TERM_ID), is(requiredCapacity)); assertThat(rawTailVolatile(logMetaDataBuffer, PARTITION_INDEX), is(packTail(TERM_ID, tail + requiredCapacity))); final InOrder inOrder = inOrder(termBuffer, headerWriter); inOrder.verify(headerWriter, times(1)).write(termBuffer, tail, MAX_FRAME_LENGTH, TERM_ID); inOrder.verify(termBuffer, times(1)).putBytes(tail + headerLength, buffer, 0, MAX_PAYLOAD_LENGTH); inOrder.verify(termBuffer, times(1)).putByte(flagsOffset(tail), BEGIN_FRAG_FLAG); inOrder.verify(termBuffer, times(1)).putLong(tail + RESERVED_VALUE_OFFSET, RV, LITTLE_ENDIAN); inOrder.verify(termBuffer, times(1)).putIntOrdered(tail, MAX_FRAME_LENGTH); tail = MAX_FRAME_LENGTH; inOrder.verify(headerWriter, times(1)).write(termBuffer, tail, frameLength, TERM_ID); inOrder.verify(termBuffer, times(1)).putBytes(tail + headerLength, buffer, MAX_PAYLOAD_LENGTH, 1); inOrder.verify(termBuffer, times(1)).putByte(flagsOffset(tail), END_FRAG_FLAG); inOrder.verify(termBuffer, times(1)).putLong(tail + RESERVED_VALUE_OFFSET, RV, LITTLE_ENDIAN); inOrder.verify(termBuffer, times(1)).putIntOrdered(tail, frameLength); }
/** * Set the value of the header flags field. * * @param flags value to be set in the header. * @return this for a fluent API. * @see io.aeron.protocol.DataHeaderFlyweight */ public BufferClaim flags(final byte flags) { buffer.putByte(FLAGS_FIELD_OFFSET, flags); return this; }
public int putNaturalLongAscii(final int index, final long value) { if (value == 0) { putByte(index, ZERO); return 1; } int i = endOffset(value); final int length = i + 1; if (SHOULD_BOUNDS_CHECK) { boundsCheck0(index, length); } long quotient = value; while (i >= 0) { final long remainder = quotient % 10; quotient = quotient / 10; putByteWithoutBoundsCheck(i + index, (byte)(ZERO + remainder)); i--; } return length; }
public int putNaturalIntAsciiFromEnd(final int value, final int endExclusive) { int remainder = value; int index = endExclusive; while (remainder > 0) { index--; final int digit = remainder % 10; remainder = remainder / 10; putByte(index, (byte)(ZERO + digit)); } return index; }
/** * Write the flags field for a frame. * * @param buffer containing the frame. * @param termOffset at which a frame begins. * @param flags value for the frame. */ public static void frameFlags(final UnsafeBuffer buffer, final int termOffset, final byte flags) { buffer.putByte(flagsOffset(termOffset), flags); }
public void putNaturalPaddedIntAscii(final int offset, final int length, final int value) { final int end = offset + length; int remainder = value; for (int index = end - 1; index >= offset; index--) { final int digit = remainder % 10; remainder = remainder / 10; putByte(index, (byte)(ZERO + digit)); } if (remainder != 0) { throw new NumberFormatException(String.format("Cannot write %d in %d bytes", value, length)); } }
/** * Return an initialised default Data Frame Header. * * @param sessionId for the header * @param streamId for the header * @param termId for the header * @return byte array containing the header */ public static UnsafeBuffer createDefaultHeader(final int sessionId, final int streamId, final int termId) { final UnsafeBuffer buffer = new UnsafeBuffer( BufferUtil.allocateDirectAligned(HEADER_LENGTH, CACHE_LINE_LENGTH)); buffer.putByte(VERSION_FIELD_OFFSET, CURRENT_VERSION); buffer.putByte(FLAGS_FIELD_OFFSET, (byte)BEGIN_AND_END_FLAGS); buffer.putShort(TYPE_FIELD_OFFSET, (short)HDR_TYPE_DATA, LITTLE_ENDIAN); buffer.putInt(SESSION_ID_FIELD_OFFSET, sessionId, LITTLE_ENDIAN); buffer.putInt(STREAM_ID_FIELD_OFFSET, streamId, LITTLE_ENDIAN); buffer.putInt(TERM_ID_FIELD_OFFSET, termId, LITTLE_ENDIAN); buffer.putLong(RESERVED_VALUE_OFFSET, DEFAULT_RESERVE_VALUE); return buffer; }
private void shouldExposePositionAtWhichByteBufferGetsWrapped(final ByteBuffer byteBuffer) { final UnsafeBuffer wibbleBuffer = new UnsafeBuffer( byteBuffer, ADJUSTMENT_OFFSET, byteBuffer.capacity() - ADJUSTMENT_OFFSET); wibbleBuffer.putByte(0, VALUE); assertEquals(VALUE, byteBuffer.get(wibbleBuffer.wrapAdjustment())); }
@Test public void shouldExposePositionAtWhichByteArrayGetsWrapped() { final UnsafeBuffer wibbleBuffer = new UnsafeBuffer( wibbleBytes, ADJUSTMENT_OFFSET, wibbleBytes.length - ADJUSTMENT_OFFSET); wibbleBuffer.putByte(0, VALUE); assertEquals(VALUE, wibbleBytes[wibbleBuffer.wrapAdjustment()]); }
/** * Set the value of the header flags field. * * @param flags value to be set in the header. * @return this for a fluent API. * @see io.aeron.protocol.DataHeaderFlyweight */ public BufferClaim flags(final byte flags) { buffer.putByte(FLAGS_FIELD_OFFSET, flags); return this; }
/** * Set the value of the header flags field. * * @param flags value to be set in the header. * @return this for a fluent API. * @see io.aeron.protocol.DataHeaderFlyweight */ public ExclusiveBufferClaim flags(final byte flags) { buffer.putByte(FLAGS_FIELD_OFFSET, flags); return this; }
/** * Set the value of the header flags field. * * @param flags value to be set in the header. * @return this for a fluent API. * @see io.aeron.protocol.DataHeaderFlyweight */ public BufferClaim flags(final byte flags) { buffer.putByte(FLAGS_FIELD_OFFSET, flags); return this; }
/** * Set the value of the header flags field. * * @param flags value to be set in the header. * @return this for a fluent API. * @see io.aeron.protocol.DataHeaderFlyweight */ public ExclusiveBufferClaim flags(final byte flags) { buffer.putByte(FLAGS_FIELD_OFFSET, flags); return this; }
public int putNaturalIntAsciiFromEnd(final int value, final int endExclusive) { int remainder = value; int index = endExclusive; while (remainder > 0) { index--; final int digit = remainder % 10; remainder = remainder / 10; putByte(index, (byte)(ZERO + digit)); } return index; }
/** * Write the flags field for a frame. * * @param buffer containing the frame. * @param termOffset at which a frame begins. * @param flags value for the frame. */ public static void frameFlags(final UnsafeBuffer buffer, final int termOffset, final byte flags) { buffer.putByte(flagsOffset(termOffset), flags); }
/** * Write the flags field for a frame. * * @param buffer containing the frame. * @param termOffset at which a frame begins. * @param flags value for the frame. */ public static void frameFlags(final UnsafeBuffer buffer, final int termOffset, final byte flags) { buffer.putByte(flagsOffset(termOffset), flags); }