Skip to content

Commit

Permalink
Fix module casing
Browse files Browse the repository at this point in the history
  • Loading branch information
NichtStudioCode committed Feb 19, 2024
1 parent 97807e4 commit 658068d
Show file tree
Hide file tree
Showing 35 changed files with 5,306 additions and 0 deletions.
27 changes: 27 additions & 0 deletions cosmic-binary-format-netty-adapter/pom.xml
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>
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))

}
Loading

0 comments on commit 658068d

Please sign in to comment.