SokDoc

sok / Sok.Buffer

Package Sok.Buffer

As Sok is buffer based, you need to use buffers to perform I/O operations. The primitive for that is the MultiplatformBuffer class. This package also contains a basic implementation of a buffer pool for object recycling.

Types

BufferPool
(Common)
class BufferPool
In order to avoid garbage collection pressure it is a common practice to pre-allocate objects that are known to be long-living for a later use, Kotlin channels give us a great way to implement a quite straightforward object pool. The pool will allocate all the buffers lazily when needed, this means that the pool will never suspend until reaching the maximum size.
JSMultiplatformBuffer
(JS)
class JSMultiplatformBuffer
JS implementation of the MultiplatformBuffer class
JVMMultiplatformBuffer
(JVM)
class JVMMultiplatformBuffer
JVM implementation of the MultiplatformBuffer class
MultiplatformBuffer
(Common)
abstract class MultiplatformBuffer
A MultiplatformBuffer is the primitive type of Sok, you will use it to receive, send and manipulate data
NativeMultiplatformBuffer
(Native)
class NativeMultiplatformBuffer
Native implementation of the MultiplatformBuffer class

Functions

allocDirectMultiplatformBuffer
(JVM)
fun allocDirectMultiplatformBuffer(size: Int): <ERROR CLASS>
Allocate a new MultiplatformBuffer. The buffer is not zeroed, be careful.
allocMultiplatformBuffer expect fun allocMultiplatformBuffer(size: Int): MultiplatformBuffer
Allocate a new MultiplatformBuffer. The buffer is not zeroed, be careful.
wrapMultiplatformBuffer expect fun wrapMultiplatformBuffer(array: ByteArray): MultiplatformBuffer
Wrap the array with a MultiplatformBuffer. The data will not be copied and the array will be linked to the MultiplatformBuffer classfun wrapMultiplatformBuffer(array: ByteBuffer): <ERROR CLASS>
Make a MultiplatformBuffer that use a given ByteBuffer.