Search in sources :

Example 1 with UnsafeBuffer

use of org.agrona.concurrent.UnsafeBuffer in project deeplearning4j by deeplearning4j.

the class SbeStatsInitializationReport method encode.

@Override
public byte[] encode() {
    byte[] bytes = new byte[encodingLengthBytes()];
    MutableDirectBuffer buffer = new UnsafeBuffer(bytes);
    encode(buffer);
    return bytes;
}
Also used : MutableDirectBuffer(org.agrona.MutableDirectBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer)

Example 2 with UnsafeBuffer

use of org.agrona.concurrent.UnsafeBuffer in project deeplearning4j by deeplearning4j.

the class SbeStatsReport method encode.

@Override
public byte[] encode() {
    byte[] bytes = new byte[encodingLengthBytes()];
    MutableDirectBuffer buffer = new UnsafeBuffer(bytes);
    encode(buffer);
    return bytes;
}
Also used : MutableDirectBuffer(org.agrona.MutableDirectBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer)

Example 3 with UnsafeBuffer

use of org.agrona.concurrent.UnsafeBuffer in project deeplearning4j by deeplearning4j.

the class SbeStatsReport method decode.

@Override
public void decode(byte[] decode) {
    MutableDirectBuffer buffer = new UnsafeBuffer(decode);
    decode(buffer);
}
Also used : MutableDirectBuffer(org.agrona.MutableDirectBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer)

Example 4 with UnsafeBuffer

use of org.agrona.concurrent.UnsafeBuffer in project Aeron by real-logic.

the class ArchiveFileUtil method archiveMetaFileFormatDecoder.

static ArchiveDescriptorDecoder archiveMetaFileFormatDecoder(final File metaFile) throws IOException {
    try (RandomAccessFile randomAccessFile = new RandomAccessFile(metaFile, "rw");
        FileChannel metadataFileChannel = randomAccessFile.getChannel()) {
        final MappedByteBuffer metaDataBuffer = metadataFileChannel.map(FileChannel.MapMode.READ_WRITE, 0, ArchiveIndex.INDEX_RECORD_SIZE);
        final ArchiveDescriptorDecoder decoder = new ArchiveDescriptorDecoder();
        return decoder.wrap(new UnsafeBuffer(metaDataBuffer), ArchiveIndex.INDEX_FRAME_LENGTH, ArchiveDescriptorDecoder.BLOCK_LENGTH, ArchiveDescriptorDecoder.SCHEMA_VERSION);
    }
}
Also used : MappedByteBuffer(java.nio.MappedByteBuffer) FileChannel(java.nio.channels.FileChannel) ArchiveDescriptorDecoder(io.aeron.archiver.messages.ArchiveDescriptorDecoder) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer)

Example 5 with UnsafeBuffer

use of org.agrona.concurrent.UnsafeBuffer in project Aeron by real-logic.

the class BufferBuilderTest method shouldAppendOneBufferWithoutResizing.

@Test
public void shouldAppendOneBufferWithoutResizing() {
    final UnsafeBuffer srcBuffer = new UnsafeBuffer(new byte[INITIAL_CAPACITY]);
    final byte[] bytes = "Hello World".getBytes(StandardCharsets.UTF_8);
    srcBuffer.putBytes(0, bytes, 0, bytes.length);
    bufferBuilder.append(srcBuffer, 0, bytes.length);
    final byte[] temp = new byte[bytes.length];
    bufferBuilder.buffer().getBytes(0, temp, 0, bytes.length);
    assertThat(bufferBuilder.limit(), is(bytes.length));
    assertThat(bufferBuilder.capacity(), is(INITIAL_CAPACITY));
    assertArrayEquals(temp, bytes);
}
Also used : UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.Test)

Aggregations

UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)78 Test (org.junit.Test)42 StatusMessageFlyweight (io.aeron.protocol.StatusMessageFlyweight)8 MediaDriver (io.aeron.driver.MediaDriver)7 MutableDirectBuffer (org.agrona.MutableDirectBuffer)6 Header (io.aeron.logbuffer.Header)5 InOrder (org.mockito.InOrder)5 MappedByteBuffer (java.nio.MappedByteBuffer)4 Theory (org.junit.experimental.theories.Theory)4 ReceiveChannelEndpoint (io.aeron.driver.media.ReceiveChannelEndpoint)3 File (java.io.File)3 Date (java.util.Date)3 DirectBuffer (org.agrona.DirectBuffer)3 Before (org.junit.Before)3 DataPoint (org.junit.experimental.theories.DataPoint)3 SendChannelEndpoint (io.aeron.driver.media.SendChannelEndpoint)2 BufferClaim (io.aeron.logbuffer.BufferClaim)2 FragmentHandler (io.aeron.logbuffer.FragmentHandler)2 PrintStream (java.io.PrintStream)2 InetSocketAddress (java.net.InetSocketAddress)2