@Override public long start() { return bytesStore.start(); }
/** * Use this test to determine if an offset is considered safe. */ default boolean inside(long offset) { return start() <= offset && offset < safeLimit(); }
default boolean inside(long offset, int buffer) { return start() <= offset && offset + buffer < safeLimit(); }
private void initBytesStoreAndHeadersViews(BytesStore bytesStore) { if (bytesStore.start() != 0) { throw new AssertionError("bytes store " + bytesStore + " starts from " + bytesStore.start() + ", 0 expected"); } this.bs = bytesStore; //noinspection unchecked globalMutableState.bytesStore(bs, headerSize + GLOBAL_MUTABLE_STATE_VALUE_OFFSET, globalMutableState.maxSize()); onHeaderCreated(); }
private void check(@NotNull BytesStore b) { for (long i = b.start(); i < b.readLimit(); i++) { int ch = b.readByte(i); if (ch < ' ') throw new AssertionError("Char " + ch); } }
/** * Fill the BytesStore with zeros * * @param start first byte inclusive * @param end last byte exclusive. * @return this. */ @Override @NotNull default B zeroOut(long start, long end) { if (end <= start) return (B) this; if (start < start()) start = start(); if (end > capacity()) end = capacity(); long i = start; try { for (; i < end - 7; i += 8L) writeLong(i, 0L); for (; i < end; i++) writeByte(i, 0); } catch (BufferOverflowException | IllegalArgumentException e) { throw new AssertionError(e); } return (B) this; }
/** * @return a Bytes to wrap this ByteStore from the start() to the realCapacity(). * @throws IllegalStateException if this Bytes has been released. */ @Override @NotNull default Bytes<Underlying> bytesForRead() throws IllegalStateException { try { return bytesForWrite() .readLimit(writeLimit()) .readPosition(start()); } catch (BufferUnderflowException e) { throw new IllegalStateException(e); } }
@Override protected long writeOffsetPositionMoved(long adding, long advance) throws BufferOverflowException { long oldPosition = writePosition; if (writePosition < bytesStore.start()) throw new BufferOverflowException(); long writeEnd = writePosition + adding; if (writeEnd > bytesStore.safeLimit()) checkResize(writeEnd); this.writePosition = writePosition + advance; return oldPosition; }
@Override protected void writeCheckOffset(long offset, long adding) throws BufferOverflowException { if (offset < bytesStore.start()) throw new BufferOverflowException(); long writeEnd = offset + adding; if (writeEnd > bytesStore.safeLimit()) checkResize(writeEnd); }
@NotNull private net.openhft.lang.io.Bytes toLangBytes(@NotNull BytesStore b, @NotNull Bytes tmpBytes, @NotNull net.openhft.lang.io.NativeBytes lb) { if (b.isDirectMemory()) { // check(b); lb.setStartPositionAddress(b.address(b.start()), b.address(b.readLimit())); // check(lb); } else { tmpBytes.clear(); tmpBytes.write(b); lb.setStartPositionAddress(tmpBytes.address(tmpBytes.start()), tmpBytes.address(tmpBytes.readLimit())); } return lb; }