-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97807e4
commit 658068d
Showing
35 changed files
with
5,306 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>cosmic-binary-format-parent</artifactId> | ||
<groupId>xyz.xenondevs.cbf</groupId> | ||
<version>0.8</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>cosmic-binary-format-netty-adapter</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>xyz.xenondevs.cbf</groupId> | ||
<artifactId>cosmic-binary-format</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.netty</groupId> | ||
<artifactId>netty-buffer</artifactId> | ||
<version>4.1.78.Final</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
28 changes: 28 additions & 0 deletions
28
...ary-format-netty-adapter/src/main/kotlin/xyz/xenondevs/cbf/adapter/NettyBufferProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package xyz.xenondevs.cbf.adapter | ||
|
||
import io.netty.buffer.ByteBuf | ||
import io.netty.buffer.ByteBufAllocator | ||
import io.netty.buffer.Unpooled | ||
import xyz.xenondevs.cbf.CBF | ||
import kotlin.reflect.KType | ||
import kotlin.reflect.typeOf | ||
|
||
fun ByteBufAllocator.cbfBuffer() = NettyByteBuffer(buffer()) | ||
|
||
fun ByteBufAllocator.cbfBuffer(initialCapacity: Int) = NettyByteBuffer(buffer(initialCapacity)) | ||
|
||
inline fun <reified T> CBF.read(buf: ByteBuf): T? = read(typeOf<T>(), NettyByteBuffer(buf)) | ||
|
||
fun <T> CBF.read(type: KType, buf: ByteBuf): T? = read(type, NettyByteBuffer(buf)) | ||
|
||
fun CBF.write(obj: Any?, buf: ByteBuf) = write(obj, NettyByteBuffer(buf)) | ||
|
||
object NettyBufferProvider { | ||
|
||
fun getBuffer(size: Int) = NettyByteBuffer(Unpooled.buffer(size)) | ||
|
||
fun getBuffer() = NettyByteBuffer(Unpooled.buffer()) | ||
|
||
fun wrappedBuffer(data: ByteArray) = NettyByteBuffer(Unpooled.wrappedBuffer(data)) | ||
|
||
} |
Oops, something went wrong.