@Override public void setValue(final boolean flag) { bytes.writeByte(offset, flag ? TRUE : FALSE); } }
void append8bit(char[] chars) throws BufferOverflowException, IllegalArgumentException { for (int i = 0; i < chars.length; i++) { char c = chars[i]; bytesStore.writeByte(writePosition++, (byte) c); } }
@NotNull @Override public Bytes<Underlying> writeByte(long offset, byte i) throws BufferOverflowException { writeCheckOffset(offset, 1); bytesStore.writeByte(offset, i); return this; }
@NotNull @Override public Bytes<Underlying> writeByte(byte i8) throws BufferOverflowException { long offset = writeOffsetPositionMoved(1, 1); bytesStore.writeByte(offset, i8); return this; }
@NotNull protected Bytes<Underlying> append8bit0(@NotNull CharSequence cs) throws BufferOverflowException, IndexOutOfBoundsException { int length = cs.length(); long offset = writeOffsetPositionMoved(length); for (int i = 0; i < length; i++) { char c = cs.charAt(i); if (c > 255) c = '?'; bytesStore.writeByte(offset + i, (byte) c); } return this; }
@NotNull @Override public Bytes<Underlying> prewriteByte(byte i8) throws BufferOverflowException { long offset = prewriteOffsetPositionMoved(1); bytesStore.writeByte(offset, i8); return this; }
@NotNull @Override public Bytes<Underlying> writeByte(byte i8) throws BufferOverflowException { long offset = writeOffsetPositionMoved(1, 1); bytesStore.writeByte(offset, i8); return this; }
@Override public int addModificationIteratorsCount(int addition) { int oldModificationIteratorsCount = (bs.readByte(offset + 29)) & 0xFF; int newModificationIteratorsCount = oldModificationIteratorsCount + addition; if (newModificationIteratorsCount < 0 || newModificationIteratorsCount > 128) { throw new IllegalStateException("(bs.readByte(offset + 29)) & 0xFF should be in [0, 128] range, the value was " + oldModificationIteratorsCount + ", + " + addition + " = " + newModificationIteratorsCount + " out of the range"); } bs.writeByte(offset + 29, (byte) (newModificationIteratorsCount)); return newModificationIteratorsCount; }
@NotNull @Override public Bytes<Underlying> writeByte(byte i8) throws BufferOverflowException { long offset = writeOffsetPositionMoved(1, 1); bytesStore.writeByte(offset, i8); return this; }
public static void write(final boolean value, final BytesStore bytes, long offset) { bytes.writeVolatileInt(offset, value ? TRUE : FALSE); bytes.writeByte(offset + 4, (byte) 'e'); }
/** * Perform a <i>not</i> atomic add and get operation for an unsigned byte value. This method * <i>does not</i> check for unsigned byte overflow. * * @param offset to add and get * @param adding value to add, can be 1 * @return the sum */ default int addAndGetUnsignedByteNotAtomic(long offset, int adding) throws BufferUnderflowException { try { int r = (readUnsignedByte(offset) + adding) & 0xFF; writeByte(offset, (byte) r); return r; } catch (BufferOverflowException e) { throw new AssertionError(e); } }
@Override public void set(BytesStore bytes, long index, long value) { bytes.writeByte(index, Maths.toInt8(value)); }
@Override public void set(BytesStore bytes, long index, long value) { bytes.writeByte(index, Maths.toUInt8(value)); }
/** * Perform a <i>not</i> atomic add and get operation for a short value. * * @param offset to add and get * @param adding value to add, can be 1 * @return the sum */ default short addAndGetShortNotAtomic(long offset, short adding) throws BufferUnderflowException { try { short r = (short) (readShort(offset) + adding); writeByte(offset, r); return r; } catch (BufferOverflowException | IllegalArgumentException e) { throw new AssertionError(e); } }
@Override public void setModificationIteratorInitAt(int index, boolean _modificationIteratorInit) { if (index < 0 || index >= 128) { throw new ArrayIndexOutOfBoundsException(index + " is out of bounds, array length 128"); } int bitOffset = 240 + index; int byteOffset = bitOffset / 8; int bitShift = bitOffset & 7; int b = bs.readByte(offset + byteOffset); if (_modificationIteratorInit) { b |= (1 << bitShift); } else { b &= ~(1 << bitShift); } bs.writeByte(offset + byteOffset, (byte) b); }
@Override public void set(BytesStore bytes, long index, long value) { int i = bytes.readUnsignedByte(index >> 1); int i2 = (int) ((index & 1) != 0 ? (i & 0xF0) | (value & 0xF) : (i & 0xF) | ((value & 0xf) << 4)); bytes.writeByte(index, Maths.toUInt8(value)); }
@Override public void bytesStore(@NotNull final BytesStore bytes, long offset, long length) { if (length != template.length) throw new IllegalArgumentException(length + " != " + template.length); // align for ARM long newOffset = roundUpTo8ByteAlign(offset); for (long i = offset; i < newOffset; i++) { bytes.writeByte(i, (byte) ' '); } super.bytesStore(bytes, newOffset, length); if (bytes.readInt(newOffset) == UNINITIALIZED) bytes.write(newOffset, template); }
@Override public void bytesStore(@NotNull final BytesStore bytes, long offset, long length) { if (length != template.length) throw new IllegalArgumentException(); // align for ARM long newOffset = roundUpTo8ByteAlign(offset); for (long i = offset; i < newOffset; i++) { bytes.writeByte(i, (byte) ' '); } super.bytesStore(bytes, newOffset, length); if (bytes.readLong(newOffset) == UNINITIALIZED) bytes.write(newOffset, template); }
@NotNull @Override public Bytes<Void> writeByte(byte i8) throws BufferOverflowException { assert singleThreadedAccess(); long oldPosition = writePosition; if (writePosition < 0 || writePosition > capacity() - (long) 1) throw writeBufferOverflowException(writePosition); if (!bytesStore.inside(writePosition, 1)) { // already determined we need it acquireNextByteStore0(writePosition, false); } this.writePosition = writePosition + (long) 1; bytesStore.writeByte(oldPosition, i8); return this; }
@Override public void readMarshallable(BytesIn bytes) { bs.writeInt(offset + 0, ((bs.readInt(offset + 0)) & 0xFF000000) | (bytes.readInt())); bs.writeLong(offset + 3, ((bs.readLong(offset + 3)) & 0xFFFFFF0000000000L) | (bytes.readLong())); bs.writeLong(offset + 8, ((bs.readLong(offset + 8)) & 0xFFFFFF0000000000L) | (bytes.readLong())); bs.writeInt(offset + 13, (int) (bytes.readLong())); bs.writeLong(offset + 17, bytes.readLong()); bs.writeInt(offset + 25, bytes.readInt()); bs.writeByte(offset + 29, (byte) (bytes.readInt())); for (int index = 0; index < 128; index++) { setModificationIteratorInitAt(index, bytes.readBoolean()); } }