Class NettyDataBufFactory
java.lang.Object
eu.cloudnetservice.driver.network.netty.buffer.NettyDataBufFactory
- All Implemented Interfaces:
DataBufFactory
@Singleton
@Provides(DataBufFactory.class)
public class NettyDataBufFactory
extends Object
implements DataBufFactory
An implementation (and currently the default one) of a data buf factory wrapping netty byte buffers.
- Since:
- 4.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final io.netty5.buffer.BufferAllocatorstatic final NettyDataBufFactory -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a new instance of this factory. -
Method Summary
Modifier and TypeMethodDescriptionCreates a readonly copy of the given data buffer.Creates an empty buffer which can be expanded by writing to it.createWithExpectedSize(int byteSize) Creates an empty mutable data buffer which pre-allocates the specified amount of expected bytes rather than dynamically growing during write operations.fromBytes(byte[] bytes) Creates a new readonly buffer wrapping the given byte array and using it as it's data source.mutableCopyOf(@NonNull DataBuf dataBuf) Creates a mutable copy of the given data buffer.
-
Field Details
-
INSTANCE
-
ALLOCATOR
protected static final io.netty5.buffer.BufferAllocator ALLOCATOR
-
-
Constructor Details
-
NettyDataBufFactory
protected NettyDataBufFactory()Creates a new instance of this factory. This method is protected to allow developers to create their own variant of this factory. In normal casesDataBufFactory.defaultFactory()should be used to obtain the instance of this factory.
-
-
Method Details
-
createEmpty
Creates an empty buffer which can be expanded by writing to it.- Specified by:
createEmptyin interfaceDataBufFactory- Returns:
- a new, empty data buf.
-
fromBytes
Creates a new readonly buffer wrapping the given byte array and using it as it's data source. Modification to the given bytes will be visible in the buffer.- Specified by:
fromBytesin interfaceDataBufFactory- Parameters:
bytes- the bytes to wrap.- Returns:
- a new buffer wrapping the given bytes.
-
copyOf
Creates a readonly copy of the given data buffer. The copied variant of the buffer will start the read process from the first byte rather than re-using the current index of the original buffer.A factory is only expected to be able to copy a buffer created by it. Cross factory copy might be possible but is not a requirement. Use
factory.createOf(buffer.toByteArray)if you want to be sure that the buffer can be copied.- Specified by:
copyOfin interfaceDataBufFactory- Parameters:
dataBuf- the buffer to copy.- Returns:
- a copied variant of the given buffer.
-
mutableCopyOf
Creates a mutable copy of the given data buffer. The copied variant of the buffer will start the read and write process from the first byte rather than re-using the current index of the original buffer.A factory is only expected to be able to copy a buffer created by it. Cross factory copy might be possible but is not a requirement. Use
factory.createOf(buffer.toByteArray)if you want to be sure that the buffer can be copied.- Specified by:
mutableCopyOfin interfaceDataBufFactory- Parameters:
dataBuf- the buffer to copy.- Returns:
- a copied variant of the given buffer.
-
createWithExpectedSize
Creates an empty mutable data buffer which pre-allocates the specified amount of expected bytes rather than dynamically growing during write operations.- Specified by:
createWithExpectedSizein interfaceDataBufFactory- Parameters:
byteSize- the expected amount of bytes which get written.- Returns:
- a new, mutable buffer with the given amount of bytes pre-allocated.
-