Class NettyMutableDataBuf
java.lang.Object
eu.cloudnetservice.driver.network.netty.buffer.NettyImmutableDataBuf
eu.cloudnetservice.driver.network.netty.buffer.NettyMutableDataBuf
- All Implemented Interfaces:
DataBuf,DataBuf.Mutable,AutoCloseable
Represents the default implementation of a mutable data buf, wrapping a netty byte buffer.
- Since:
- 4.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface eu.cloudnetservice.driver.network.buffer.DataBuf
DataBuf.Mutable -
Field Summary
Fields inherited from class eu.cloudnetservice.driver.network.netty.buffer.NettyImmutableDataBuf
buffer, readOffset, releasable, writeOffset -
Constructor Summary
ConstructorsConstructorDescriptionNettyMutableDataBuf(@NonNull io.netty5.buffer.Buffer buffer) Constructs a new mutable data buf instance. -
Method Summary
Modifier and TypeMethodDescriptionConverts this buffer into an immutable version of it.writeBoolean(boolean b) Writes the given boolean at the current writer index, increasing the index by one.writeByte(byte b) Writes the given byte at the current writer index, increasing the index by one.writeByteArray(byte[] b) Writes the given byte array into the buffer, prefixed by an integer containing the amount of bytes following in the array.writeByteArray(byte[] b, int amount) Writes the given byte array into the buffer, prefixed by an integer containing the amount of bytes following in the array.writeChar(char c) Writes the given UTF-16 char at the current writer index, increasing the index by two.writeDataBuf(@NonNull DataBuf buf) Writes all data of the given data buffer into this data buffer starting at the current reader index of the given buffer.writeDouble(double d) Writes the given double at the current writer index, increasing the index by eight.writeFloat(float f) Writes the given float at the current writer index, increasing the index by four.writeInt(int integer) Writes the given integer at the current writer index, increasing the index by four.writeLong(long l) Writes the given long at the current writer index, increasing the index by eight.writeNullable(T object, @NonNull BiConsumer<DataBuf.Mutable, T> handlerWhenNonNull) Writes the given object null-safe into this buffer.writeObject(@Nullable Object obj) Writes the given object into this buffer.writeShort(short s) Writes the given short at the current writer index, increasing the index by two.writeString(@NonNull String string) Writes the string into the buffer.writeUniqueId(@NonNull UUID uuid) Writes the unique id into the buffer by first writing the most significant bits of the id followed by the last significant bits of the id.Methods inherited from class eu.cloudnetservice.driver.network.netty.buffer.NettyImmutableDataBuf
accessible, asMutable, buffer, close, disableReleasing, enableReleasing, hotRead, readableBytes, readBoolean, readByte, readByteArray, readChar, readDataBuf, readDouble, readFloat, readInt, readLong, readNullable, readNullable, readObject, readObject, readShort, readString, readUniqueId, redoTransaction, release, startTransaction, toByteArrayMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface eu.cloudnetservice.driver.network.buffer.DataBuf
accessible, asMutable, close, disableReleasing, enableReleasing, readableBytes, readBoolean, readByte, readByteArray, readChar, readDataBuf, readDouble, readFloat, readInt, readLong, readNullable, readNullable, readObject, readObject, readShort, readString, readUniqueId, redoTransaction, release, startTransaction, toByteArray
-
Constructor Details
-
NettyMutableDataBuf
Constructs a new mutable data buf instance.- Parameters:
buffer- the netty buffer to wrap.- Throws:
NullPointerException- if the given buffer is null.
-
-
Method Details
-
writeBoolean
Writes the given boolean at the current writer index, increasing the index by one.- Specified by:
writeBooleanin interfaceDataBuf.Mutable- Parameters:
b- the boolean to write.- Returns:
- the same buffer used to call the method, for chaining.
-
writeInt
Writes the given integer at the current writer index, increasing the index by four.- Specified by:
writeIntin interfaceDataBuf.Mutable- Parameters:
integer- the integer to write into the buffer.- Returns:
- the same buffer used to call the method, for chaining.
-
writeByte
Writes the given byte at the current writer index, increasing the index by one.- Specified by:
writeBytein interfaceDataBuf.Mutable- Parameters:
b- the byte to write into the buffer.- Returns:
- the same buffer used to call the method, for chaining.
-
writeShort
Writes the given short at the current writer index, increasing the index by two.- Specified by:
writeShortin interfaceDataBuf.Mutable- Parameters:
s- the short to write into the buffer.- Returns:
- the same buffer used to call the method, for chaining.
-
writeLong
Writes the given long at the current writer index, increasing the index by eight.- Specified by:
writeLongin interfaceDataBuf.Mutable- Parameters:
l- the long to write into the buffer.- Returns:
- the same buffer used to call the method, for chaining.
-
writeFloat
Writes the given float at the current writer index, increasing the index by four.- Specified by:
writeFloatin interfaceDataBuf.Mutable- Parameters:
f- the float to write into the buffer.- Returns:
- the same buffer used to call the method, for chaining.
-
writeDouble
Writes the given double at the current writer index, increasing the index by eight.- Specified by:
writeDoublein interfaceDataBuf.Mutable- Parameters:
d- the double to write into the buffer.- Returns:
- the same buffer used to call the method, for chaining.
-
writeChar
Writes the given UTF-16 char at the current writer index, increasing the index by two.- Specified by:
writeCharin interfaceDataBuf.Mutable- Parameters:
c- the char to write into the buffer.- Returns:
- the same buffer used to call the method, for chaining.
-
writeByteArray
Writes the given byte array into the buffer, prefixed by an integer containing the amount of bytes following in the array.This method call is equivalent to
writeByteArray(b, b.length).- Specified by:
writeByteArrayin interfaceDataBuf.Mutable- Parameters:
b- the byte array to write into the buffer.- Returns:
- the same buffer used to call the method, for chaining.
-
writeByteArray
Writes the given byte array into the buffer, prefixed by an integer containing the amount of bytes following in the array.- Specified by:
writeByteArrayin interfaceDataBuf.Mutable- Parameters:
b- the byte array to write into the buffer.amount- the amount of bytes of the array to write into the buffer.- Returns:
- the same buffer used to call the method, for chaining.
-
writeUniqueId
Writes the unique id into the buffer by first writing the most significant bits of the id followed by the last significant bits of the id.- Specified by:
writeUniqueIdin interfaceDataBuf.Mutable- Parameters:
uuid- the id to write into the buffer.- Returns:
- the same buffer used to call the method, for chaining.
-
writeString
Writes the string into the buffer. This method does the same thing asDataBuf.Mutable.writeByteArray(byte[]). The string gets converted into it's byte array representation and then written into the buffer like that.- Specified by:
writeStringin interfaceDataBuf.Mutable- Parameters:
string- the string to write into the buffer.- Returns:
- the same buffer used to call the method, for chaining.
-
writeDataBuf
Writes all data of the given data buffer into this data buffer starting at the current reader index of the given buffer.Buffers are not expected to be cross-implementation-compatible. For instance, a netty buffer can only be written to netty buffers.
- Specified by:
writeDataBufin interfaceDataBuf.Mutable- Parameters:
buf- the buffer to write into this buffer.- Returns:
- the same buffer used to call the method, for chaining.
-
writeObject
Writes the given object into this buffer. The object is written using the default object mapper of the system.- Specified by:
writeObjectin interfaceDataBuf.Mutable- Parameters:
obj- the object to write into the buffer.- Returns:
- the same buffer used to call the method, for chaining.
- See Also:
-
writeNullable
@NonNull public <T> @NonNull DataBuf.Mutable writeNullable(@Nullable T object, @NonNull @NonNull BiConsumer<DataBuf.Mutable, T> handlerWhenNonNull) Writes the given object null-safe into this buffer. It appends a boolean before the actual object data (if the object is present) whether the data is present. The writer consumer is only called when the data is present and can then safely proceed to write all the required data into the buffer. The supplied buffer is the same buffer used for calling the method.- Specified by:
writeNullablein interfaceDataBuf.Mutable- Type Parameters:
T- the generic type of the object being written.- Parameters:
object- the object which should be safely written into this buffer.handlerWhenNonNull- the writer of the object when it's non-null.- Returns:
- the same buffer used to call the method, for chaining.
-
asImmutable
Converts this buffer into an immutable version of it. The underlying buffer is not expected to be clones, that means that writes to this buffer are still reflected into the immutable version of it and vise-versa.- Specified by:
asImmutablein interfaceDataBuf.Mutable- Returns:
- an immutable version of this buffer.
-