/** * Get the value of the flags field. * * @return the value of the header flags field. * @see io.aeron.protocol.DataHeaderFlyweight */ public final byte flags() { return buffer.getByte(FLAGS_FIELD_OFFSET); }
/** * Does the data frame in the packet have the EOS flag set? * * @param packet containing the data frame. * @return true if the EOS flag is set otherwise false. */ public static boolean isEndOfStream(final UnsafeBuffer packet) { return BEGIN_END_AND_EOS_FLAGS == (packet.getByte(FLAGS_FIELD_OFFSET) & 0xFF); }
/** * Get the flags field for a frame. * * @param buffer containing the frame. * @param termOffset at which a frame begins. * @return the value of the flags. */ public static byte frameFlags(final UnsafeBuffer buffer, final int termOffset) { return buffer.getByte(flagsOffset(termOffset)); }
public static boolean isValidDescriptor(final UnsafeBuffer descriptorBuffer) { return descriptorBuffer.getByte(RecordingDescriptorHeaderDecoder.validEncodingOffset()) == VALID; }
/** * Read the type of of the frame from header. * * @param buffer containing the frame. * @param termOffset at which a frame begins. * @return the value of the frame type header. */ public static int frameVersion(final UnsafeBuffer buffer, final int termOffset) { return buffer.getByte(versionOffset(termOffset)); }
public boolean hasRecording(final long recordingId) { return recordingId >= 0 && recordingId < nextRecordingId && fieldAccessBuffer.getByte( recordingDescriptorOffset(recordingId) + RecordingDescriptorHeaderDecoder.validEncodingOffset()) == VALID; }
private void verifyData(final UnsafeBuffer srcBuffer, final FragmentHandler mockFragmentHandler) { final ArgumentCaptor<DirectBuffer> bufferArg = ArgumentCaptor.forClass(DirectBuffer.class); final ArgumentCaptor<Integer> offsetArg = ArgumentCaptor.forClass(Integer.class); verify(mockFragmentHandler, times(1)).onFragment( bufferArg.capture(), offsetArg.capture(), eq(srcBuffer.capacity()), any(Header.class)); final DirectBuffer capturedBuffer = bufferArg.getValue(); final int offset = offsetArg.getValue(); for (int i = 0; i < srcBuffer.capacity(); i++) { final int index = offset + i; assertThat("same at " + index, capturedBuffer.getByte(index), is(srcBuffer.getByte(i))); } } }
@Test public void shouldAssembleTwoPartMessage() { when(header.flags()) .thenReturn(FrameDescriptor.BEGIN_FRAG_FLAG) .thenReturn(FrameDescriptor.END_FRAG_FLAG); final UnsafeBuffer srcBuffer = new UnsafeBuffer(new byte[1024]); final int offset = 0; final int length = srcBuffer.capacity() / 2; srcBuffer.setMemory(0, length, (byte)65); srcBuffer.setMemory(length, length, (byte)66); adapter.onFragment(srcBuffer, offset, length, header); adapter.onFragment(srcBuffer, length, length, header); final ArgumentCaptor<UnsafeBuffer> bufferArg = ArgumentCaptor.forClass(UnsafeBuffer.class); final ArgumentCaptor<Header> headerArg = ArgumentCaptor.forClass(Header.class); verify(delegateFragmentHandler, times(1)).onFragment( bufferArg.capture(), eq(offset), eq(length * 2), headerArg.capture()); final UnsafeBuffer capturedBuffer = bufferArg.getValue(); for (int i = 0; i < srcBuffer.capacity(); i++) { assertThat("same at i=" + i, capturedBuffer.getByte(i), is(srcBuffer.getByte(i))); } final Header capturedHeader = headerArg.getValue(); assertThat(capturedHeader.sessionId(), is(SESSION_ID)); assertThat(capturedHeader.flags(), is(FrameDescriptor.END_FRAG_FLAG)); }
@Test public void shouldCreateCorrectLengthAndZeroedFilesForPublication() { final String canonicalForm = udpChannel.canonicalForm(); final RawLog rawLog = rawLogFactory.newNetworkPublication( canonicalForm, SESSION_ID, STREAM_ID, CREATION_ID, TERM_BUFFER_LENGTH, PRE_ZERO_LOG); assertThat(rawLog.termLength(), is(TERM_BUFFER_LENGTH)); final UnsafeBuffer[] termBuffers = rawLog.termBuffers(); assertThat(termBuffers.length, is(PARTITION_COUNT)); for (final UnsafeBuffer termBuffer : termBuffers) { assertThat(termBuffer.capacity(), is(TERM_BUFFER_LENGTH)); assertThat(termBuffer.getByte(0), is((byte)0)); assertThat(termBuffer.getByte(TERM_BUFFER_LENGTH - 1), is((byte)0)); } final UnsafeBuffer metaData = rawLog.metaData(); assertThat(metaData.capacity(), is(LogBufferDescriptor.LOG_META_DATA_LENGTH)); assertThat(metaData.getByte(0), is((byte)0)); assertThat(metaData.getByte(LogBufferDescriptor.LOG_META_DATA_LENGTH - 1), is((byte)0)); rawLog.close(); }
@Test public void shouldCreateCorrectLengthAndZeroedFilesForImage() { final String canonicalForm = udpChannel.canonicalForm(); final int imageTermBufferMaxLength = TERM_BUFFER_LENGTH / 2; final RawLog rawLog = rawLogFactory.newNetworkedImage( canonicalForm, SESSION_ID, STREAM_ID, CREATION_ID, imageTermBufferMaxLength, PRE_ZERO_LOG); assertThat(rawLog.termLength(), is(imageTermBufferMaxLength)); final UnsafeBuffer[] termBuffers = rawLog.termBuffers(); assertThat(termBuffers.length, is(PARTITION_COUNT)); for (final UnsafeBuffer termBuffer : termBuffers) { assertThat(termBuffer.capacity(), is(imageTermBufferMaxLength)); assertThat(termBuffer.getByte(0), is((byte)0)); assertThat(termBuffer.getByte(imageTermBufferMaxLength - 1), is((byte)0)); } final UnsafeBuffer metaData = rawLog.metaData(); assertThat(metaData.capacity(), is(LogBufferDescriptor.LOG_META_DATA_LENGTH)); assertThat(metaData.getByte(0), is((byte)0)); assertThat(metaData.getByte(LogBufferDescriptor.LOG_META_DATA_LENGTH - 1), is((byte)0)); rawLog.close(); }
private void validateRecordingFragment( final UnsafeBuffer buffer, final int offset, final int length, @SuppressWarnings("unused") final int frameType, @SuppressWarnings("unused") final byte flags, @SuppressWarnings("unused") final long reservedValue) { if (!FrameDescriptor.isPaddingFrame(buffer, offset - HEADER_LENGTH)) { final int expectedLength = messageLengths[messageCount] - HEADER_LENGTH; if (length != expectedLength) { fail("Message length=" + length + " expected=" + expectedLength + " messageCount=" + messageCount); } assertThat(buffer.getInt(offset), is(messageCount)); assertThat(buffer.getByte(offset + 4), is((byte)'z')); remaining -= BitUtil.align(messageLengths[messageCount], FrameDescriptor.FRAME_ALIGNMENT); messageCount++; } }
static void validateFrame(final UnsafeBuffer buffer, final int message, final byte flags) { final int offset = message * FRAME_LENGTH; assertEquals(FRAME_LENGTH, FrameDescriptor.frameLength(buffer, offset)); assertEquals(flags, FrameDescriptor.frameFlags(buffer, offset)); assertEquals(message, buffer.getLong(offset + DataHeaderFlyweight.RESERVED_VALUE_OFFSET)); assertEquals(message, buffer.getByte(offset + DataHeaderFlyweight.HEADER_LENGTH)); } }
for (int i = 0; i < srcBuffer.capacity(); i++) assertThat("same at i=" + i, capturedBuffer.getByte(i), is(srcBuffer.getByte(i)));
/** * Get the flags field for a frame. * * @param buffer containing the frame. * @param termOffset at which a frame begins. * @return the value of the flags. */ public static byte frameFlags(final UnsafeBuffer buffer, final int termOffset) { return buffer.getByte(flagsOffset(termOffset)); }
/** * Read the type of of the frame from header. * * @param buffer containing the frame. * @param termOffset at which a frame begins. * @return the value of the frame type header. */ public static int frameVersion(final UnsafeBuffer buffer, final int termOffset) { return buffer.getByte(versionOffset(termOffset)); }
/** * Read the type of of the frame from header. * * @param buffer containing the frame. * @param termOffset at which a frame begins. * @return the value of the frame type header. */ public static int frameVersion(final UnsafeBuffer buffer, final int termOffset) { return buffer.getByte(versionOffset(termOffset)); }
public boolean hasRecording(final long recordingId) { return recordingId >= 0 && recordingId < nextRecordingId && fieldAccessBuffer.getByte( recordingDescriptorOffset(recordingId) + RecordingDescriptorHeaderDecoder.validEncodingOffset()) == VALID; }
@Override public int keyHashCode() { int result = 1; for (int i = 0; i < keyBuffer.capacity(); i++) { result = 31 * result + keyBuffer.getByte(i); } if (keyBuffer.capacity() < keyLength) { for (int i = keyBuffer.capacity(); i < keyLength; i++) { result = 31 * result; } } return result; }