Interface DataBuf.Mutable
- All Superinterfaces:
AutoCloseable,DataBuf
- Enclosing interface:
DataBuf
Represents a mutable version of a data buf.
- Since:
- 4.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface eu.cloudnetservice.driver.network.buffer.DataBuf
DataBuf.Mutable -
Method Summary
Modifier and TypeMethodDescriptionConverts this buffer into an immutable version of it.ensureWriteable(int bytes) Ensures that this buffer has at least the given amount of bytes unused for writing data.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.<T> DataBuf.MutablewriteNullable(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 interface eu.cloudnetservice.driver.network.buffer.DataBuf
accessible, acquire, acquires, asMutable, close, forceRelease, readableBytes, readBoolean, readByte, readByteArray, readChar, readDataBuf, readDouble, readFloat, readInt, readLong, readNullable, readNullable, readObject, readObject, readShort, readString, readUniqueId, redoTransaction, release, startTransaction, toByteArray
-
Method Details
-
writeBoolean
Writes the given boolean at the current writer index, increasing the index by one.- 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.- 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.- 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.- 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.- 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.- 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.- 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.- 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).- 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.- 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.- 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 aswriteByteArray(byte[]). The string gets converted into it's byte array representation and then written into the buffer like that.- 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.
- 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.- Parameters:
obj- the object to write into the buffer.- Returns:
- the same buffer used to call the method, for chaining.
- See Also:
-
writeNullable
@NonNull <T> 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.- 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.
-
ensureWriteable
Ensures that this buffer has at least the given amount of bytes unused for writing data. If the buffer already has the amount of bytes present, this method returns immediately.- Parameters:
bytes- the bytes that must be available in the buffer.- Returns:
- this buffer, for chaining.
- Throws:
IllegalArgumentException- if the given byte count is negative.
-
asImmutable
-