Update method names and javadocs

Motivation:
There's a desire to be able to clearly tell from a method name, whether or not it updates the reader or writer offsets.

Modification:
The accessor methods that take offsets as arguments (and thus do not update reader or writer offsets) have now been changed to follow a get/set naming pattern.
The methods that *do* update reader and writer offsets are still following a read/write naming pattern.

Result:
This makes it even more clear, whether or not the relative offsets are updated or not.
This commit is contained in:
Chris Vest 2020-11-11 23:00:08 +01:00
parent ca32784fe8
commit bb5aff940f
5 changed files with 825 additions and 752 deletions

View File

@ -21,7 +21,87 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
/**
* A reference counted buffer API with separate reader and writer indexes.
* A reference counted buffer of memory, with separate reader and writer offsets.
* <p>
* A buffer is a sequential stretch of memory with a certain capacity, an offset for writing, and an offset for reading.
*
* <h3>Creating a buffer</h3>
*
* Buffers are created by {@linkplain Allocator allocators}, and their {@code allocate} family of methods.
* A number of standard allocators exist, and ara available through static methods on the {@code Allocator} interface.
*
* <h3>Life cycle and reference counting</h3>
*
* The buffer has a life cycle, where it is allocated, used, and deallocated.
* The reference count controls this life cycle.
* <p>
* When the buffer is initially allocated, a pairing {@link #close()} call will deallocate it.
* In this state, the buffer is "owned".
* <p>
* The buffer can also be {@linkplain #acquire() acquired} when it's about to be involved in a complicated life time.
* The {@link #acquire()} call increments the reference count of the buffer,
* and a pairing {@link #close()} call will decrement the reference count.
* Each acquire lends out the buffer, and the buffer is said to be in a "borrowed" state.
* <p>
* Certain operations, such as {@link #send()}, are only available on owned buffers.
*
* <h3>Thread-safety</h3>
*
* Buffers are not thread-safe.
* The reference counting implied by the {@link Rc} interface is itself not thread-safe,
* and buffers additionally contain other mutable data that is not thread-safe.
* Depending on the buffer implementation, the buffer may impose confinement restrictions as well,
* so that the buffer cannot even be read using absolute offsets,
* such as with the {@link #getByte(int)} method,
* from multiple threads.
* <p>
* Confined buffers will initially be confined to the thread that allocates them.
* <p>
* If a buffer needs to be accessed by a different thread,
* then the ownership of that buffer must be sent to that thread.
* This can be done with the {@link #send()} method.
* The send method consumes the buffer, if it is in an owned state, and produces a {@link Send} object.
* The {@link Send} object can then be shared in a thread-safe way (so called "safe publication"),
* with the intended recipient thread.
* <p>
* To send a buffer to another thread, the buffer must not have any outstanding borrows.
* That is to say, all {@linkplain #acquire() acquires} must have been paired with a {@link #close()};
* all {@linkplain #slice() slices} must have been closed.
* And if this buffer is a constituent of a {@linkplain #compose(Buf...) composite buffer},
* then that composite buffer must be closed.
* And if this buffer is itself a composite buffer, then it must own all of its constituent buffers.
* The {@link #isSendable()} method can be used on any buffer to check if it can be sent or not.
*
* <h3>Accessing data</h3>
*
* Data access methods fall into two classes:
* <ol>
* <li>Access that are based on, and updates, the read or write offset positions.</li>
* <ul><li>These accessor methods are typically called {@code readX} or {@code writeX}.</li></ul>
* <li>Access that take offsets as arguments, and do not update read or write offset positions.</li>
* <ul><li>These accessor methods are typically called {@code getX} or {@code setX}.</li></ul>
* </ol>
*
* A buffer contain two mutable offset positions: one for reading and one for writing.
* These positions use <a href="https://en.wikipedia.org/wiki/Zero-based_numbering">zero-based indexing</a>,
* such that the first byte of data in the buffer is placed at offset {@code 0},
* and the last byte in the buffer is at offset {@link #capacity() capacity - 1}.
* The {@link #readerOffset()} is the offset into the buffer from which the next read will take place,
* and is initially zero.
* The reader offset must always be less than or equal to the {@link #writerOffset()}.
* The {@link #writerOffset()} is likewise the offset into the buffer where the next write will take place.
* The writer offset is also initially zero, and must be less than or equal to the {@linkplain #capacity() capacity}.
* <p>
* This carves the buffer into three regions, as demonstrated by this diagram:
* <pre>
* +-------------------+------------------+------------------+
* | discardable bytes | readable bytes | writable bytes |
* | | (CONTENT) | |
* +-------------------+------------------+------------------+
* | | | |
* 0 <= readerOffset <= writerOffset <= capacity
* </pre>
*
*/
public interface Buf extends Rc<Buf>, BufAccessors {
/**
@ -49,10 +129,10 @@ public interface Buf extends Rc<Buf>, BufAccessors {
* The read and write offsets of the constituent buffers must be arranged such that there are no "gaps" when viewed
* as a single connected chunk of memory.
* Specifically, there can be at most one buffer whose write offset is neither zero nor at capacity,
* and all buffers prior to it must have their write indexes at capacity, and all buffers after it must have a write
* and all buffers prior to it must have their write offsets at capacity, and all buffers after it must have a write
* offset of zero.
* Likewise, there can be at most one buffer whose read offset is neither zero nor at capacity,
* and all buffers prior to it must have their read indexes at capacity, and all buffers after it must have a read
* and all buffers prior to it must have their read offsets at capacity, and all buffers after it must have a read
* offset of zero.
* Furthermore, the sum of the read offsets must be less than or equal to the sum of the write offsets.
* <p>
@ -91,72 +171,63 @@ public interface Buf extends Rc<Buf>, BufAccessors {
int capacity();
/**
* Get the current reader index. The next read will happen from this byte index into the buffer.
* Get the current reader offset. The next read will happen from this byte offset into the buffer.
*
* @return The current reader index.
* @return The current reader offset.
*/
int readerIndex();
int readerOffset();
/**
* Set the reader index. Make the next read happen from the given index.
* Set the reader offset. Make the next read happen from the given offset into the buffer.
*
* @param index The reader index to set.
* @param offset The reader offset to set.
* @return This Buf.
* @throws IndexOutOfBoundsException if the specified {@code index} is less than zero or greater than the current
* {@link #writerIndex()}.
* @throws IndexOutOfBoundsException if the specified {@code offset} is less than zero or greater than the current
* {@link #writerOffset()}.
*/
Buf readerIndex(int index);
Buf readerOffset(int offset);
/**
* Get the current writer index. The next write will happen at this byte index into the byffer.
* Get the current writer offset. The next write will happen at this byte offset into the byffer.
*
* @return The current writer index.
* @return The current writer offset.
*/
int writerIndex();
int writerOffset();
/**
* Set the writer index. Make the next write happen at the given index.
* Set the writer offset. Make the next write happen at the given offset.
*
* @param index The writer index to set.
* @param offset The writer offset to set.
* @return This Buf.
* @throws IndexOutOfBoundsException if the specified {@code index} is less than the current {@link #readerIndex()}
* @throws IndexOutOfBoundsException if the specified {@code offset} is less than the current {@link #readerOffset()}
* or greater than {@link #capacity()}.
*/
Buf writerIndex(int index);
Buf writerOffset(int offset);
/**
* Returns the number of readable bytes which is equal to {@code (writerIndex() - readerIndex())}.
* Returns the number of readable bytes which is equal to {@code (writerOffset() - readerOffset())}.
*/
default int readableBytes() {
return writerIndex() - readerIndex();
return writerOffset() - readerOffset();
}
/**
* Returns the number of writable bytes which is equal to {@code (capacity() - writerIndex())}.
* Returns the number of writable bytes which is equal to {@code (capacity() - writerOffset())}.
*/
default int writableBytes() {
return capacity() - writerIndex();
return capacity() - writerOffset();
}
/**
* Fill the buffer with the given byte value. This method does not respect the {@link #readerIndex()} or {@link
* #writerIndex()}, but copies the full capacity of the buffer. The {@link #readerIndex()} and {@link
* #writerIndex()} are not modified.
* Fill the buffer with the given byte value. This method does not respect the {@link #readerOffset()} or {@link
* #writerOffset()}, but copies the full capacity of the buffer. The {@link #readerOffset()} and {@link
* #writerOffset()} are not modified.
*
* @param value The byte value to write at every index in the buffer.
* @param value The byte value to write at every position in the buffer.
* @return This Buf.
*/
Buf fill(byte value);
/**
* Create a byte array, and fill it with the complete contents of this buffer. This method does not respect the
* {@link #readerIndex()} or {@link #writerIndex()}, but copies the full capacity of the buffer. The {@link
* #readerIndex()} and {@link #writerIndex()} are not modified.
*
* @return A byte array that contains a copy of the contents of this buffer.
*/
byte[] copy();
/**
* Give the native memory address backing this buffer, or return 0 if this buffer has no native memory address.
* @return The native memory address, if any, otherwise 0.
@ -166,30 +237,30 @@ public interface Buf extends Rc<Buf>, BufAccessors {
/**
* Returns a slice of this buffer's readable bytes.
* Modifying the content of the returned buffer or this buffer affects each other's content,
* while they maintain separate indexes. This method is identical to
* {@code buf.slice(buf.readerIndex(), buf.readableBytes())}.
* This method does not modify {@link #readerIndex()} or {@link #writerIndex()} of this buffer.
* while they maintain separate offsets. This method is identical to
* {@code buf.slice(buf.readerOffset(), buf.readableBytes())}.
* This method does not modify {@link #readerOffset()} or {@link #writerOffset()} of this buffer.
* <p>
* This method increments the reference count of this buffer.
* The reference count is decremented again when the slice is deallocated.
*
* @return A new buffer instance, with independent {@link #readerIndex()} and {@link #writerIndex()},
* @return A new buffer instance, with independent {@link #readerOffset()} and {@link #writerOffset()},
* that is a view of the readable region of this buffer.
*/
default Buf slice() {
return slice(readerIndex(), readableBytes());
return slice(readerOffset(), readableBytes());
}
/**
* Returns a slice of the given region of this buffer.
* Modifying the content of the returned buffer or this buffer affects each other's content,
* while they maintain separate indexes.
* This method does not modify {@link #readerIndex()} or {@link #writerIndex()} of this buffer.
* while they maintain separate offsets.
* This method does not modify {@link #readerOffset()} or {@link #writerOffset()} of this buffer.
* <p>
* This method increments the reference count of this buffer.
* The reference count is decremented again when the slice is deallocated.
*
* @return A new buffer instance, with independent {@link #readerIndex()} and {@link #writerIndex()},
* @return A new buffer instance, with independent {@link #readerOffset()} and {@link #writerOffset()},
* that is a view of the given region of this buffer.
*/
Buf slice(int offset, int length);
@ -198,8 +269,8 @@ public interface Buf extends Rc<Buf>, BufAccessors {
* Copies the given length of data from this buffer into the given destination array, beginning at the given source
* position in this buffer, and the given destination position in the destination array.
* <p>
* This method does not read or modify the {@linkplain #writerIndex() write offset} or the
* {@linkplain #readerIndex() read offset}.
* This method does not read or modify the {@linkplain #writerOffset() write offset} or the
* {@linkplain #readerOffset() read offset}.
*
* @param srcPos The byte offset into this buffer wherefrom the copying should start; the byte at this offset in
* this buffer will be copied to the {@code destPos} index in the {@code dest} array.
@ -216,8 +287,8 @@ public interface Buf extends Rc<Buf>, BufAccessors {
* Copies the given length of data from this buffer into the given destination byte buffer, beginning at the given
* source position in this buffer, and the given destination position in the destination byte buffer.
* <p>
* This method does not read or modify the {@linkplain #writerIndex() write offset} or the
* {@linkplain #readerIndex() read offset}, nor is the position of the destination buffer changed.
* This method does not read or modify the {@linkplain #writerOffset() write offset} or the
* {@linkplain #readerOffset() read offset}, nor is the position of the destination buffer changed.
* <p>
* The position and limit of the destination byte buffer are also ignored, and do not influence {@code destPos}
* or {@code length}.
@ -237,8 +308,8 @@ public interface Buf extends Rc<Buf>, BufAccessors {
* Copies the given length of data from this buffer into the given destination buffer, beginning at the given
* source position in this buffer, and the given destination position in the destination buffer.
* <p>
* This method does not read or modify the {@linkplain #writerIndex() write offset} or the
* {@linkplain #readerIndex() read offset} on this buffer, nor on the destination buffer.
* This method does not read or modify the {@linkplain #writerOffset() write offset} or the
* {@linkplain #readerOffset() read offset} on this buffer, nor on the destination buffer.
* <p>
* The read and write offsets of the destination buffer are also ignored, and do not influence {@code destPos}
* or {@code length}.
@ -255,35 +326,35 @@ public interface Buf extends Rc<Buf>, BufAccessors {
void copyInto(int srcPos, Buf dest, int destPos, int length);
/**
* Resets the {@linkplain #readerIndex() read offset} and the {@linkplain #writerIndex() write offset} on this
* Resets the {@linkplain #readerOffset() read offset} and the {@linkplain #writerOffset() write offset} on this
* buffer to their initial values.
*/
default void reset() {
readerIndex(0);
writerIndex(0);
readerOffset(0);
writerOffset(0);
}
/**
* Iterate the readable bytes of this buffer. The {@linkplain #readerIndex() reader offset} and
* {@linkplain #writerIndex() witer offset} are not modified by the iterator.
* Iterate the readable bytes of this buffer. The {@linkplain #readerOffset() reader offset} and
* {@linkplain #writerOffset() witer offset} are not modified by the iterator.
* <p>
* Care should be taken to ensure that the buffers lifetime extends beyond the iteration, and the
* {@linkplain #readerIndex() reader offset} and {@linkplain #writerIndex() writer offset} are not modified while
* {@linkplain #readerOffset() reader offset} and {@linkplain #writerOffset() writer offset} are not modified while
* the iteration takes place. Otherwise unpredictable behaviour might result.
*
* @return A {@link ByteIterator} for the readable bytes of this buffer.
*/
default ByteIterator iterate() {
return iterate(readerIndex(), readableBytes());
return iterate(readerOffset(), readableBytes());
}
/**
* Iterate the given number bytes of this buffer, starting at the given offset.
* The {@linkplain #readerIndex() reader offset} and {@linkplain #writerIndex() witer offset} are not modified by
* The {@linkplain #readerOffset() reader offset} and {@linkplain #writerOffset() witer offset} are not modified by
* the iterator.
* <p>
* Care should be taken to ensure that the buffers lifetime extends beyond the iteration, and the
* {@linkplain #readerIndex() reader offset} and {@linkplain #writerIndex() writer offset} are not modified while
* {@linkplain #readerOffset() reader offset} and {@linkplain #writerOffset() writer offset} are not modified while
* the iteration takes place. Otherwise unpredictable behaviour might result.
*
* @param fromOffset The offset into the buffer where iteration should start.
@ -296,27 +367,27 @@ public interface Buf extends Rc<Buf>, BufAccessors {
ByteIterator iterate(int fromOffset, int length);
/**
* Iterate the readable bytes of this buffer, in reverse. The {@linkplain #readerIndex() reader offset} and
* {@linkplain #writerIndex() witer offset} are not modified by the iterator.
* Iterate the readable bytes of this buffer, in reverse. The {@linkplain #readerOffset() reader offset} and
* {@linkplain #writerOffset() witer offset} are not modified by the iterator.
* <p>
* Care should be taken to ensure that the buffers lifetime extends beyond the iteration, and the
* {@linkplain #readerIndex() reader offset} and {@linkplain #writerIndex() writer offset} are not modified while
* {@linkplain #readerOffset() reader offset} and {@linkplain #writerOffset() writer offset} are not modified while
* the iteration takes place. Otherwise unpredictable behaviour might result.
*
* @return A {@link ByteIterator} for the readable bytes of this buffer.
*/
default ByteIterator iterateReverse() {
int woff = writerIndex();
int woff = writerOffset();
return iterateReverse(woff == 0? 0 : woff - 1, readableBytes());
}
/**
* Iterate the given number bytes of this buffer, in reverse, starting at the given offset.
* The {@linkplain #readerIndex() reader offset} and {@linkplain #writerIndex() witer offset} are not modified by
* The {@linkplain #readerOffset() reader offset} and {@linkplain #writerOffset() witer offset} are not modified by
* the iterator.
* <p>
* Care should be taken to ensure that the buffers lifetime extends beyond the iteration, and the
* {@linkplain #readerIndex() reader offset} and {@linkplain #writerIndex() writer offset} are not modified while
* {@linkplain #readerOffset() reader offset} and {@linkplain #writerOffset() writer offset} are not modified while
* the iteration takes place. Otherwise unpredictable behaviour might result.
*
* @param fromOffset The offset into the buffer where iteration should start.

View File

@ -21,11 +21,9 @@ package io.netty.buffer.b2;
* Usually, you'd use the {@link Buf} interface directly, since this lets you properly control the buffer reference count.
*/
public interface BufAccessors {
// ### CODEGEN START primitive accessors interface
// <editor-fold defaultstate="collapsed" desc="Generated primitive accessors interface.">
// <editor-fold defaultstate="collapsed" desc="Primitive accessors interface.">
/**
* Get the byte value at the current {@link Buf#readerIndex()},
* Get the byte value at the current {@link Buf#readerOffset()},
* and increases the reader offset by {@link Byte#BYTES}.
* The value is read using a two's complement 8-bit encoding,
* with the {@link Buf#order() configured} default byte order.
@ -37,19 +35,19 @@ public interface BufAccessors {
/**
* Get the byte value at the given reader offset.
* The {@link Buf#readerIndex()} is not modified.
* The {@link Buf#readerOffset()} is not modified.
* The value is read using a two's complement 8-bit encoding,
* with the {@link Buf#order() configured} default byte order.
*
* @param roff The read offset, an absolute index into this buffer, to read from.
* @param roff The read offset, an absolute offset into this buffer, to read from.
* @return The byte value at the given offset.
* @throws IndexOutOfBoundsException if the given index is out of bounds of the buffer, that is, less than 0 or
* @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or
* greater than or equal to {@link Buf#capacity()} minus {@link Byte#BYTES}.
*/
byte readByte(int roff);
byte getByte(int roff);
/**
* Get the unsigned byte value at the current {@link Buf#readerIndex()},
* Get the unsigned byte value at the current {@link Buf#readerOffset()},
* and increases the reader offset by {@link Byte#BYTES}.
* The value is read using an unsigned two's complement 8-bit encoding,
* with the {@link Buf#order() configured} default byte order.
@ -61,19 +59,19 @@ public interface BufAccessors {
/**
* Get the unsigned byte value at the given reader offset.
* The {@link Buf#readerIndex()} is not modified.
* The {@link Buf#readerOffset()} is not modified.
* The value is read using an unsigned two's complement 8-bit encoding,
* with the {@link Buf#order() configured} default byte order.
*
* @param roff The read offset, an absolute index into this buffer, to read from.
* @param roff The read offset, an absolute offset into this buffer, to read from.
* @return The unsigned byte value at the given offset.
* @throws IndexOutOfBoundsException if the given index is out of bounds of the buffer, that is, less than 0 or
* @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or
* greater than or equal to {@link Buf#capacity()} minus {@link Byte#BYTES}.
*/
int readUnsignedByte(int roff);
int getUnsignedByte(int roff);
/**
* Set the given byte value at the current {@link Buf#writerIndex()},
* Set the given byte value at the current {@link Buf#writerOffset()},
* and increase the writer offset by {@link Byte#BYTES}.
* The value is written using a two's complement 8-bit encoding,
* with the {@link Buf#order() configured} default byte order.
@ -85,20 +83,20 @@ public interface BufAccessors {
Buf writeByte(byte value);
/**
* Set the given byte value at the given write offset. The {@link Buf#writerIndex()} is not modified.
* Set the given byte value at the given write offset. The {@link Buf#writerOffset()} is not modified.
* The value is written using a two's complement 8-bit encoding,
* with the {@link Buf#order() configured} default byte order.
*
* @param woff The write offset, an absolute index into this buffer to write to.
* @param woff The write offset, an absolute offset into this buffer to write to.
* @param value The byte value to write.
* @return This Buf.
* @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or
* greater than or equal to {@link Buf#capacity()} minus {@link Byte#BYTES}.
*/
Buf writeByte(int woff, byte value);
Buf setByte(int woff, byte value);
/**
* Set the given unsigned byte value at the current {@link Buf#writerIndex()},
* Set the given unsigned byte value at the current {@link Buf#writerOffset()},
* and increase the writer offset by {@link Byte#BYTES}.
* The value is written using an unsigned two's complement 8-bit encoding,
* with the {@link Buf#order() configured} default byte order.
@ -110,20 +108,20 @@ public interface BufAccessors {
Buf writeUnsignedByte(int value);
/**
* Set the given unsigned byte value at the given write offset. The {@link Buf#writerIndex()} is not modified.
* Set the given unsigned byte value at the given write offset. The {@link Buf#writerOffset()} is not modified.
* The value is written using an unsigned two's complement 8-bit encoding,
* with the {@link Buf#order() configured} default byte order.
*
* @param woff The write offset, an absolute index into this buffer to write to.
* @param woff The write offset, an absolute offset into this buffer to write to.
* @param value The int value to write.
* @return This Buf.
* @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or
* greater than or equal to {@link Buf#capacity()} minus {@link Byte#BYTES}.
*/
Buf writeUnsignedByte(int woff, int value);
Buf setUnsignedByte(int woff, int value);
/**
* Get the char value at the current {@link Buf#readerIndex()},
* Get the char value at the current {@link Buf#readerOffset()},
* and increases the reader offset by 2.
* The value is read using a 2-byte UTF-16 encoding,
* with the {@link Buf#order() configured} default byte order.
@ -135,19 +133,19 @@ public interface BufAccessors {
/**
* Get the char value at the given reader offset.
* The {@link Buf#readerIndex()} is not modified.
* The {@link Buf#readerOffset()} is not modified.
* The value is read using a 2-byte UTF-16 encoding,
* with the {@link Buf#order() configured} default byte order.
*
* @param roff The read offset, an absolute index into this buffer, to read from.
* @param roff The read offset, an absolute offset into this buffer, to read from.
* @return The char value at the given offset.
* @throws IndexOutOfBoundsException if the given index is out of bounds of the buffer, that is, less than 0 or
* @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or
* greater than or equal to {@link Buf#capacity()} minus 2.
*/
char readChar(int roff);
char getChar(int roff);
/**
* Set the given char value at the current {@link Buf#writerIndex()},
* Set the given char value at the current {@link Buf#writerOffset()},
* and increase the writer offset by 2.
* The value is written using a 2-byte UTF-16 encoding,
* with the {@link Buf#order() configured} default byte order.
@ -159,20 +157,20 @@ public interface BufAccessors {
Buf writeChar(char value);
/**
* Set the given char value at the given write offset. The {@link Buf#writerIndex()} is not modified.
* Set the given char value at the given write offset. The {@link Buf#writerOffset()} is not modified.
* The value is written using a 2-byte UTF-16 encoding,
* with the {@link Buf#order() configured} default byte order.
*
* @param woff The write offset, an absolute index into this buffer to write to.
* @param woff The write offset, an absolute offset into this buffer to write to.
* @param value The char value to write.
* @return This Buf.
* @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or
* greater than or equal to {@link Buf#capacity()} minus 2.
*/
Buf writeChar(int woff, char value);
Buf setChar(int woff, char value);
/**
* Get the short value at the current {@link Buf#readerIndex()},
* Get the short value at the current {@link Buf#readerOffset()},
* and increases the reader offset by {@link Short#BYTES}.
* The value is read using a two's complement 16-bit encoding,
* with the {@link Buf#order() configured} default byte order.
@ -184,19 +182,19 @@ public interface BufAccessors {
/**
* Get the short value at the given reader offset.
* The {@link Buf#readerIndex()} is not modified.
* The {@link Buf#readerOffset()} is not modified.
* The value is read using a two's complement 16-bit encoding,
* with the {@link Buf#order() configured} default byte order.
*
* @param roff The read offset, an absolute index into this buffer, to read from.
* @param roff The read offset, an absolute offset into this buffer, to read from.
* @return The short value at the given offset.
* @throws IndexOutOfBoundsException if the given index is out of bounds of the buffer, that is, less than 0 or
* @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or
* greater than or equal to {@link Buf#capacity()} minus {@link Short#BYTES}.
*/
short readShort(int roff);
short getShort(int roff);
/**
* Get the unsigned short value at the current {@link Buf#readerIndex()},
* Get the unsigned short value at the current {@link Buf#readerOffset()},
* and increases the reader offset by {@link Short#BYTES}.
* The value is read using an unsigned two's complement 16-bit encoding,
* with the {@link Buf#order() configured} default byte order.
@ -208,19 +206,19 @@ public interface BufAccessors {
/**
* Get the unsigned short value at the given reader offset.
* The {@link Buf#readerIndex()} is not modified.
* The {@link Buf#readerOffset()} is not modified.
* The value is read using an unsigned two's complement 16-bit encoding,
* with the {@link Buf#order() configured} default byte order.
*
* @param roff The read offset, an absolute index into this buffer, to read from.
* @param roff The read offset, an absolute offset into this buffer, to read from.
* @return The unsigned short value at the given offset.
* @throws IndexOutOfBoundsException if the given index is out of bounds of the buffer, that is, less than 0 or
* @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or
* greater than or equal to {@link Buf#capacity()} minus {@link Short#BYTES}.
*/
int readUnsignedShort(int roff);
int getUnsignedShort(int roff);
/**
* Set the given short value at the current {@link Buf#writerIndex()},
* Set the given short value at the current {@link Buf#writerOffset()},
* and increase the writer offset by {@link Short#BYTES}.
* The value is written using a two's complement 16-bit encoding,
* with the {@link Buf#order() configured} default byte order.
@ -232,20 +230,20 @@ public interface BufAccessors {
Buf writeShort(short value);
/**
* Set the given short value at the given write offset. The {@link Buf#writerIndex()} is not modified.
* Set the given short value at the given write offset. The {@link Buf#writerOffset()} is not modified.
* The value is written using a two's complement 16-bit encoding,
* with the {@link Buf#order() configured} default byte order.
*
* @param woff The write offset, an absolute index into this buffer to write to.
* @param woff The write offset, an absolute offset into this buffer to write to.
* @param value The short value to write.
* @return This Buf.
* @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or
* greater than or equal to {@link Buf#capacity()} minus {@link Short#BYTES}.
*/
Buf writeShort(int woff, short value);
Buf setShort(int woff, short value);
/**
* Set the given unsigned short value at the current {@link Buf#writerIndex()},
* Set the given unsigned short value at the current {@link Buf#writerOffset()},
* and increase the writer offset by {@link Short#BYTES}.
* The value is written using an unsigned two's complement 16-bit encoding,
* with the {@link Buf#order() configured} default byte order.
@ -257,20 +255,20 @@ public interface BufAccessors {
Buf writeUnsignedShort(int value);
/**
* Set the given unsigned short value at the given write offset. The {@link Buf#writerIndex()} is not modified.
* Set the given unsigned short value at the given write offset. The {@link Buf#writerOffset()} is not modified.
* The value is written using an unsigned two's complement 16-bit encoding,
* with the {@link Buf#order() configured} default byte order.
*
* @param woff The write offset, an absolute index into this buffer to write to.
* @param woff The write offset, an absolute offset into this buffer to write to.
* @param value The int value to write.
* @return This Buf.
* @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or
* greater than or equal to {@link Buf#capacity()} minus {@link Short#BYTES}.
*/
Buf writeUnsignedShort(int woff, int value);
Buf setUnsignedShort(int woff, int value);
/**
* Get the int value at the current {@link Buf#readerIndex()},
* Get the int value at the current {@link Buf#readerOffset()},
* and increases the reader offset by 3.
* The value is read using a two's complement 24-bit encoding,
* with the {@link Buf#order() configured} default byte order.
@ -282,19 +280,19 @@ public interface BufAccessors {
/**
* Get the int value at the given reader offset.
* The {@link Buf#readerIndex()} is not modified.
* The {@link Buf#readerOffset()} is not modified.
* The value is read using a two's complement 24-bit encoding,
* with the {@link Buf#order() configured} default byte order.
*
* @param roff The read offset, an absolute index into this buffer, to read from.
* @param roff The read offset, an absolute offset into this buffer, to read from.
* @return The int value at the given offset.
* @throws IndexOutOfBoundsException if the given index is out of bounds of the buffer, that is, less than 0 or
* @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or
* greater than or equal to {@link Buf#capacity()} minus 3.
*/
int readMedium(int roff);
int getMedium(int roff);
/**
* Get the unsigned int value at the current {@link Buf#readerIndex()},
* Get the unsigned int value at the current {@link Buf#readerOffset()},
* and increases the reader offset by 3.
* The value is read using an unsigned two's complement 24-bit encoding,
* with the {@link Buf#order() configured} default byte order.
@ -306,19 +304,19 @@ public interface BufAccessors {
/**
* Get the unsigned int value at the given reader offset.
* The {@link Buf#readerIndex()} is not modified.
* The {@link Buf#readerOffset()} is not modified.
* The value is read using an unsigned two's complement 24-bit encoding,
* with the {@link Buf#order() configured} default byte order.
*
* @param roff The read offset, an absolute index into this buffer, to read from.
* @param roff The read offset, an absolute offset into this buffer, to read from.
* @return The unsigned int value at the given offset.
* @throws IndexOutOfBoundsException if the given index is out of bounds of the buffer, that is, less than 0 or
* @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or
* greater than or equal to {@link Buf#capacity()} minus 3.
*/
int readUnsignedMedium(int roff);
int getUnsignedMedium(int roff);
/**
* Set the given int value at the current {@link Buf#writerIndex()},
* Set the given int value at the current {@link Buf#writerOffset()},
* and increase the writer offset by 3.
* The value is written using a two's complement 24-bit encoding,
* with the {@link Buf#order() configured} default byte order.
@ -330,20 +328,20 @@ public interface BufAccessors {
Buf writeMedium(int value);
/**
* Set the given int value at the given write offset. The {@link Buf#writerIndex()} is not modified.
* Set the given int value at the given write offset. The {@link Buf#writerOffset()} is not modified.
* The value is written using a two's complement 24-bit encoding,
* with the {@link Buf#order() configured} default byte order.
*
* @param woff The write offset, an absolute index into this buffer to write to.
* @param woff The write offset, an absolute offset into this buffer to write to.
* @param value The int value to write.
* @return This Buf.
* @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or
* greater than or equal to {@link Buf#capacity()} minus 3.
*/
Buf writeMedium(int woff, int value);
Buf setMedium(int woff, int value);
/**
* Set the given unsigned int value at the current {@link Buf#writerIndex()},
* Set the given unsigned int value at the current {@link Buf#writerOffset()},
* and increase the writer offset by 3.
* The value is written using an unsigned two's complement 24-bit encoding,
* with the {@link Buf#order() configured} default byte order.
@ -355,20 +353,20 @@ public interface BufAccessors {
Buf writeUnsignedMedium(int value);
/**
* Set the given unsigned int value at the given write offset. The {@link Buf#writerIndex()} is not modified.
* Set the given unsigned int value at the given write offset. The {@link Buf#writerOffset()} is not modified.
* The value is written using an unsigned two's complement 24-bit encoding,
* with the {@link Buf#order() configured} default byte order.
*
* @param woff The write offset, an absolute index into this buffer to write to.
* @param woff The write offset, an absolute offset into this buffer to write to.
* @param value The int value to write.
* @return This Buf.
* @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or
* greater than or equal to {@link Buf#capacity()} minus 3.
*/
Buf writeUnsignedMedium(int woff, int value);
Buf setUnsignedMedium(int woff, int value);
/**
* Get the int value at the current {@link Buf#readerIndex()},
* Get the int value at the current {@link Buf#readerOffset()},
* and increases the reader offset by {@link Integer#BYTES}.
* The value is read using a two's complement 32-bit encoding,
* with the {@link Buf#order() configured} default byte order.
@ -380,19 +378,19 @@ public interface BufAccessors {
/**
* Get the int value at the given reader offset.
* The {@link Buf#readerIndex()} is not modified.
* The {@link Buf#readerOffset()} is not modified.
* The value is read using a two's complement 32-bit encoding,
* with the {@link Buf#order() configured} default byte order.
*
* @param roff The read offset, an absolute index into this buffer, to read from.
* @param roff The read offset, an absolute offset into this buffer, to read from.
* @return The int value at the given offset.
* @throws IndexOutOfBoundsException if the given index is out of bounds of the buffer, that is, less than 0 or
* @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or
* greater than or equal to {@link Buf#capacity()} minus {@link Integer#BYTES}.
*/
int readInt(int roff);
int getInt(int roff);
/**
* Get the unsigned int value at the current {@link Buf#readerIndex()},
* Get the unsigned int value at the current {@link Buf#readerOffset()},
* and increases the reader offset by {@link Integer#BYTES}.
* The value is read using an unsigned two's complement 32-bit encoding,
* with the {@link Buf#order() configured} default byte order.
@ -404,19 +402,19 @@ public interface BufAccessors {
/**
* Get the unsigned int value at the given reader offset.
* The {@link Buf#readerIndex()} is not modified.
* The {@link Buf#readerOffset()} is not modified.
* The value is read using an unsigned two's complement 32-bit encoding,
* with the {@link Buf#order() configured} default byte order.
*
* @param roff The read offset, an absolute index into this buffer, to read from.
* @param roff The read offset, an absolute offset into this buffer, to read from.
* @return The unsigned int value at the given offset.
* @throws IndexOutOfBoundsException if the given index is out of bounds of the buffer, that is, less than 0 or
* @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or
* greater than or equal to {@link Buf#capacity()} minus {@link Integer#BYTES}.
*/
long readUnsignedInt(int roff);
long getUnsignedInt(int roff);
/**
* Set the given int value at the current {@link Buf#writerIndex()},
* Set the given int value at the current {@link Buf#writerOffset()},
* and increase the writer offset by {@link Integer#BYTES}.
* The value is written using a two's complement 32-bit encoding,
* with the {@link Buf#order() configured} default byte order.
@ -428,20 +426,20 @@ public interface BufAccessors {
Buf writeInt(int value);
/**
* Set the given int value at the given write offset. The {@link Buf#writerIndex()} is not modified.
* Set the given int value at the given write offset. The {@link Buf#writerOffset()} is not modified.
* The value is written using a two's complement 32-bit encoding,
* with the {@link Buf#order() configured} default byte order.
*
* @param woff The write offset, an absolute index into this buffer to write to.
* @param woff The write offset, an absolute offset into this buffer to write to.
* @param value The int value to write.
* @return This Buf.
* @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or
* greater than or equal to {@link Buf#capacity()} minus {@link Integer#BYTES}.
*/
Buf writeInt(int woff, int value);
Buf setInt(int woff, int value);
/**
* Set the given unsigned int value at the current {@link Buf#writerIndex()},
* Set the given unsigned int value at the current {@link Buf#writerOffset()},
* and increase the writer offset by {@link Integer#BYTES}.
* The value is written using an unsigned two's complement 32-bit encoding,
* with the {@link Buf#order() configured} default byte order.
@ -453,20 +451,20 @@ public interface BufAccessors {
Buf writeUnsignedInt(long value);
/**
* Set the given unsigned int value at the given write offset. The {@link Buf#writerIndex()} is not modified.
* Set the given unsigned int value at the given write offset. The {@link Buf#writerOffset()} is not modified.
* The value is written using an unsigned two's complement 32-bit encoding,
* with the {@link Buf#order() configured} default byte order.
*
* @param woff The write offset, an absolute index into this buffer to write to.
* @param woff The write offset, an absolute offset into this buffer to write to.
* @param value The long value to write.
* @return This Buf.
* @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or
* greater than or equal to {@link Buf#capacity()} minus {@link Integer#BYTES}.
*/
Buf writeUnsignedInt(int woff, long value);
Buf setUnsignedInt(int woff, long value);
/**
* Get the float value at the current {@link Buf#readerIndex()},
* Get the float value at the current {@link Buf#readerOffset()},
* and increases the reader offset by {@link Float#BYTES}.
* The value is read using a 32-bit IEEE floating point encoding,
* with the {@link Buf#order() configured} default byte order.
@ -478,19 +476,19 @@ public interface BufAccessors {
/**
* Get the float value at the given reader offset.
* The {@link Buf#readerIndex()} is not modified.
* The {@link Buf#readerOffset()} is not modified.
* The value is read using a 32-bit IEEE floating point encoding,
* with the {@link Buf#order() configured} default byte order.
*
* @param roff The read offset, an absolute index into this buffer, to read from.
* @param roff The read offset, an absolute offset into this buffer, to read from.
* @return The float value at the given offset.
* @throws IndexOutOfBoundsException if the given index is out of bounds of the buffer, that is, less than 0 or
* @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or
* greater than or equal to {@link Buf#capacity()} minus {@link Float#BYTES}.
*/
float readFloat(int roff);
float getFloat(int roff);
/**
* Set the given float value at the current {@link Buf#writerIndex()},
* Set the given float value at the current {@link Buf#writerOffset()},
* and increase the writer offset by {@link Float#BYTES}.
* The value is written using a 32-bit IEEE floating point encoding,
* with the {@link Buf#order() configured} default byte order.
@ -502,20 +500,20 @@ public interface BufAccessors {
Buf writeFloat(float value);
/**
* Set the given float value at the given write offset. The {@link Buf#writerIndex()} is not modified.
* Set the given float value at the given write offset. The {@link Buf#writerOffset()} is not modified.
* The value is written using a 32-bit IEEE floating point encoding,
* with the {@link Buf#order() configured} default byte order.
*
* @param woff The write offset, an absolute index into this buffer to write to.
* @param woff The write offset, an absolute offset into this buffer to write to.
* @param value The float value to write.
* @return This Buf.
* @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or
* greater than or equal to {@link Buf#capacity()} minus {@link Float#BYTES}.
*/
Buf writeFloat(int woff, float value);
Buf setFloat(int woff, float value);
/**
* Get the long value at the current {@link Buf#readerIndex()},
* Get the long value at the current {@link Buf#readerOffset()},
* and increases the reader offset by {@link Long#BYTES}.
* The value is read using a two's complement 64-bit encoding,
* with the {@link Buf#order() configured} default byte order.
@ -527,19 +525,19 @@ public interface BufAccessors {
/**
* Get the long value at the given reader offset.
* The {@link Buf#readerIndex()} is not modified.
* The {@link Buf#readerOffset()} is not modified.
* The value is read using a two's complement 64-bit encoding,
* with the {@link Buf#order() configured} default byte order.
*
* @param roff The read offset, an absolute index into this buffer, to read from.
* @param roff The read offset, an absolute offset into this buffer, to read from.
* @return The long value at the given offset.
* @throws IndexOutOfBoundsException if the given index is out of bounds of the buffer, that is, less than 0 or
* @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or
* greater than or equal to {@link Buf#capacity()} minus {@link Long#BYTES}.
*/
long readLong(int roff);
long getLong(int roff);
/**
* Set the given long value at the current {@link Buf#writerIndex()},
* Set the given long value at the current {@link Buf#writerOffset()},
* and increase the writer offset by {@link Long#BYTES}.
* The value is written using a two's complement 64-bit encoding,
* with the {@link Buf#order() configured} default byte order.
@ -551,20 +549,20 @@ public interface BufAccessors {
Buf writeLong(long value);
/**
* Set the given long value at the given write offset. The {@link Buf#writerIndex()} is not modified.
* Set the given long value at the given write offset. The {@link Buf#writerOffset()} is not modified.
* The value is written using a two's complement 64-bit encoding,
* with the {@link Buf#order() configured} default byte order.
*
* @param woff The write offset, an absolute index into this buffer to write to.
* @param woff The write offset, an absolute offset into this buffer to write to.
* @param value The long value to write.
* @return This Buf.
* @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or
* greater than or equal to {@link Buf#capacity()} minus {@link Long#BYTES}.
*/
Buf writeLong(int woff, long value);
Buf setLong(int woff, long value);
/**
* Get the double value at the current {@link Buf#readerIndex()},
* Get the double value at the current {@link Buf#readerOffset()},
* and increases the reader offset by {@link Double#BYTES}.
* The value is read using a 64-bit IEEE floating point encoding,
* with the {@link Buf#order() configured} default byte order.
@ -576,19 +574,19 @@ public interface BufAccessors {
/**
* Get the double value at the given reader offset.
* The {@link Buf#readerIndex()} is not modified.
* The {@link Buf#readerOffset()} is not modified.
* The value is read using a 64-bit IEEE floating point encoding,
* with the {@link Buf#order() configured} default byte order.
*
* @param roff The read offset, an absolute index into this buffer, to read from.
* @param roff The read offset, an absolute offset into this buffer, to read from.
* @return The double value at the given offset.
* @throws IndexOutOfBoundsException if the given index is out of bounds of the buffer, that is, less than 0 or
* @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or
* greater than or equal to {@link Buf#capacity()} minus {@link Double#BYTES}.
*/
double readDouble(int roff);
double getDouble(int roff);
/**
* Set the given double value at the current {@link Buf#writerIndex()},
* Set the given double value at the current {@link Buf#writerOffset()},
* and increase the writer offset by {@link Double#BYTES}.
* The value is written using a 64-bit IEEE floating point encoding,
* with the {@link Buf#order() configured} default byte order.
@ -600,17 +598,16 @@ public interface BufAccessors {
Buf writeDouble(double value);
/**
* Set the given double value at the given write offset. The {@link Buf#writerIndex()} is not modified.
* Set the given double value at the given write offset. The {@link Buf#writerOffset()} is not modified.
* The value is written using a 64-bit IEEE floating point encoding,
* with the {@link Buf#order() configured} default byte order.
*
* @param woff The write offset, an absolute index into this buffer to write to.
* @param woff The write offset, an absolute offset into this buffer to write to.
* @param value The double value to write.
* @return This Buf.
* @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or
* greater than or equal to {@link Buf#capacity()} minus {@link Double#BYTES}.
*/
Buf writeDouble(int woff, double value);
Buf setDouble(int woff, double value);
// </editor-fold>
// ### CODEGEN END primitive accessors interface
}

View File

@ -69,9 +69,9 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
if (buf.writableBytes() == 0) {
woff += buf.capacity();
} else if (!woffMidpoint) {
woff += buf.writerIndex();
woff += buf.writerOffset();
woffMidpoint = true;
} else if (buf.writerIndex() != 0) {
} else if (buf.writerOffset() != 0) {
throw new IllegalArgumentException(
"The given buffers cannot be composed because they have an unwritten gap: " +
Arrays.toString(bufs) + '.');
@ -82,9 +82,9 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
if (buf.readableBytes() == 0 && buf.writableBytes() == 0) {
roff += buf.capacity();
} else if (!roffMidpoint) {
roff += buf.readerIndex();
roff += buf.readerOffset();
roffMidpoint = true;
} else if (buf.readerIndex() != 0) {
} else if (buf.readerOffset() != 0) {
throw new IllegalArgumentException(
"The given buffers cannot be composed because they have an unread gap: " +
Arrays.toString(bufs) + '.');
@ -129,16 +129,16 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public int readerIndex() {
public int readerOffset() {
return roff;
}
@Override
public Buf readerIndex(int index) {
public Buf readerOffset(int index) {
prepRead(index, 0);
int indexLeft = index;
for (Buf buf : bufs) {
buf.readerIndex(Math.min(indexLeft, buf.capacity()));
buf.readerOffset(Math.min(indexLeft, buf.capacity()));
indexLeft = Math.max(0, indexLeft - buf.capacity());
}
roff = index;
@ -146,16 +146,16 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public int writerIndex() {
public int writerOffset() {
return woff;
}
@Override
public Buf writerIndex(int index) {
public Buf writerOffset(int index) {
checkWriteBounds(index, 0);
int indexLeft = index;
for (Buf buf : bufs) {
buf.writerIndex(Math.min(indexLeft, buf.capacity()));
buf.writerOffset(Math.min(indexLeft, buf.capacity()));
indexLeft = Math.max(0, indexLeft - buf.capacity());
}
woff = index;
@ -170,18 +170,6 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
return this;
}
@Override
public byte[] copy() {
var bytes = new byte[capacity];
int base = 0;
for (Buf buf : bufs) {
var src = buf.copy();
System.arraycopy(src, 0, bytes, base, src.length);
base += src.length;
}
return bytes;
}
@Override
public long getNativeAddress() {
return 0;
@ -222,7 +210,7 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
slices = new Buf[] { choice.slice(subOffset, 0) };
}
return new CompositeBuf(false, slices, drop).writerIndex(length);
return new CompositeBuf(false, slices, drop).writerOffset(length);
} catch (Throwable throwable) {
// We called acquire prior to the try-clause. We need to undo that if we're not creating a composite buffer:
close();
@ -295,10 +283,10 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
while (itr.hasNextLong()) {
long val = itr.nextLong();
length -= Long.BYTES;
dest.writeLong(destPos + length, val);
dest.setLong(destPos + length, val);
}
while (itr.hasNextByte()) {
dest.writeByte(destPos + --length, itr.nextByte());
dest.setByte(destPos + --length, itr.nextByte());
}
} finally {
dest.order(prevOrder);
@ -479,8 +467,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public byte readByte(int roff) {
return prepRead(roff, Byte.BYTES).readByte(subOffset);
public byte getByte(int roff) {
return prepRead(roff, Byte.BYTES).getByte(subOffset);
}
@Override
@ -489,8 +477,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public int readUnsignedByte(int roff) {
return prepRead(roff, Byte.BYTES).readUnsignedByte(subOffset);
public int getUnsignedByte(int roff) {
return prepRead(roff, Byte.BYTES).getUnsignedByte(subOffset);
}
@Override
@ -500,8 +488,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public Buf writeByte(int woff, byte value) {
prepWrite(woff, Byte.BYTES).writeByte(subOffset, value);
public Buf setByte(int woff, byte value) {
prepWrite(woff, Byte.BYTES).setByte(subOffset, value);
return this;
}
@ -512,8 +500,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public Buf writeUnsignedByte(int woff, int value) {
prepWrite(woff, Byte.BYTES).writeUnsignedByte(subOffset, value);
public Buf setUnsignedByte(int woff, int value) {
prepWrite(woff, Byte.BYTES).setUnsignedByte(subOffset, value);
return this;
}
@ -523,8 +511,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public char readChar(int roff) {
return prepRead(roff, 2).readChar(subOffset);
public char getChar(int roff) {
return prepRead(roff, 2).getChar(subOffset);
}
@Override
@ -534,8 +522,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public Buf writeChar(int woff, char value) {
prepWrite(woff, 2).writeChar(subOffset, value);
public Buf setChar(int woff, char value) {
prepWrite(woff, 2).setChar(subOffset, value);
return this;
}
@ -545,8 +533,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public short readShort(int roff) {
return prepRead(roff, Short.BYTES).readShort(subOffset);
public short getShort(int roff) {
return prepRead(roff, Short.BYTES).getShort(subOffset);
}
@Override
@ -555,8 +543,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public int readUnsignedShort(int roff) {
return prepRead(roff, Short.BYTES).readUnsignedShort(subOffset);
public int getUnsignedShort(int roff) {
return prepRead(roff, Short.BYTES).getUnsignedShort(subOffset);
}
@Override
@ -566,8 +554,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public Buf writeShort(int woff, short value) {
prepWrite(woff, Short.BYTES).writeShort(subOffset, value);
public Buf setShort(int woff, short value) {
prepWrite(woff, Short.BYTES).setShort(subOffset, value);
return this;
}
@ -578,8 +566,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public Buf writeUnsignedShort(int woff, int value) {
prepWrite(woff, Short.BYTES).writeUnsignedShort(subOffset, value);
public Buf setUnsignedShort(int woff, int value) {
prepWrite(woff, Short.BYTES).setUnsignedShort(subOffset, value);
return this;
}
@ -589,8 +577,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public int readMedium(int roff) {
return prepRead(roff, 3).readMedium(subOffset);
public int getMedium(int roff) {
return prepRead(roff, 3).getMedium(subOffset);
}
@Override
@ -599,8 +587,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public int readUnsignedMedium(int roff) {
return prepRead(roff, 3).readMedium(subOffset);
public int getUnsignedMedium(int roff) {
return prepRead(roff, 3).getMedium(subOffset);
}
@Override
@ -610,8 +598,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public Buf writeMedium(int woff, int value) {
prepWrite(woff, 3).writeMedium(subOffset, value);
public Buf setMedium(int woff, int value) {
prepWrite(woff, 3).setMedium(subOffset, value);
return this;
}
@ -622,8 +610,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public Buf writeUnsignedMedium(int woff, int value) {
prepWrite(woff, 3).writeUnsignedMedium(subOffset, value);
public Buf setUnsignedMedium(int woff, int value) {
prepWrite(woff, 3).setUnsignedMedium(subOffset, value);
return this;
}
@ -633,8 +621,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public int readInt(int roff) {
return prepRead(roff, Integer.BYTES).readInt(subOffset);
public int getInt(int roff) {
return prepRead(roff, Integer.BYTES).getInt(subOffset);
}
@Override
@ -643,8 +631,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public long readUnsignedInt(int roff) {
return prepRead(roff, Integer.BYTES).readUnsignedInt(subOffset);
public long getUnsignedInt(int roff) {
return prepRead(roff, Integer.BYTES).getUnsignedInt(subOffset);
}
@Override
@ -654,8 +642,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public Buf writeInt(int woff, int value) {
prepWrite(woff, Integer.BYTES).writeInt(subOffset, value);
public Buf setInt(int woff, int value) {
prepWrite(woff, Integer.BYTES).setInt(subOffset, value);
return this;
}
@ -666,8 +654,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public Buf writeUnsignedInt(int woff, long value) {
prepWrite(woff, Integer.BYTES).writeUnsignedInt(subOffset, value);
public Buf setUnsignedInt(int woff, long value) {
prepWrite(woff, Integer.BYTES).setUnsignedInt(subOffset, value);
return this;
}
@ -677,8 +665,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public float readFloat(int roff) {
return prepRead(roff, Float.BYTES).readFloat(subOffset);
public float getFloat(int roff) {
return prepRead(roff, Float.BYTES).getFloat(subOffset);
}
@Override
@ -688,8 +676,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public Buf writeFloat(int woff, float value) {
prepWrite(woff, Float.BYTES).writeFloat(subOffset, value);
public Buf setFloat(int woff, float value) {
prepWrite(woff, Float.BYTES).setFloat(subOffset, value);
return this;
}
@ -699,8 +687,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public long readLong(int roff) {
return prepRead(roff, Long.BYTES).readLong(subOffset);
public long getLong(int roff) {
return prepRead(roff, Long.BYTES).getLong(subOffset);
}
@Override
@ -710,8 +698,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public Buf writeLong(int woff, long value) {
prepWrite(woff, Long.BYTES).writeLong(subOffset, value);
public Buf setLong(int woff, long value) {
prepWrite(woff, Long.BYTES).setLong(subOffset, value);
return this;
}
@ -721,8 +709,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public double readDouble(int roff) {
return prepRead(roff, Double.BYTES).readDouble(subOffset);
public double getDouble(int roff) {
return prepRead(roff, Double.BYTES).getDouble(subOffset);
}
@Override
@ -732,8 +720,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public Buf writeDouble(int woff, double value) {
prepWrite(woff, Double.BYTES).writeDouble(subOffset, value);
public Buf setDouble(int woff, double value) {
prepWrite(woff, Double.BYTES).setDouble(subOffset, value);
return this;
}
// </editor-fold>
@ -799,16 +787,16 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
buf.writeUnsignedByte(value);
}
long readPassThrough(int roff) {
long getPassThrough(int roff) {
var buf = chooseBuffer(roff, 1);
assert buf != tornBufAccessors: "Recursive call to torn buffer.";
return buf.readUnsignedByte(subOffset);
return buf.getUnsignedByte(subOffset);
}
void writePassThrough(int woff, int value) {
void setPassThrough(int woff, int value) {
var buf = chooseBuffer(woff, 1);
assert buf != tornBufAccessors: "Recursive call to torn buffer.";
buf.writeUnsignedByte(subOffset, value);
buf.setUnsignedByte(subOffset, value);
}
private BufAccessors prepRead(int size) {
@ -892,7 +880,7 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public byte readByte(int roff) {
public byte getByte(int roff) {
throw new AssertionError("Method should not be used.");
}
@ -902,7 +890,7 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public int readUnsignedByte(int roff) {
public int getUnsignedByte(int roff) {
throw new AssertionError("Method should not be used.");
}
@ -912,7 +900,7 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public Buf writeByte(int woff, byte value) {
public Buf setByte(int woff, byte value) {
throw new AssertionError("Method should not be used.");
}
@ -922,7 +910,7 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public Buf writeUnsignedByte(int woff, int value) {
public Buf setUnsignedByte(int woff, int value) {
throw new AssertionError("Method should not be used.");
}
@ -936,7 +924,7 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public char readChar(int roff) {
public char getChar(int roff) {
if (bigEndian()) {
return (char) (read(roff) << 8 | read(roff + 1));
} else {
@ -957,7 +945,7 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public Buf writeChar(int woff, char value) {
public Buf setChar(int woff, char value) {
if (bigEndian()) {
write(woff, value >>> 8);
write(woff + 1, value & 0xFF);
@ -978,7 +966,7 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public short readShort(int roff) {
public short getShort(int roff) {
if (bigEndian()) {
return (short) (read(roff) << 8 | read(roff + 1));
} else {
@ -996,7 +984,7 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public int readUnsignedShort(int roff) {
public int getUnsignedShort(int roff) {
if (bigEndian()) {
return (int) (read(roff) << 8 | read(roff + 1)) & 0xFFFF;
} else {
@ -1017,7 +1005,7 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public Buf writeShort(int woff, short value) {
public Buf setShort(int woff, short value) {
if (bigEndian()) {
write(woff, value >>> 8);
write(woff + 1, value & 0xFF);
@ -1041,7 +1029,7 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public Buf writeUnsignedShort(int woff, int value) {
public Buf setUnsignedShort(int woff, int value) {
if (bigEndian()) {
write(woff, value >>> 8);
write(woff + 1, value & 0xFF);
@ -1062,7 +1050,7 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public int readMedium(int roff) {
public int getMedium(int roff) {
if (bigEndian()) {
return (int) (read(roff) << 16 | read(roff + 1) << 8 | read(roff + 2));
} else {
@ -1080,7 +1068,7 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public int readUnsignedMedium(int roff) {
public int getUnsignedMedium(int roff) {
if (bigEndian()) {
return (int) (read(roff) << 16 | read(roff + 1) << 8 | read(roff + 2)) & 0xFFFFFF;
} else {
@ -1103,7 +1091,7 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public Buf writeMedium(int woff, int value) {
public Buf setMedium(int woff, int value) {
if (bigEndian()) {
write(woff, value >>> 16);
write(woff + 1, value >>> 8 & 0xFF);
@ -1131,7 +1119,7 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public Buf writeUnsignedMedium(int woff, int value) {
public Buf setUnsignedMedium(int woff, int value) {
if (bigEndian()) {
write(woff, value >>> 16);
write(woff + 1, value >>> 8 & 0xFF);
@ -1154,7 +1142,7 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public int readInt(int roff) {
public int getInt(int roff) {
if (bigEndian()) {
return (int) (read(roff) << 24 | read(roff + 1) << 16 | read(roff + 2) << 8 | read(roff + 3));
} else {
@ -1172,7 +1160,7 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public long readUnsignedInt(int roff) {
public long getUnsignedInt(int roff) {
if (bigEndian()) {
return (read(roff) << 24 | read(roff + 1) << 16 | read(roff + 2) << 8 | read(roff + 3)) & 0xFFFFFFFFL;
} else {
@ -1197,7 +1185,7 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public Buf writeInt(int woff, int value) {
public Buf setInt(int woff, int value) {
if (bigEndian()) {
write(woff, value >>> 24);
write(woff + 1, value >>> 16 & 0xFF);
@ -1229,7 +1217,7 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public Buf writeUnsignedInt(int woff, long value) {
public Buf setUnsignedInt(int woff, long value) {
if (bigEndian()) {
write(woff, (int) (value >>> 24));
write(woff + 1, (int) (value >>> 16 & 0xFF));
@ -1250,8 +1238,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public float readFloat(int roff) {
return Float.intBitsToFloat(readInt(roff));
public float getFloat(int roff) {
return Float.intBitsToFloat(getInt(roff));
}
@Override
@ -1260,8 +1248,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public Buf writeFloat(int woff, float value) {
return writeUnsignedInt(woff, Float.floatToRawIntBits(value));
public Buf setFloat(int woff, float value) {
return setUnsignedInt(woff, Float.floatToRawIntBits(value));
}
@Override
@ -1276,7 +1264,7 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public long readLong(int roff) {
public long getLong(int roff) {
if (bigEndian()) {
return read(roff) << 56 | read(roff + 1) << 48 | read(roff + 2) << 40 | read(roff + 3) << 32 |
read(roff + 4) << 24 | read(roff + 5) << 16 | read(roff + 6) << 8 | read(roff + 7);
@ -1311,7 +1299,7 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public Buf writeLong(int woff, long value) {
public Buf setLong(int woff, long value) {
if (bigEndian()) {
write(woff, (int) (value >>> 56));
write(woff + 1, (int) (value >>> 48 & 0xFF));
@ -1340,8 +1328,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public double readDouble(int roff) {
return Double.longBitsToDouble(readLong(roff));
public double getDouble(int roff) {
return Double.longBitsToDouble(getLong(roff));
}
@Override
@ -1350,8 +1338,8 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
@Override
public Buf writeDouble(int woff, double value) {
return writeLong(woff, Double.doubleToRawLongBits(value));
public Buf setDouble(int woff, double value) {
return setLong(woff, Double.doubleToRawLongBits(value));
}
private boolean bigEndian() {
@ -1367,11 +1355,11 @@ final class CompositeBuf extends RcSupport<Buf, CompositeBuf> implements Buf {
}
private long read(int roff) {
return buf.readPassThrough(roff);
return buf.getPassThrough(roff);
}
private void write(int woff, int value) {
buf.writePassThrough(woff, value);
buf.setPassThrough(woff, value);
}
}
// </editor-fold>

View File

@ -87,24 +87,24 @@ class MemSegBuf extends RcSupport<Buf, MemSegBuf> implements Buf {
}
@Override
public int readerIndex() {
public int readerOffset() {
return roff;
}
@Override
public MemSegBuf readerIndex(int index) {
public MemSegBuf readerOffset(int index) {
checkRead(index, 0);
roff = index;
return this;
}
@Override
public int writerIndex() {
public int writerOffset() {
return woff;
}
@Override
public MemSegBuf writerIndex(int index) {
public MemSegBuf writerOffset(int index) {
checkWrite(index, 0);
woff = index;
return this;
@ -116,11 +116,6 @@ class MemSegBuf extends RcSupport<Buf, MemSegBuf> implements Buf {
return this;
}
@Override
public byte[] copy() {
return seg.toByteArray();
}
@Override
public long getNativeAddress() {
try {
@ -136,7 +131,7 @@ class MemSegBuf extends RcSupport<Buf, MemSegBuf> implements Buf {
acquire();
Drop<MemSegBuf> drop = b -> close();
var sendable = false; // Sending implies ownership change, which we can't do for slices.
return new MemSegBuf(slice, drop, sendable).writerIndex(length).order(order());
return new MemSegBuf(slice, drop, sendable).writerOffset(length).order(order());
}
@Override
@ -169,10 +164,10 @@ class MemSegBuf extends RcSupport<Buf, MemSegBuf> implements Buf {
while (itr.hasNextLong()) {
long val = itr.nextLong();
length -= Long.BYTES;
dest.writeLong(destPos + length, val);
dest.setLong(destPos + length, val);
}
while (itr.hasNextByte()) {
dest.writeByte(destPos + --length, itr.nextByte());
dest.setByte(destPos + --length, itr.nextByte());
}
} finally {
dest.order(prevOrder);
@ -301,21 +296,19 @@ class MemSegBuf extends RcSupport<Buf, MemSegBuf> implements Buf {
};
}
// ### CODEGEN START primitive accessors implementation
// <editor-fold defaultstate="collapsed" desc="Generated primitive accessors implementation.">
// <editor-fold defaultstate="collapsed" desc="Primitive accessors implementation.">
@Override
public byte readByte() {
checkRead(roff, Byte.BYTES);
byte value = (isBigEndian? getByteAtOffset_BE(seg, roff) : getByteAtOffset_LE(seg, roff));
byte value = isBigEndian? getByteAtOffset_BE(seg, roff) : getByteAtOffset_LE(seg, roff);
roff += Byte.BYTES;
return value;
}
@Override
public byte readByte(int roff) {
public byte getByte(int roff) {
checkRead(roff, Byte.BYTES);
return (isBigEndian? getByteAtOffset_BE(seg, roff) : getByteAtOffset_LE(seg, roff));
return isBigEndian? getByteAtOffset_BE(seg, roff) : getByteAtOffset_LE(seg, roff);
}
@Override
@ -327,7 +320,7 @@ class MemSegBuf extends RcSupport<Buf, MemSegBuf> implements Buf {
}
@Override
public int readUnsignedByte(int roff) {
public int getUnsignedByte(int roff) {
checkRead(roff, Byte.BYTES);
return (isBigEndian? getByteAtOffset_BE(seg, roff) : getByteAtOffset_LE(seg, roff)) & 0xFF;
}
@ -344,7 +337,7 @@ class MemSegBuf extends RcSupport<Buf, MemSegBuf> implements Buf {
}
@Override
public Buf writeByte(int woff, byte value) {
public Buf setByte(int woff, byte value) {
if (isBigEndian) {
setByteAtOffset_BE(seg, woff, value);
} else {
@ -365,7 +358,7 @@ class MemSegBuf extends RcSupport<Buf, MemSegBuf> implements Buf {
}
@Override
public Buf writeUnsignedByte(int woff, int value) {
public Buf setUnsignedByte(int woff, int value) {
if (isBigEndian) {
setByteAtOffset_BE(seg, woff, (byte) (value & 0xFF));
} else {
@ -377,15 +370,15 @@ class MemSegBuf extends RcSupport<Buf, MemSegBuf> implements Buf {
@Override
public char readChar() {
checkRead(roff, 2);
char value = (isBigEndian? getCharAtOffset_BE(seg, roff) : getCharAtOffset_LE(seg, roff));
char value = isBigEndian? getCharAtOffset_BE(seg, roff) : getCharAtOffset_LE(seg, roff);
roff += 2;
return value;
}
@Override
public char readChar(int roff) {
public char getChar(int roff) {
checkRead(roff, 2);
return (isBigEndian? getCharAtOffset_BE(seg, roff) : getCharAtOffset_LE(seg, roff));
return isBigEndian? getCharAtOffset_BE(seg, roff) : getCharAtOffset_LE(seg, roff);
}
@Override
@ -400,7 +393,7 @@ class MemSegBuf extends RcSupport<Buf, MemSegBuf> implements Buf {
}
@Override
public Buf writeChar(int woff, char value) {
public Buf setChar(int woff, char value) {
if (isBigEndian) {
setCharAtOffset_BE(seg, woff, value);
} else {
@ -412,15 +405,15 @@ class MemSegBuf extends RcSupport<Buf, MemSegBuf> implements Buf {
@Override
public short readShort() {
checkRead(roff, Short.BYTES);
short value = (isBigEndian? getShortAtOffset_BE(seg, roff) : getShortAtOffset_LE(seg, roff));
short value = isBigEndian? getShortAtOffset_BE(seg, roff) : getShortAtOffset_LE(seg, roff);
roff += Short.BYTES;
return value;
}
@Override
public short readShort(int roff) {
public short getShort(int roff) {
checkRead(roff, Short.BYTES);
return (isBigEndian? getShortAtOffset_BE(seg, roff) : getShortAtOffset_LE(seg, roff));
return isBigEndian? getShortAtOffset_BE(seg, roff) : getShortAtOffset_LE(seg, roff);
}
@Override
@ -432,7 +425,7 @@ class MemSegBuf extends RcSupport<Buf, MemSegBuf> implements Buf {
}
@Override
public int readUnsignedShort(int roff) {
public int getUnsignedShort(int roff) {
checkRead(roff, Short.BYTES);
return (isBigEndian? getShortAtOffset_BE(seg, roff) : getShortAtOffset_LE(seg, roff)) & 0xFFFF;
}
@ -449,7 +442,7 @@ class MemSegBuf extends RcSupport<Buf, MemSegBuf> implements Buf {
}
@Override
public Buf writeShort(int woff, short value) {
public Buf setShort(int woff, short value) {
if (isBigEndian) {
setShortAtOffset_BE(seg, woff, value);
} else {
@ -470,7 +463,7 @@ class MemSegBuf extends RcSupport<Buf, MemSegBuf> implements Buf {
}
@Override
public Buf writeUnsignedShort(int woff, int value) {
public Buf setUnsignedShort(int woff, int value) {
if (isBigEndian) {
setShortAtOffset_BE(seg, woff, (short) (value & 0xFFFF));
} else {
@ -483,10 +476,10 @@ class MemSegBuf extends RcSupport<Buf, MemSegBuf> implements Buf {
public int readMedium() {
checkRead(roff, 3);
int value = isBigEndian?
getByteAtOffset_BE(seg, roff) << 16 |
getByteAtOffset_BE(seg, roff) << 16 |
(getByteAtOffset_BE(seg, roff + 1) & 0xFF) << 8 |
getByteAtOffset_BE(seg, roff + 2) & 0xFF :
getByteAtOffset_BE(seg, roff) & 0xFF |
getByteAtOffset_BE(seg, roff + 2) & 0xFF :
getByteAtOffset_BE(seg, roff) & 0xFF |
(getByteAtOffset_BE(seg, roff + 1) & 0xFF) << 8 |
getByteAtOffset_BE(seg, roff + 2) << 16;
roff += 3;
@ -494,13 +487,13 @@ getByteAtOffset_BE(seg, roff) & 0xFF |
}
@Override
public int readMedium(int roff) {
public int getMedium(int roff) {
checkRead(roff, 3);
return isBigEndian?
getByteAtOffset_BE(seg, roff) << 16 |
getByteAtOffset_BE(seg, roff) << 16 |
(getByteAtOffset_BE(seg, roff + 1) & 0xFF) << 8 |
getByteAtOffset_BE(seg, roff + 2) & 0xFF :
getByteAtOffset_BE(seg, roff) & 0xFF |
getByteAtOffset_BE(seg, roff + 2) & 0xFF :
getByteAtOffset_BE(seg, roff) & 0xFF |
(getByteAtOffset_BE(seg, roff + 1) & 0xFF) << 8 |
getByteAtOffset_BE(seg, roff + 2) << 16;
}
@ -509,10 +502,10 @@ getByteAtOffset_BE(seg, roff) & 0xFF |
public int readUnsignedMedium() {
checkRead(roff, 3);
int value = isBigEndian?
(getByteAtOffset_BE(seg, roff) << 16 |
(getByteAtOffset_BE(seg, roff) << 16 |
(getByteAtOffset_BE(seg, roff + 1) & 0xFF) << 8 |
getByteAtOffset_BE(seg, roff + 2) & 0xFF) & 0xFFFFFF :
(getByteAtOffset_BE(seg, roff) & 0xFF |
getByteAtOffset_BE(seg, roff + 2) & 0xFF) & 0xFFFFFF :
(getByteAtOffset_BE(seg, roff) & 0xFF |
(getByteAtOffset_BE(seg, roff + 1) & 0xFF) << 8 |
getByteAtOffset_BE(seg, roff + 2) << 16) & 0xFFFFFF;
roff += 3;
@ -520,13 +513,13 @@ getByteAtOffset_BE(seg, roff) & 0xFF |
}
@Override
public int readUnsignedMedium(int roff) {
public int getUnsignedMedium(int roff) {
checkRead(roff, 3);
return isBigEndian?
(getByteAtOffset_BE(seg, roff) << 16 |
(getByteAtOffset_BE(seg, roff) << 16 |
(getByteAtOffset_BE(seg, roff + 1) & 0xFF) << 8 |
getByteAtOffset_BE(seg, roff + 2) & 0xFF) & 0xFFFFFF :
(getByteAtOffset_BE(seg, roff) & 0xFF |
getByteAtOffset_BE(seg, roff + 2) & 0xFF) & 0xFFFFFF :
(getByteAtOffset_BE(seg, roff) & 0xFF |
(getByteAtOffset_BE(seg, roff + 1) & 0xFF) << 8 |
getByteAtOffset_BE(seg, roff + 2) << 16) & 0xFFFFFF;
}
@ -548,7 +541,7 @@ getByteAtOffset_BE(seg, roff) & 0xFF |
}
@Override
public Buf writeMedium(int woff, int value) {
public Buf setMedium(int woff, int value) {
checkWrite(woff, 3);
if (isBigEndian) {
setByteAtOffset_BE(seg, woff, (byte) (value >> 16));
@ -579,7 +572,7 @@ getByteAtOffset_BE(seg, roff) & 0xFF |
}
@Override
public Buf writeUnsignedMedium(int woff, int value) {
public Buf setUnsignedMedium(int woff, int value) {
checkWrite(woff, 3);
if (isBigEndian) {
setByteAtOffset_BE(seg, woff, (byte) (value >> 16));
@ -596,15 +589,15 @@ getByteAtOffset_BE(seg, roff) & 0xFF |
@Override
public int readInt() {
checkRead(roff, Integer.BYTES);
int value = (isBigEndian? getIntAtOffset_BE(seg, roff) : getIntAtOffset_LE(seg, roff));
int value = isBigEndian? getIntAtOffset_BE(seg, roff) : getIntAtOffset_LE(seg, roff);
roff += Integer.BYTES;
return value;
}
@Override
public int readInt(int roff) {
public int getInt(int roff) {
checkRead(roff, Integer.BYTES);
return (isBigEndian? getIntAtOffset_BE(seg, roff) : getIntAtOffset_LE(seg, roff));
return isBigEndian? getIntAtOffset_BE(seg, roff) : getIntAtOffset_LE(seg, roff);
}
@Override
@ -616,7 +609,7 @@ getByteAtOffset_BE(seg, roff) & 0xFF |
}
@Override
public long readUnsignedInt(int roff) {
public long getUnsignedInt(int roff) {
checkRead(roff, Integer.BYTES);
return (isBigEndian? getIntAtOffset_BE(seg, roff) : getIntAtOffset_LE(seg, roff)) & 0xFFFFFFFFL;
}
@ -633,7 +626,7 @@ getByteAtOffset_BE(seg, roff) & 0xFF |
}
@Override
public Buf writeInt(int woff, int value) {
public Buf setInt(int woff, int value) {
if (isBigEndian) {
setIntAtOffset_BE(seg, woff, value);
} else {
@ -654,7 +647,7 @@ getByteAtOffset_BE(seg, roff) & 0xFF |
}
@Override
public Buf writeUnsignedInt(int woff, long value) {
public Buf setUnsignedInt(int woff, long value) {
if (isBigEndian) {
setIntAtOffset_BE(seg, woff, (int) (value & 0xFFFFFFFFL));
} else {
@ -666,15 +659,15 @@ getByteAtOffset_BE(seg, roff) & 0xFF |
@Override
public float readFloat() {
checkRead(roff, Float.BYTES);
float value = (isBigEndian? getFloatAtOffset_BE(seg, roff) : getFloatAtOffset_LE(seg, roff));
float value = isBigEndian? getFloatAtOffset_BE(seg, roff) : getFloatAtOffset_LE(seg, roff);
roff += Float.BYTES;
return value;
}
@Override
public float readFloat(int roff) {
public float getFloat(int roff) {
checkRead(roff, Float.BYTES);
return (isBigEndian? getFloatAtOffset_BE(seg, roff) : getFloatAtOffset_LE(seg, roff));
return isBigEndian? getFloatAtOffset_BE(seg, roff) : getFloatAtOffset_LE(seg, roff);
}
@Override
@ -689,7 +682,7 @@ getByteAtOffset_BE(seg, roff) & 0xFF |
}
@Override
public Buf writeFloat(int woff, float value) {
public Buf setFloat(int woff, float value) {
if (isBigEndian) {
setFloatAtOffset_BE(seg, woff, value);
} else {
@ -701,15 +694,15 @@ getByteAtOffset_BE(seg, roff) & 0xFF |
@Override
public long readLong() {
checkRead(roff, Long.BYTES);
long value = (isBigEndian? getLongAtOffset_BE(seg, roff) : getLongAtOffset_LE(seg, roff));
long value = isBigEndian? getLongAtOffset_BE(seg, roff) : getLongAtOffset_LE(seg, roff);
roff += Long.BYTES;
return value;
}
@Override
public long readLong(int roff) {
public long getLong(int roff) {
checkRead(roff, Long.BYTES);
return (isBigEndian? getLongAtOffset_BE(seg, roff) : getLongAtOffset_LE(seg, roff));
return isBigEndian? getLongAtOffset_BE(seg, roff) : getLongAtOffset_LE(seg, roff);
}
@Override
@ -724,7 +717,7 @@ getByteAtOffset_BE(seg, roff) & 0xFF |
}
@Override
public Buf writeLong(int woff, long value) {
public Buf setLong(int woff, long value) {
if (isBigEndian) {
setLongAtOffset_BE(seg, woff, value);
} else {
@ -736,15 +729,15 @@ getByteAtOffset_BE(seg, roff) & 0xFF |
@Override
public double readDouble() {
checkRead(roff, Double.BYTES);
double value = (isBigEndian? getDoubleAtOffset_BE(seg, roff) : getDoubleAtOffset_LE(seg, roff));
double value = isBigEndian? getDoubleAtOffset_BE(seg, roff) : getDoubleAtOffset_LE(seg, roff);
roff += Double.BYTES;
return value;
}
@Override
public double readDouble(int roff) {
public double getDouble(int roff) {
checkRead(roff, Double.BYTES);
return (isBigEndian? getDoubleAtOffset_BE(seg, roff) : getDoubleAtOffset_LE(seg, roff));
return isBigEndian? getDoubleAtOffset_BE(seg, roff) : getDoubleAtOffset_LE(seg, roff);
}
@Override
@ -759,7 +752,7 @@ getByteAtOffset_BE(seg, roff) & 0xFF |
}
@Override
public Buf writeDouble(int woff, double value) {
public Buf setDouble(int woff, double value) {
if (isBigEndian) {
setDoubleAtOffset_BE(seg, woff, value);
} else {
@ -768,7 +761,6 @@ getByteAtOffset_BE(seg, roff) & 0xFF |
return this;
}
// </editor-fold>
// ### CODEGEN END primitive accessors implementation
@Override
protected Owned<MemSegBuf> prepareSend() {

File diff suppressed because it is too large Load Diff