@Test @DisplayName("A chunk can be written") void put() { assume(); for (val virtual : virtuals) { assertThat(virtual).isNotZero(); val bytes = new byte[Long.BYTES]; random.nextBytes(bytes); val packet = new PacketBufferWrapper(virtual); packet.put(0, bytes.length, bytes); val copy = new byte[bytes.length]; packet.get(0, copy.length, copy); assertThat(copy).isEqualTo(bytes); } }
public void put(final int offset, int bytes, final @NotNull byte[] buffer) { if (!OPTIMIZED) { if (buffer == null) throw new NullPointerException("The parameter 'buffer' MUST NOT be null."); if (offset < 0 || offset >= buffer.length) { throw new ArrayIndexOutOfBoundsException("The parameter 'offset' MUST be in [0, buffer.length)."); } if (bytes < 0) throw new IllegalArgumentException("The parameter 'bytes' MUST be positive."); if (buffer.length < bytes) { if (DEBUG >= LOG_WARN) { log.warn("You are trying to write more bytes than the buffer can hold. Adapting bytes."); } bytes = buffer.length; } if (bytes == 0) return; } if (DEBUG >= LOG_TRACE) { log.trace("Writing packet payload chunk of {} bytes @ offset '{}'.", bytes, leftPad(offset)); } mmanager.put(virtualAddress + PAYLOAD_OFFSET, bytes, buffer, offset); }
PacketBufferWrapper implements Comparable<PacketBufferWrapper> { public void put(final int offset, int bytes, final @NotNull byte[] buffer) { if (!OPTIMIZED) { if (buffer == null) throw new NullPointerException("The parameter 'buffer' MUST NOT be null."); if (offset < 0 || offset >= buffer.length) { throw new ArrayIndexOutOfBoundsException("The parameter 'offset' MUST be in [0, buffer.length)."); } if (bytes < 0) throw new IllegalArgumentException("The parameter 'bytes' MUST be positive."); if (buffer.length < bytes) { if (DEBUG >= LOG_WARN) { log.warn("You are trying to write more bytes than the buffer can hold. Adapting bytes."); } bytes = buffer.length; } if (bytes == 0) return; } if (DEBUG >= LOG_TRACE) { log.trace("Writing packet payload chunk of {} bytes @ offset '{}'.", bytes, leftPad(offset)); } mmanager.put(virtualAddress + PAYLOAD_OFFSET, bytes, buffer, offset); } }
PacketBufferWrapper implements Comparable<PacketBufferWrapper> { public void put(final int offset, int bytes, final @NotNull byte[] buffer) { if (!OPTIMIZED) { if (buffer == null) throw new NullPointerException("The parameter 'buffer' MUST NOT be null."); if (offset < 0 || offset >= buffer.length) { throw new ArrayIndexOutOfBoundsException("The parameter 'offset' MUST be in [0, buffer.length)."); } if (bytes < 0) throw new IllegalArgumentException("The parameter 'bytes' MUST be positive."); if (buffer.length < bytes) { if (DEBUG >= LOG_WARN) { log.warn("You are trying to write more bytes than the buffer can hold. Adapting bytes."); } bytes = buffer.length; } if (bytes == 0) return; } if (DEBUG >= LOG_TRACE) { log.trace("Writing packet payload chunk of {} bytes @ offset '{}'.", bytes, leftPad(offset)); } mmanager.put(virtualAddress + PAYLOAD_OFFSET, bytes, buffer, offset); }  }
PacketBufferWrapper implements Comparable<PacketBufferWrapper> { public void put(final int offset, int bytes, final @NotNull byte[] buffer) { if (!OPTIMIZED) { if (buffer == null) throw new NullPointerException("The parameter 'buffer' MUST NOT be null."); if (offset < 0 || offset >= buffer.length) { throw new ArrayIndexOutOfBoundsException("The parameter 'offset' MUST be in [0, buffer.length)."); } if (bytes < 0) throw new IllegalArgumentException("The parameter 'bytes' MUST be positive."); if (buffer.length < bytes) { if (DEBUG >= LOG_WARN) { log.warn("You are trying to write more bytes than the buffer can hold. Adapting bytes."); } bytes = buffer.length; } if (bytes == 0) return; } if (DEBUG >= LOG_TRACE) { log.trace("Writing packet payload chunk of {} bytes @ offset '{}'.", bytes, leftPad(offset)); } mmanager.put(virtualAddress + PAYLOAD_OFFSET, bytes, buffer, offset); }  @Contract(pure = true) long getPhysicalAddress(); @Contract(pure = true) int getSize(); void setSize(final int size); byte getByte(final int offset); void putByte(final int offset, final byte value); short getShort(final int offset); void putShort(final int offset, final short value); int getInt(final int offset); void putInt(final int offset, final int value); long getLong(final int offset); void putLong(final int offset, final long value); void get(final int offset, int bytes, final @NotNull byte[] buffer); void put(final int offset, int bytes, final @NotNull byte[] buffer); @Override @Contract(pure = true) int compareTo(final @NotNull PacketBufferWrapper o); @Override @Contract(pure = true) @NotNull String toString(); }
PacketBufferWrapper implements Comparable<PacketBufferWrapper> { public void put(final int offset, int bytes, final @NotNull byte[] buffer) { if (!OPTIMIZED) { if (buffer == null) throw new NullPointerException("The parameter 'buffer' MUST NOT be null."); if (offset < 0 || offset >= buffer.length) { throw new ArrayIndexOutOfBoundsException("The parameter 'offset' MUST be in [0, buffer.length)."); } if (bytes < 0) throw new IllegalArgumentException("The parameter 'bytes' MUST be positive."); if (buffer.length < bytes) { if (DEBUG >= LOG_WARN) { log.warn("You are trying to write more bytes than the buffer can hold. Adapting bytes."); } bytes = buffer.length; } if (bytes == 0) return; } if (DEBUG >= LOG_TRACE) { log.trace("Writing packet payload chunk of {} bytes @ offset '{}'.", bytes, leftPad(offset)); } mmanager.put(virtualAddress + PAYLOAD_OFFSET, bytes, buffer, offset); }  @Contract(pure = true) long getPhysicalAddress(); @Contract(pure = true) int getSize(); void setSize(final int size); byte getByte(final int offset); void putByte(final int offset, final byte value); short getShort(final int offset); void putShort(final int offset, final short value); int getInt(final int offset); void putInt(final int offset, final int value); long getLong(final int offset); void putLong(final int offset, final long value); void get(final int offset, int bytes, final @NotNull byte[] buffer); void put(final int offset, int bytes, final @NotNull byte[] buffer); @Override @Contract(pure = true) int compareTo(final @NotNull PacketBufferWrapper o); @Override @Contract(pure = true) @NotNull String toString();  }