Interface MutableBytes
- All Superinterfaces:
Bytes,Comparable<Bytes>
- All Known Subinterfaces:
MutableBytes32,MutableBytes48
- All Known Implementing Classes:
DelegatingMutableBytes,MutableByteBufferWrappingBytes
Bytes value.-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiondefault voidclear()Set all bytes in this value to 0.static MutableBytescreate(int size) Create a new mutable byte value.default MutableBytesDecrements the value of the bytes by 1, treating the value as big endian.default voidfill(byte b) Fill all the bytes of this value with the specified byte.default MutableBytesIncrements the value of the bytes by 1, treating the value as big endian.mutableSlice(int i, int length) Create a mutable slice of the bytes of this value.static MutableBytesof(byte... bytes) Create a value that contains the specified bytes in their specified order.static MutableBytesof(int... bytes) Create a value that contains the specified bytes in their specified order.voidset(int i, byte b) Set a byte in this value.default voidSet a byte in this value.default voidsetInt(int i, int value) Set the 4 bytes starting at the specified index to the specified integer value.default voidsetLong(int i, long value) Set the 8 bytes starting at the specified index to the specified long value.static MutableByteswrap(byte[] value) Wrap a byte array in aMutableBytesvalue.static MutableByteswrap(byte[] value, int offset, int length) Wrap a slice of a byte array as aMutableBytesvalue.static MutableByteswrapBuffer(io.vertx.core.buffer.Buffer buffer) Wrap a full Vert.xBufferas aMutableBytesvalue.static MutableByteswrapBuffer(io.vertx.core.buffer.Buffer buffer, int offset, int size) Wrap a slice of a Vert.xBufferas aMutableBytesvalue.static MutableByteswrapByteBuf(io.netty.buffer.ByteBuf byteBuf) Wrap a full NettyByteBufas aMutableBytesvalue.static MutableByteswrapByteBuf(io.netty.buffer.ByteBuf byteBuf, int offset, int size) Wrap a slice of a NettyByteBufas aMutableBytesvalue.static MutableByteswrapByteBuffer(ByteBuffer byteBuffer) Wrap a full Java NIOByteBufferas aMutableBytesvalue.static MutableByteswrapByteBuffer(ByteBuffer byteBuffer, int offset, int size) Wrap a slice of a Java NIOByteBufferas aMutableBytesvalue.Methods inherited from interface org.apache.tuweni.bytes.Bytes
and, and, appendHexTo, appendTo, appendTo, bitLength, commonPrefix, commonPrefixLength, compareTo, copy, copyTo, copyTo, get, getInt, getInt, getLong, getLong, hasLeadingZero, hasLeadingZeroByte, isEmpty, isZero, mutableCopy, not, not, numberOfLeadingZeroBytes, numberOfLeadingZeros, numberOfTrailingZeroBytes, or, or, reverse, shiftLeft, shiftLeft, shiftRight, shiftRight, size, slice, slice, toArray, toArray, toArrayUnsafe, toBase64String, toBigInteger, toBigInteger, toEllipsisHexString, toFastHex, toHexString, toInt, toInt, toLong, toLong, toQuantityHexString, toShortHexString, toString, toUnprefixedHexString, toUnsignedBigInteger, toUnsignedBigInteger, trimLeadingZeros, trimTrailingZeros, update, xor, xor
-
Field Details
-
EMPTY
The empty value (with 0 bytes).
-
-
Method Details
-
create
Create a new mutable byte value.- Parameters:
size- The size of the returned value.- Returns:
- A
MutableBytesvalue.
-
wrap
Wrap a byte array in aMutableBytesvalue.- Parameters:
value- The value to wrap.- Returns:
- A
MutableBytesvalue wrappingvalue.
-
wrap
Wrap a slice of a byte array as aMutableBytesvalue.Note that value is not copied and thus any future update to
valuewithin the slice will be reflected in the returned value.- Parameters:
value- The value to wrap.offset- The index (inclusive) invalueof the first byte exposed by the returned value. In other words, you will havewrap(value, o, l).get(0) == value[o].length- The length of the resulting value.- Returns:
- A
Bytesvalue that expose the bytes ofvaluefromoffset(inclusive) tooffset + length(exclusive). - Throws:
IndexOutOfBoundsException- ifoffset < 0 || (value.length > 0 && offset >= value.length).IllegalArgumentException- iflength < 0 || offset + length > value.length.
-
wrapBuffer
Wrap a full Vert.xBufferas aMutableBytesvalue.Note that any change to the content of the buffer may be reflected in the returned value.
- Parameters:
buffer- The buffer to wrap.- Returns:
- A
MutableBytesvalue.
-
wrapBuffer
Wrap a slice of a Vert.xBufferas aMutableBytesvalue.Note that any change to the content of the buffer may be reflected in the returned value, and any change to the returned value will be reflected in the buffer.
- Parameters:
buffer- The buffer to wrap.offset- The offset inbufferfrom which to expose the bytes in the returned value. That is,wrapBuffer(buffer, i, 1).get(0) == buffer.getByte(i).size- The size of the returned value.- Returns:
- A
MutableBytesvalue. - Throws:
IndexOutOfBoundsException- ifoffset < 0 || (buffer.length() > 0 && offset >= buffer.length()).IllegalArgumentException- iflength < 0 || offset + length > buffer.length().
-
wrapByteBuf
Wrap a full NettyByteBufas aMutableBytesvalue.Note that any change to the content of the buffer may be reflected in the returned value.
- Parameters:
byteBuf- TheByteBufto wrap.- Returns:
- A
MutableBytesvalue.
-
wrapByteBuf
Wrap a slice of a NettyByteBufas aMutableBytesvalue.Note that any change to the content of the buffer may be reflected in the returned value, and any change to the returned value will be reflected in the buffer.
- Parameters:
byteBuf- TheByteBufto wrap.offset- The offset inbyteBuffrom which to expose the bytes in the returned value. That is,wrapByteBuf(byteBuf, i, 1).get(0) == byteBuf.getByte(i).size- The size of the returned value.- Returns:
- A
MutableBytesvalue. - Throws:
IndexOutOfBoundsException- ifoffset < 0 || (byteBuf.capacity() > 0 && offset >= byteBuf.capacity()).IllegalArgumentException- iflength < 0 || offset + length > byteBuf.capacity().
-
wrapByteBuffer
Wrap a full Java NIOByteBufferas aMutableBytesvalue.Note that any change to the content of the buffer may be reflected in the returned value.
- Parameters:
byteBuffer- TheByteBufferto wrap.- Returns:
- A
MutableBytesvalue.
-
wrapByteBuffer
Wrap a slice of a Java NIOByteBufferas aMutableBytesvalue.Note that any change to the content of the buffer may be reflected in the returned value, and any change to the returned value will be reflected in the buffer.
- Parameters:
byteBuffer- TheByteBufferto wrap.offset- The offset inbyteBufferfrom which to expose the bytes in the returned value. That is,wrapByteBuffer(byteBuffer, i, 1).get(0) == byteBuffer.getByte(i).size- The size of the returned value.- Returns:
- A
MutableBytesvalue. - Throws:
IndexOutOfBoundsException- ifoffset < 0 || (byteBuffer.limit() > 0 && offset >= byteBuffer.limit()).IllegalArgumentException- iflength < 0 || offset + length > byteBuffer.limit().
-
of
Create a value that contains the specified bytes in their specified order.- Parameters:
bytes- The bytes that must compose the returned value.- Returns:
- A value containing the specified bytes.
-
of
Create a value that contains the specified bytes in their specified order.- Parameters:
bytes- The bytes.- Returns:
- A value containing bytes are the one from
bytes. - Throws:
IllegalArgumentException- if any of the specified would be truncated when storing as a byte.
-
set
void set(int i, byte b) Set a byte in this value.- Parameters:
i- The index of the byte to set.b- The value to set that byte to.- Throws:
IndexOutOfBoundsException- ifi < 0or {i >= size()}.
-
set
Set a byte in this value.- Parameters:
offset- The offset of the bytes to set.bytes- The value to set bytes to.- Throws:
IndexOutOfBoundsException- ifi < 0or {i >= size()}.
-
setInt
default void setInt(int i, int value) Set the 4 bytes starting at the specified index to the specified integer value.- Parameters:
i- The index, which must less than or equal tosize() - 4.value- The integer value.- Throws:
IndexOutOfBoundsException- ifi < 0ori > size() - 4.
-
setLong
default void setLong(int i, long value) Set the 8 bytes starting at the specified index to the specified long value.- Parameters:
i- The index, which must less than or equal tosize() - 8.value- The long value.- Throws:
IndexOutOfBoundsException- ifi < 0ori > size() - 8.
-
increment
Increments the value of the bytes by 1, treating the value as big endian.If incrementing overflows the value then all bits flip, i.e. incrementing 0xFFFF will return 0x0000.
- Returns:
- this value
-
decrement
Decrements the value of the bytes by 1, treating the value as big endian.If decrementing underflows the value then all bits flip, i.e. decrementing 0x0000 will return 0xFFFF.
- Returns:
- this value
-
mutableSlice
Create a mutable slice of the bytes of this value.Note: the resulting slice is only a view over the original value. Holding a reference to the returned slice may hold more memory than the slide represents. Use
Bytes.copy()on the returned slice to avoid this.- Parameters:
i- The start index for the slice.length- The length of the resulting value.- Returns:
- A new mutable view over the bytes of this value from index
i(included) to indexi + length(excluded). - Throws:
IllegalArgumentException- iflength < 0.IndexOutOfBoundsException- ifi < 0or {i >= size()} or {i + length > size()} .
-
fill
default void fill(byte b) Fill all the bytes of this value with the specified byte.- Parameters:
b- The byte to use to fill the value.
-
clear
default void clear()Set all bytes in this value to 0.
-