From d7e9f83953ed35e5c293b6725cbcc086668d8719 Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 2 May 2021 11:38:11 +0100 Subject: [PATCH] Return ByteBuf from extension methods for chaining This is consistent with the built-in ByteBuf methods that would otherwise return void/unit. Signed-off-by: Graham --- .../generator/ByteBufExtensionGenerator.kt | 55 ++ .../buffer/GeneratedByteBufExtensions.kt | 504 ++++++++++++------ 2 files changed, 391 insertions(+), 168 deletions(-) diff --git a/buffer-generator/src/main/kotlin/org/openrs2/buffer/generator/ByteBufExtensionGenerator.kt b/buffer-generator/src/main/kotlin/org/openrs2/buffer/generator/ByteBufExtensionGenerator.kt index 6bd537f6..a38d9f52 100644 --- a/buffer-generator/src/main/kotlin/org/openrs2/buffer/generator/ByteBufExtensionGenerator.kt +++ b/buffer-generator/src/main/kotlin/org/openrs2/buffer/generator/ByteBufExtensionGenerator.kt @@ -179,6 +179,7 @@ public class ByteBufExtensionGenerator { builder.receiver(ByteBuf::class) builder.addParameter("index", Int::class) builder.addParameter("value", type.writeType) + builder.returns(ByteBuf::class) for (i in 0 until type.width) { val shift = order.getShift(i, type.width) @@ -196,6 +197,8 @@ public class ByteBufExtensionGenerator { builder.addStatement("setByte(index + %L, $pre(value shr %L)$post)", i, shift) } + builder.addStatement("return this") + return builder.build() } @@ -205,11 +208,13 @@ public class ByteBufExtensionGenerator { val builder = FunSpec.builder("write$name") builder.receiver(ByteBuf::class) builder.addParameter("value", type.writeType) + builder.returns(ByteBuf::class) builder.addStatement("val index = writerIndex()") builder.addStatement("ensureWritable(%L)", type.width) builder.addStatement("%N(index, value)", "set$name") builder.addStatement("writerIndex(index + %L)", type.width) + builder.addStatement("return this") return builder.build() } @@ -240,6 +245,7 @@ public class ByteBufExtensionGenerator { builder.receiver(ByteBuf::class) builder.addParameter("index", Int::class) builder.addParameter("value", Boolean::class) + builder.returns(ByteBuf::class) builder.beginControlFlow("if (value)") builder.addStatement("%N(index, 1)", "setByte$transformation") @@ -247,6 +253,8 @@ public class ByteBufExtensionGenerator { builder.addStatement("%N(index, 0)", "setByte$transformation") builder.endControlFlow() + builder.addStatement("return this") + return builder.build() } @@ -254,6 +262,7 @@ public class ByteBufExtensionGenerator { val builder = FunSpec.builder("writeBoolean$transformation") builder.receiver(ByteBuf::class) builder.addParameter("value", Boolean::class) + builder.returns(ByteBuf::class) builder.beginControlFlow("if (value)") builder.addStatement("%N(1)", "writeByte$transformation") @@ -261,6 +270,8 @@ public class ByteBufExtensionGenerator { builder.addStatement("%N(0)", "writeByte$transformation") builder.endControlFlow() + builder.addStatement("return this") + return builder.build() } @@ -269,8 +280,10 @@ public class ByteBufExtensionGenerator { builder.receiver(ByteBuf::class) builder.addParameter("index", Int::class) builder.addParameter("dst", ByteArray::class) + builder.returns(ByteBuf::class) builder.addStatement("%N(index, dst, 0, dst.size)", "getBytes${order.suffix}${transformation.suffix}") + builder.addStatement("return this") return builder.build() } @@ -282,6 +295,7 @@ public class ByteBufExtensionGenerator { builder.addParameter("dst", ByteArray::class) builder.addParameter("dstIndex", Int::class) builder.addParameter("len", Int::class) + builder.returns(ByteBuf::class) builder.addStatement("getBytes(index, dst, dstIndex, len)") builder.beginControlFlow("for (i in 0 until len)") @@ -295,6 +309,8 @@ public class ByteBufExtensionGenerator { builder.addStatement("dst.reverse(dstIndex, dstIndex + len)") } + builder.addStatement("return this") + return builder.build() } @@ -303,12 +319,14 @@ public class ByteBufExtensionGenerator { builder.receiver(ByteBuf::class) builder.addParameter("index", Int::class) builder.addParameter("dst", ByteBuf::class) + builder.returns(ByteBuf::class) builder.addStatement("val dstIndex = dst.writerIndex()") builder.addStatement("val len = dst.writableBytes()") builder.addStatement("dst.ensureWritable(len)") builder.addStatement("%N(index, dst, dstIndex, len)", "getBytes${order.suffix}${transformation.suffix}") builder.addStatement("dst.writerIndex(dstIndex + len)") + builder.addStatement("return this") return builder.build() } @@ -319,11 +337,13 @@ public class ByteBufExtensionGenerator { builder.addParameter("index", Int::class) builder.addParameter("dst", ByteBuf::class) builder.addParameter("len", Int::class) + builder.returns(ByteBuf::class) builder.addStatement("val dstIndex = dst.writerIndex()") builder.addStatement("dst.ensureWritable(len)") builder.addStatement("%N(index, dst, dstIndex, len)", "getBytes${order.suffix}${transformation.suffix}") builder.addStatement("dst.writerIndex(dstIndex + len)") + builder.addStatement("return this") return builder.build() } @@ -335,6 +355,7 @@ public class ByteBufExtensionGenerator { builder.addParameter("dst", ByteBuf::class) builder.addParameter("dstIndex", Int::class) builder.addParameter("len", Int::class) + builder.returns(ByteBuf::class) val srcIndex = if (order == ArrayOrder.FORWARD) { "i" @@ -349,6 +370,8 @@ public class ByteBufExtensionGenerator { ) builder.endControlFlow() + builder.addStatement("return this") + return builder.build() } @@ -374,8 +397,10 @@ public class ByteBufExtensionGenerator { val builder = FunSpec.builder("readBytes${order.suffix}${transformation.suffix}") builder.receiver(ByteBuf::class) builder.addParameter("dst", ByteArray::class) + builder.returns(ByteBuf::class) builder.addStatement("%N(dst, 0, dst.size)", "readBytes${order.suffix}${transformation.suffix}") + builder.addStatement("return this") return builder.build() } @@ -386,10 +411,12 @@ public class ByteBufExtensionGenerator { builder.addParameter("dst", ByteArray::class) builder.addParameter("dstIndex", Int::class) builder.addParameter("len", Int::class) + builder.returns(ByteBuf::class) builder.addStatement("val index = readerIndex()") builder.addStatement("%N(index, dst, dstIndex, len)", "getBytes${order.suffix}${transformation.suffix}") builder.addStatement("readerIndex(index + len)") + builder.addStatement("return this") return builder.build() } @@ -398,12 +425,14 @@ public class ByteBufExtensionGenerator { val builder = FunSpec.builder("readBytes${order.suffix}${transformation.suffix}") builder.receiver(ByteBuf::class) builder.addParameter("dst", ByteBuf::class) + builder.returns(ByteBuf::class) builder.addStatement("val dstIndex = dst.writerIndex()") builder.addStatement("val len = dst.writableBytes()") builder.addStatement("dst.ensureWritable(len)") builder.addStatement("%N(dst, dstIndex, len)", "readBytes${order.suffix}${transformation.suffix}") builder.addStatement("dst.writerIndex(dstIndex + len)") + builder.addStatement("return this") return builder.build() } @@ -413,11 +442,13 @@ public class ByteBufExtensionGenerator { builder.receiver(ByteBuf::class) builder.addParameter("dst", ByteBuf::class) builder.addParameter("len", Int::class) + builder.returns(ByteBuf::class) builder.addStatement("val dstIndex = dst.writerIndex()") builder.addStatement("dst.ensureWritable(len)") builder.addStatement("%N(dst, dstIndex, len)", "readBytes${order.suffix}${transformation.suffix}") builder.addStatement("dst.writerIndex(dstIndex + len)") + builder.addStatement("return this") return builder.build() } @@ -428,10 +459,12 @@ public class ByteBufExtensionGenerator { builder.addParameter("dst", ByteBuf::class) builder.addParameter("dstIndex", Int::class) builder.addParameter("len", Int::class) + builder.returns(ByteBuf::class) builder.addStatement("val index = readerIndex()") builder.addStatement("%N(index, dst, dstIndex, len)", "getBytes${order.suffix}${transformation.suffix}") builder.addStatement("readerIndex(index + len)") + builder.addStatement("return this") return builder.build() } @@ -441,8 +474,10 @@ public class ByteBufExtensionGenerator { builder.receiver(ByteBuf::class) builder.addParameter("index", Int::class) builder.addParameter("src", ByteArray::class) + builder.returns(ByteBuf::class) builder.addStatement("%N(index, src, 0, src.size)", "setBytes${order.suffix}${transformation.suffix}") + builder.addStatement("return this") return builder.build() } @@ -454,11 +489,14 @@ public class ByteBufExtensionGenerator { builder.addParameter("src", ByteArray::class) builder.addParameter("srcIndex", Int::class) builder.addParameter("len", Int::class) + builder.returns(ByteBuf::class) builder.beginControlFlow("%T.wrappedBuffer(src).use { buf ->", Unpooled::class) builder.addStatement("%N(index, buf, srcIndex, len)", "setBytes${order.suffix}${transformation.suffix}") builder.endControlFlow() + builder.addStatement("return this") + return builder.build() } @@ -467,11 +505,13 @@ public class ByteBufExtensionGenerator { builder.receiver(ByteBuf::class) builder.addParameter("index", Int::class) builder.addParameter("src", ByteBuf::class) + builder.returns(ByteBuf::class) builder.addStatement("val srcIndex = src.readerIndex()") builder.addStatement("val len = src.readableBytes()") builder.addStatement("%N(index, src, srcIndex, len)", "setBytes${order.suffix}${transformation.suffix}") builder.addStatement("src.readerIndex(srcIndex + len)") + builder.addStatement("return this") return builder.build() } @@ -482,10 +522,12 @@ public class ByteBufExtensionGenerator { builder.addParameter("index", Int::class) builder.addParameter("src", ByteBuf::class) builder.addParameter("len", Int::class) + builder.returns(ByteBuf::class) builder.addStatement("val srcIndex = src.readerIndex()") builder.addStatement("%N(index, src, srcIndex, len)", "setBytes${order.suffix}${transformation.suffix}") builder.addStatement("src.readerIndex(srcIndex + len)") + builder.addStatement("return this") return builder.build() } @@ -497,6 +539,7 @@ public class ByteBufExtensionGenerator { builder.addParameter("src", ByteBuf::class) builder.addParameter("srcIndex", Int::class) builder.addParameter("len", Int::class) + builder.returns(ByteBuf::class) val srcIndex = if (order == ArrayOrder.FORWARD) { "i" @@ -511,6 +554,8 @@ public class ByteBufExtensionGenerator { ) builder.endControlFlow() + builder.addStatement("return this") + return builder.build() } @@ -518,8 +563,10 @@ public class ByteBufExtensionGenerator { val builder = FunSpec.builder("writeBytes${order.suffix}${transformation.suffix}") builder.receiver(ByteBuf::class) builder.addParameter("src", ByteArray::class) + builder.returns(ByteBuf::class) builder.addStatement("%N(src, 0, src.size)", "writeBytes${order.suffix}${transformation.suffix}") + builder.addStatement("return this") return builder.build() } @@ -530,11 +577,13 @@ public class ByteBufExtensionGenerator { builder.addParameter("src", ByteArray::class) builder.addParameter("srcIndex", Int::class) builder.addParameter("len", Int::class) + builder.returns(ByteBuf::class) builder.addStatement("val index = writerIndex()") builder.addStatement("ensureWritable(len)") builder.addStatement("%N(index, src, srcIndex, len)", "setBytes${order.suffix}${transformation.suffix}") builder.addStatement("writerIndex(index + len)") + builder.addStatement("return this") return builder.build() } @@ -543,11 +592,13 @@ public class ByteBufExtensionGenerator { val builder = FunSpec.builder("writeBytes${order.suffix}${transformation.suffix}") builder.receiver(ByteBuf::class) builder.addParameter("src", ByteBuf::class) + builder.returns(ByteBuf::class) builder.addStatement("val srcIndex = src.readerIndex()") builder.addStatement("val len = src.readableBytes()") builder.addStatement("%N(src, srcIndex, len)", "writeBytes${order.suffix}${transformation.suffix}") builder.addStatement("src.readerIndex(srcIndex + len)") + builder.addStatement("return this") return builder.build() } @@ -557,10 +608,12 @@ public class ByteBufExtensionGenerator { builder.receiver(ByteBuf::class) builder.addParameter("src", ByteBuf::class) builder.addParameter("len", Int::class) + builder.returns(ByteBuf::class) builder.addStatement("val srcIndex = src.readerIndex()") builder.addStatement("%N(src, srcIndex, len)", "writeBytes${order.suffix}${transformation.suffix}") builder.addStatement("src.readerIndex(srcIndex + len)") + builder.addStatement("return this") return builder.build() } @@ -571,11 +624,13 @@ public class ByteBufExtensionGenerator { builder.addParameter("src", ByteBuf::class) builder.addParameter("srcIndex", Int::class) builder.addParameter("len", Int::class) + builder.returns(ByteBuf::class) builder.addStatement("val index = writerIndex()") builder.addStatement("ensureWritable(len)") builder.addStatement("%N(index, src, srcIndex, len)", "setBytes${order.suffix}${transformation.suffix}") builder.addStatement("writerIndex(index + len)") + builder.addStatement("return this") return builder.build() } diff --git a/buffer/src/main/kotlin/org/openrs2/buffer/GeneratedByteBufExtensions.kt b/buffer/src/main/kotlin/org/openrs2/buffer/GeneratedByteBufExtensions.kt index 451ffcab..09682d17 100644 --- a/buffer/src/main/kotlin/org/openrs2/buffer/GeneratedByteBufExtensions.kt +++ b/buffer/src/main/kotlin/org/openrs2/buffer/GeneratedByteBufExtensions.kt @@ -30,15 +30,17 @@ public fun ByteBuf.readUnsignedByteA(): Short { return result } -public fun ByteBuf.setByteA(index: Int, `value`: Int) { +public fun ByteBuf.setByteA(index: Int, `value`: Int): ByteBuf { setByte(index + 0, (value shr 0) + 128) + return this } -public fun ByteBuf.writeByteA(`value`: Int) { +public fun ByteBuf.writeByteA(`value`: Int): ByteBuf { val index = writerIndex() ensureWritable(1) setByteA(index, value) writerIndex(index + 1) + return this } public fun ByteBuf.getByteC(index: Int): Byte { @@ -67,15 +69,17 @@ public fun ByteBuf.readUnsignedByteC(): Short { return result } -public fun ByteBuf.setByteC(index: Int, `value`: Int) { +public fun ByteBuf.setByteC(index: Int, `value`: Int): ByteBuf { setByte(index + 0, -(value shr 0)) + return this } -public fun ByteBuf.writeByteC(`value`: Int) { +public fun ByteBuf.writeByteC(`value`: Int): ByteBuf { val index = writerIndex() ensureWritable(1) setByteC(index, value) writerIndex(index + 1) + return this } public fun ByteBuf.getByteS(index: Int): Byte { @@ -104,15 +108,17 @@ public fun ByteBuf.readUnsignedByteS(): Short { return result } -public fun ByteBuf.setByteS(index: Int, `value`: Int) { +public fun ByteBuf.setByteS(index: Int, `value`: Int): ByteBuf { setByte(index + 0, 128 - (value shr 0)) + return this } -public fun ByteBuf.writeByteS(`value`: Int) { +public fun ByteBuf.writeByteS(`value`: Int): ByteBuf { val index = writerIndex() ensureWritable(1) setByteS(index, value) writerIndex(index + 1) + return this } public fun ByteBuf.getShortA(index: Int): Short { @@ -143,16 +149,18 @@ public fun ByteBuf.readUnsignedShortA(): Int { return result } -public fun ByteBuf.setShortA(index: Int, `value`: Int) { +public fun ByteBuf.setShortA(index: Int, `value`: Int): ByteBuf { setByte(index + 0, (value shr 8)) setByte(index + 1, (value shr 0) + 128) + return this } -public fun ByteBuf.writeShortA(`value`: Int) { +public fun ByteBuf.writeShortA(`value`: Int): ByteBuf { val index = writerIndex() ensureWritable(2) setShortA(index, value) writerIndex(index + 2) + return this } public fun ByteBuf.getShortC(index: Int): Short { @@ -183,16 +191,18 @@ public fun ByteBuf.readUnsignedShortC(): Int { return result } -public fun ByteBuf.setShortC(index: Int, `value`: Int) { +public fun ByteBuf.setShortC(index: Int, `value`: Int): ByteBuf { setByte(index + 0, (value shr 8)) setByte(index + 1, -(value shr 0)) + return this } -public fun ByteBuf.writeShortC(`value`: Int) { +public fun ByteBuf.writeShortC(`value`: Int): ByteBuf { val index = writerIndex() ensureWritable(2) setShortC(index, value) writerIndex(index + 2) + return this } public fun ByteBuf.getShortS(index: Int): Short { @@ -223,16 +233,18 @@ public fun ByteBuf.readUnsignedShortS(): Int { return result } -public fun ByteBuf.setShortS(index: Int, `value`: Int) { +public fun ByteBuf.setShortS(index: Int, `value`: Int): ByteBuf { setByte(index + 0, (value shr 8)) setByte(index + 1, 128 - (value shr 0)) + return this } -public fun ByteBuf.writeShortS(`value`: Int) { +public fun ByteBuf.writeShortS(`value`: Int): ByteBuf { val index = writerIndex() ensureWritable(2) setShortS(index, value) writerIndex(index + 2) + return this } public fun ByteBuf.getShortLEA(index: Int): Short { @@ -263,16 +275,18 @@ public fun ByteBuf.readUnsignedShortLEA(): Int { return result } -public fun ByteBuf.setShortLEA(index: Int, `value`: Int) { +public fun ByteBuf.setShortLEA(index: Int, `value`: Int): ByteBuf { setByte(index + 0, (value shr 0) + 128) setByte(index + 1, (value shr 8)) + return this } -public fun ByteBuf.writeShortLEA(`value`: Int) { +public fun ByteBuf.writeShortLEA(`value`: Int): ByteBuf { val index = writerIndex() ensureWritable(2) setShortLEA(index, value) writerIndex(index + 2) + return this } public fun ByteBuf.getShortLEC(index: Int): Short { @@ -303,16 +317,18 @@ public fun ByteBuf.readUnsignedShortLEC(): Int { return result } -public fun ByteBuf.setShortLEC(index: Int, `value`: Int) { +public fun ByteBuf.setShortLEC(index: Int, `value`: Int): ByteBuf { setByte(index + 0, -(value shr 0)) setByte(index + 1, (value shr 8)) + return this } -public fun ByteBuf.writeShortLEC(`value`: Int) { +public fun ByteBuf.writeShortLEC(`value`: Int): ByteBuf { val index = writerIndex() ensureWritable(2) setShortLEC(index, value) writerIndex(index + 2) + return this } public fun ByteBuf.getShortLES(index: Int): Short { @@ -343,16 +359,18 @@ public fun ByteBuf.readUnsignedShortLES(): Int { return result } -public fun ByteBuf.setShortLES(index: Int, `value`: Int) { +public fun ByteBuf.setShortLES(index: Int, `value`: Int): ByteBuf { setByte(index + 0, 128 - (value shr 0)) setByte(index + 1, (value shr 8)) + return this } -public fun ByteBuf.writeShortLES(`value`: Int) { +public fun ByteBuf.writeShortLES(`value`: Int): ByteBuf { val index = writerIndex() ensureWritable(2) setShortLES(index, value) writerIndex(index + 2) + return this } public fun ByteBuf.getIntAlt3(index: Int): Int { @@ -371,18 +389,20 @@ public fun ByteBuf.readIntAlt3(): Int { return result } -public fun ByteBuf.setIntAlt3(index: Int, `value`: Int) { +public fun ByteBuf.setIntAlt3(index: Int, `value`: Int): ByteBuf { setByte(index + 0, (value shr 16)) setByte(index + 1, (value shr 24)) setByte(index + 2, (value shr 0)) setByte(index + 3, (value shr 8)) + return this } -public fun ByteBuf.writeIntAlt3(`value`: Int) { +public fun ByteBuf.writeIntAlt3(`value`: Int): ByteBuf { val index = writerIndex() ensureWritable(4) setIntAlt3(index, value) writerIndex(index + 4) + return this } public fun ByteBuf.getIntAlt3Reverse(index: Int): Int { @@ -401,22 +421,25 @@ public fun ByteBuf.readIntAlt3Reverse(): Int { return result } -public fun ByteBuf.setIntAlt3Reverse(index: Int, `value`: Int) { +public fun ByteBuf.setIntAlt3Reverse(index: Int, `value`: Int): ByteBuf { setByte(index + 0, (value shr 8)) setByte(index + 1, (value shr 0)) setByte(index + 2, (value shr 24)) setByte(index + 3, (value shr 16)) + return this } -public fun ByteBuf.writeIntAlt3Reverse(`value`: Int) { +public fun ByteBuf.writeIntAlt3Reverse(`value`: Int): ByteBuf { val index = writerIndex() ensureWritable(4) setIntAlt3Reverse(index, value) writerIndex(index + 4) + return this } -public fun ByteBuf.getBytesA(index: Int, dst: ByteArray) { +public fun ByteBuf.getBytesA(index: Int, dst: ByteArray): ByteBuf { getBytesA(index, dst, 0, dst.size) + return this } public fun ByteBuf.getBytesA( @@ -424,30 +447,33 @@ public fun ByteBuf.getBytesA( dst: ByteArray, dstIndex: Int, len: Int -) { +): ByteBuf { getBytes(index, dst, dstIndex, len) for (i in 0 until len) { dst[dstIndex + i] = (dst[dstIndex + i].toInt() - 128).toByte() } + return this } -public fun ByteBuf.getBytesA(index: Int, dst: ByteBuf) { +public fun ByteBuf.getBytesA(index: Int, dst: ByteBuf): ByteBuf { val dstIndex = dst.writerIndex() val len = dst.writableBytes() dst.ensureWritable(len) getBytesA(index, dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } public fun ByteBuf.getBytesA( index: Int, dst: ByteBuf, len: Int -) { +): ByteBuf { val dstIndex = dst.writerIndex() dst.ensureWritable(len) getBytesA(index, dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } public fun ByteBuf.getBytesA( @@ -455,49 +481,55 @@ public fun ByteBuf.getBytesA( dst: ByteBuf, dstIndex: Int, len: Int -) { +): ByteBuf { for (i in 0 until len) { dst.setByte(dstIndex + i, getByteA(index + i).toInt()) } + return this } -public fun ByteBuf.readBytesA(dst: ByteArray) { +public fun ByteBuf.readBytesA(dst: ByteArray): ByteBuf { readBytesA(dst, 0, dst.size) + return this } public fun ByteBuf.readBytesA( dst: ByteArray, dstIndex: Int, len: Int -) { +): ByteBuf { val index = readerIndex() getBytesA(index, dst, dstIndex, len) readerIndex(index + len) + return this } -public fun ByteBuf.readBytesA(dst: ByteBuf) { +public fun ByteBuf.readBytesA(dst: ByteBuf): ByteBuf { val dstIndex = dst.writerIndex() val len = dst.writableBytes() dst.ensureWritable(len) readBytesA(dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } -public fun ByteBuf.readBytesA(dst: ByteBuf, len: Int) { +public fun ByteBuf.readBytesA(dst: ByteBuf, len: Int): ByteBuf { val dstIndex = dst.writerIndex() dst.ensureWritable(len) readBytesA(dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } public fun ByteBuf.readBytesA( dst: ByteBuf, dstIndex: Int, len: Int -) { +): ByteBuf { val index = readerIndex() getBytesA(index, dst, dstIndex, len) readerIndex(index + len) + return this } public fun ByteBuf.readBytesA(len: Int): ByteBuf { @@ -510,8 +542,9 @@ public fun ByteBuf.readBytesA(len: Int): ByteBuf { } } -public fun ByteBuf.setBytesA(index: Int, src: ByteArray) { +public fun ByteBuf.setBytesA(index: Int, src: ByteArray): ByteBuf { setBytesA(index, src, 0, src.size) + return this } public fun ByteBuf.setBytesA( @@ -519,27 +552,30 @@ public fun ByteBuf.setBytesA( src: ByteArray, srcIndex: Int, len: Int -) { +): ByteBuf { Unpooled.wrappedBuffer(src).use { buf -> setBytesA(index, buf, srcIndex, len) } + return this } -public fun ByteBuf.setBytesA(index: Int, src: ByteBuf) { +public fun ByteBuf.setBytesA(index: Int, src: ByteBuf): ByteBuf { val srcIndex = src.readerIndex() val len = src.readableBytes() setBytesA(index, src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } public fun ByteBuf.setBytesA( index: Int, src: ByteBuf, len: Int -) { +): ByteBuf { val srcIndex = src.readerIndex() setBytesA(index, src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } public fun ByteBuf.setBytesA( @@ -547,53 +583,60 @@ public fun ByteBuf.setBytesA( src: ByteBuf, srcIndex: Int, len: Int -) { +): ByteBuf { for (i in 0 until len) { setByteA(index + i, src.getByte(srcIndex + i).toInt()) } + return this } -public fun ByteBuf.writeBytesA(src: ByteArray) { +public fun ByteBuf.writeBytesA(src: ByteArray): ByteBuf { writeBytesA(src, 0, src.size) + return this } public fun ByteBuf.writeBytesA( src: ByteArray, srcIndex: Int, len: Int -) { +): ByteBuf { val index = writerIndex() ensureWritable(len) setBytesA(index, src, srcIndex, len) writerIndex(index + len) + return this } -public fun ByteBuf.writeBytesA(src: ByteBuf) { +public fun ByteBuf.writeBytesA(src: ByteBuf): ByteBuf { val srcIndex = src.readerIndex() val len = src.readableBytes() writeBytesA(src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } -public fun ByteBuf.writeBytesA(src: ByteBuf, len: Int) { +public fun ByteBuf.writeBytesA(src: ByteBuf, len: Int): ByteBuf { val srcIndex = src.readerIndex() writeBytesA(src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } public fun ByteBuf.writeBytesA( src: ByteBuf, srcIndex: Int, len: Int -) { +): ByteBuf { val index = writerIndex() ensureWritable(len) setBytesA(index, src, srcIndex, len) writerIndex(index + len) + return this } -public fun ByteBuf.getBytesC(index: Int, dst: ByteArray) { +public fun ByteBuf.getBytesC(index: Int, dst: ByteArray): ByteBuf { getBytesC(index, dst, 0, dst.size) + return this } public fun ByteBuf.getBytesC( @@ -601,30 +644,33 @@ public fun ByteBuf.getBytesC( dst: ByteArray, dstIndex: Int, len: Int -) { +): ByteBuf { getBytes(index, dst, dstIndex, len) for (i in 0 until len) { dst[dstIndex + i] = (-dst[dstIndex + i].toInt()).toByte() } + return this } -public fun ByteBuf.getBytesC(index: Int, dst: ByteBuf) { +public fun ByteBuf.getBytesC(index: Int, dst: ByteBuf): ByteBuf { val dstIndex = dst.writerIndex() val len = dst.writableBytes() dst.ensureWritable(len) getBytesC(index, dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } public fun ByteBuf.getBytesC( index: Int, dst: ByteBuf, len: Int -) { +): ByteBuf { val dstIndex = dst.writerIndex() dst.ensureWritable(len) getBytesC(index, dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } public fun ByteBuf.getBytesC( @@ -632,49 +678,55 @@ public fun ByteBuf.getBytesC( dst: ByteBuf, dstIndex: Int, len: Int -) { +): ByteBuf { for (i in 0 until len) { dst.setByte(dstIndex + i, getByteC(index + i).toInt()) } + return this } -public fun ByteBuf.readBytesC(dst: ByteArray) { +public fun ByteBuf.readBytesC(dst: ByteArray): ByteBuf { readBytesC(dst, 0, dst.size) + return this } public fun ByteBuf.readBytesC( dst: ByteArray, dstIndex: Int, len: Int -) { +): ByteBuf { val index = readerIndex() getBytesC(index, dst, dstIndex, len) readerIndex(index + len) + return this } -public fun ByteBuf.readBytesC(dst: ByteBuf) { +public fun ByteBuf.readBytesC(dst: ByteBuf): ByteBuf { val dstIndex = dst.writerIndex() val len = dst.writableBytes() dst.ensureWritable(len) readBytesC(dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } -public fun ByteBuf.readBytesC(dst: ByteBuf, len: Int) { +public fun ByteBuf.readBytesC(dst: ByteBuf, len: Int): ByteBuf { val dstIndex = dst.writerIndex() dst.ensureWritable(len) readBytesC(dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } public fun ByteBuf.readBytesC( dst: ByteBuf, dstIndex: Int, len: Int -) { +): ByteBuf { val index = readerIndex() getBytesC(index, dst, dstIndex, len) readerIndex(index + len) + return this } public fun ByteBuf.readBytesC(len: Int): ByteBuf { @@ -687,8 +739,9 @@ public fun ByteBuf.readBytesC(len: Int): ByteBuf { } } -public fun ByteBuf.setBytesC(index: Int, src: ByteArray) { +public fun ByteBuf.setBytesC(index: Int, src: ByteArray): ByteBuf { setBytesC(index, src, 0, src.size) + return this } public fun ByteBuf.setBytesC( @@ -696,27 +749,30 @@ public fun ByteBuf.setBytesC( src: ByteArray, srcIndex: Int, len: Int -) { +): ByteBuf { Unpooled.wrappedBuffer(src).use { buf -> setBytesC(index, buf, srcIndex, len) } + return this } -public fun ByteBuf.setBytesC(index: Int, src: ByteBuf) { +public fun ByteBuf.setBytesC(index: Int, src: ByteBuf): ByteBuf { val srcIndex = src.readerIndex() val len = src.readableBytes() setBytesC(index, src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } public fun ByteBuf.setBytesC( index: Int, src: ByteBuf, len: Int -) { +): ByteBuf { val srcIndex = src.readerIndex() setBytesC(index, src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } public fun ByteBuf.setBytesC( @@ -724,53 +780,60 @@ public fun ByteBuf.setBytesC( src: ByteBuf, srcIndex: Int, len: Int -) { +): ByteBuf { for (i in 0 until len) { setByteC(index + i, src.getByte(srcIndex + i).toInt()) } + return this } -public fun ByteBuf.writeBytesC(src: ByteArray) { +public fun ByteBuf.writeBytesC(src: ByteArray): ByteBuf { writeBytesC(src, 0, src.size) + return this } public fun ByteBuf.writeBytesC( src: ByteArray, srcIndex: Int, len: Int -) { +): ByteBuf { val index = writerIndex() ensureWritable(len) setBytesC(index, src, srcIndex, len) writerIndex(index + len) + return this } -public fun ByteBuf.writeBytesC(src: ByteBuf) { +public fun ByteBuf.writeBytesC(src: ByteBuf): ByteBuf { val srcIndex = src.readerIndex() val len = src.readableBytes() writeBytesC(src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } -public fun ByteBuf.writeBytesC(src: ByteBuf, len: Int) { +public fun ByteBuf.writeBytesC(src: ByteBuf, len: Int): ByteBuf { val srcIndex = src.readerIndex() writeBytesC(src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } public fun ByteBuf.writeBytesC( src: ByteBuf, srcIndex: Int, len: Int -) { +): ByteBuf { val index = writerIndex() ensureWritable(len) setBytesC(index, src, srcIndex, len) writerIndex(index + len) + return this } -public fun ByteBuf.getBytesS(index: Int, dst: ByteArray) { +public fun ByteBuf.getBytesS(index: Int, dst: ByteArray): ByteBuf { getBytesS(index, dst, 0, dst.size) + return this } public fun ByteBuf.getBytesS( @@ -778,30 +841,33 @@ public fun ByteBuf.getBytesS( dst: ByteArray, dstIndex: Int, len: Int -) { +): ByteBuf { getBytes(index, dst, dstIndex, len) for (i in 0 until len) { dst[dstIndex + i] = (128 - dst[dstIndex + i].toInt()).toByte() } + return this } -public fun ByteBuf.getBytesS(index: Int, dst: ByteBuf) { +public fun ByteBuf.getBytesS(index: Int, dst: ByteBuf): ByteBuf { val dstIndex = dst.writerIndex() val len = dst.writableBytes() dst.ensureWritable(len) getBytesS(index, dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } public fun ByteBuf.getBytesS( index: Int, dst: ByteBuf, len: Int -) { +): ByteBuf { val dstIndex = dst.writerIndex() dst.ensureWritable(len) getBytesS(index, dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } public fun ByteBuf.getBytesS( @@ -809,49 +875,55 @@ public fun ByteBuf.getBytesS( dst: ByteBuf, dstIndex: Int, len: Int -) { +): ByteBuf { for (i in 0 until len) { dst.setByte(dstIndex + i, getByteS(index + i).toInt()) } + return this } -public fun ByteBuf.readBytesS(dst: ByteArray) { +public fun ByteBuf.readBytesS(dst: ByteArray): ByteBuf { readBytesS(dst, 0, dst.size) + return this } public fun ByteBuf.readBytesS( dst: ByteArray, dstIndex: Int, len: Int -) { +): ByteBuf { val index = readerIndex() getBytesS(index, dst, dstIndex, len) readerIndex(index + len) + return this } -public fun ByteBuf.readBytesS(dst: ByteBuf) { +public fun ByteBuf.readBytesS(dst: ByteBuf): ByteBuf { val dstIndex = dst.writerIndex() val len = dst.writableBytes() dst.ensureWritable(len) readBytesS(dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } -public fun ByteBuf.readBytesS(dst: ByteBuf, len: Int) { +public fun ByteBuf.readBytesS(dst: ByteBuf, len: Int): ByteBuf { val dstIndex = dst.writerIndex() dst.ensureWritable(len) readBytesS(dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } public fun ByteBuf.readBytesS( dst: ByteBuf, dstIndex: Int, len: Int -) { +): ByteBuf { val index = readerIndex() getBytesS(index, dst, dstIndex, len) readerIndex(index + len) + return this } public fun ByteBuf.readBytesS(len: Int): ByteBuf { @@ -864,8 +936,9 @@ public fun ByteBuf.readBytesS(len: Int): ByteBuf { } } -public fun ByteBuf.setBytesS(index: Int, src: ByteArray) { +public fun ByteBuf.setBytesS(index: Int, src: ByteArray): ByteBuf { setBytesS(index, src, 0, src.size) + return this } public fun ByteBuf.setBytesS( @@ -873,27 +946,30 @@ public fun ByteBuf.setBytesS( src: ByteArray, srcIndex: Int, len: Int -) { +): ByteBuf { Unpooled.wrappedBuffer(src).use { buf -> setBytesS(index, buf, srcIndex, len) } + return this } -public fun ByteBuf.setBytesS(index: Int, src: ByteBuf) { +public fun ByteBuf.setBytesS(index: Int, src: ByteBuf): ByteBuf { val srcIndex = src.readerIndex() val len = src.readableBytes() setBytesS(index, src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } public fun ByteBuf.setBytesS( index: Int, src: ByteBuf, len: Int -) { +): ByteBuf { val srcIndex = src.readerIndex() setBytesS(index, src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } public fun ByteBuf.setBytesS( @@ -901,53 +977,60 @@ public fun ByteBuf.setBytesS( src: ByteBuf, srcIndex: Int, len: Int -) { +): ByteBuf { for (i in 0 until len) { setByteS(index + i, src.getByte(srcIndex + i).toInt()) } + return this } -public fun ByteBuf.writeBytesS(src: ByteArray) { +public fun ByteBuf.writeBytesS(src: ByteArray): ByteBuf { writeBytesS(src, 0, src.size) + return this } public fun ByteBuf.writeBytesS( src: ByteArray, srcIndex: Int, len: Int -) { +): ByteBuf { val index = writerIndex() ensureWritable(len) setBytesS(index, src, srcIndex, len) writerIndex(index + len) + return this } -public fun ByteBuf.writeBytesS(src: ByteBuf) { +public fun ByteBuf.writeBytesS(src: ByteBuf): ByteBuf { val srcIndex = src.readerIndex() val len = src.readableBytes() writeBytesS(src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } -public fun ByteBuf.writeBytesS(src: ByteBuf, len: Int) { +public fun ByteBuf.writeBytesS(src: ByteBuf, len: Int): ByteBuf { val srcIndex = src.readerIndex() writeBytesS(src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } public fun ByteBuf.writeBytesS( src: ByteBuf, srcIndex: Int, len: Int -) { +): ByteBuf { val index = writerIndex() ensureWritable(len) setBytesS(index, src, srcIndex, len) writerIndex(index + len) + return this } -public fun ByteBuf.getBytesReverse(index: Int, dst: ByteArray) { +public fun ByteBuf.getBytesReverse(index: Int, dst: ByteArray): ByteBuf { getBytesReverse(index, dst, 0, dst.size) + return this } public fun ByteBuf.getBytesReverse( @@ -955,31 +1038,34 @@ public fun ByteBuf.getBytesReverse( dst: ByteArray, dstIndex: Int, len: Int -) { +): ByteBuf { getBytes(index, dst, dstIndex, len) for (i in 0 until len) { dst[dstIndex + i] = (dst[dstIndex + i].toInt()).toByte() } dst.reverse(dstIndex, dstIndex + len) + return this } -public fun ByteBuf.getBytesReverse(index: Int, dst: ByteBuf) { +public fun ByteBuf.getBytesReverse(index: Int, dst: ByteBuf): ByteBuf { val dstIndex = dst.writerIndex() val len = dst.writableBytes() dst.ensureWritable(len) getBytesReverse(index, dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } public fun ByteBuf.getBytesReverse( index: Int, dst: ByteBuf, len: Int -) { +): ByteBuf { val dstIndex = dst.writerIndex() dst.ensureWritable(len) getBytesReverse(index, dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } public fun ByteBuf.getBytesReverse( @@ -987,49 +1073,55 @@ public fun ByteBuf.getBytesReverse( dst: ByteBuf, dstIndex: Int, len: Int -) { +): ByteBuf { for (i in 0 until len) { dst.setByte(dstIndex + i, getByte(index + len - i - 1).toInt()) } + return this } -public fun ByteBuf.readBytesReverse(dst: ByteArray) { +public fun ByteBuf.readBytesReverse(dst: ByteArray): ByteBuf { readBytesReverse(dst, 0, dst.size) + return this } public fun ByteBuf.readBytesReverse( dst: ByteArray, dstIndex: Int, len: Int -) { +): ByteBuf { val index = readerIndex() getBytesReverse(index, dst, dstIndex, len) readerIndex(index + len) + return this } -public fun ByteBuf.readBytesReverse(dst: ByteBuf) { +public fun ByteBuf.readBytesReverse(dst: ByteBuf): ByteBuf { val dstIndex = dst.writerIndex() val len = dst.writableBytes() dst.ensureWritable(len) readBytesReverse(dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } -public fun ByteBuf.readBytesReverse(dst: ByteBuf, len: Int) { +public fun ByteBuf.readBytesReverse(dst: ByteBuf, len: Int): ByteBuf { val dstIndex = dst.writerIndex() dst.ensureWritable(len) readBytesReverse(dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } public fun ByteBuf.readBytesReverse( dst: ByteBuf, dstIndex: Int, len: Int -) { +): ByteBuf { val index = readerIndex() getBytesReverse(index, dst, dstIndex, len) readerIndex(index + len) + return this } public fun ByteBuf.readBytesReverse(len: Int): ByteBuf { @@ -1042,8 +1134,9 @@ public fun ByteBuf.readBytesReverse(len: Int): ByteBuf { } } -public fun ByteBuf.setBytesReverse(index: Int, src: ByteArray) { +public fun ByteBuf.setBytesReverse(index: Int, src: ByteArray): ByteBuf { setBytesReverse(index, src, 0, src.size) + return this } public fun ByteBuf.setBytesReverse( @@ -1051,27 +1144,30 @@ public fun ByteBuf.setBytesReverse( src: ByteArray, srcIndex: Int, len: Int -) { +): ByteBuf { Unpooled.wrappedBuffer(src).use { buf -> setBytesReverse(index, buf, srcIndex, len) } + return this } -public fun ByteBuf.setBytesReverse(index: Int, src: ByteBuf) { +public fun ByteBuf.setBytesReverse(index: Int, src: ByteBuf): ByteBuf { val srcIndex = src.readerIndex() val len = src.readableBytes() setBytesReverse(index, src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } public fun ByteBuf.setBytesReverse( index: Int, src: ByteBuf, len: Int -) { +): ByteBuf { val srcIndex = src.readerIndex() setBytesReverse(index, src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } public fun ByteBuf.setBytesReverse( @@ -1079,53 +1175,60 @@ public fun ByteBuf.setBytesReverse( src: ByteBuf, srcIndex: Int, len: Int -) { +): ByteBuf { for (i in 0 until len) { setByte(index + i, src.getByte(srcIndex + len - i - 1).toInt()) } + return this } -public fun ByteBuf.writeBytesReverse(src: ByteArray) { +public fun ByteBuf.writeBytesReverse(src: ByteArray): ByteBuf { writeBytesReverse(src, 0, src.size) + return this } public fun ByteBuf.writeBytesReverse( src: ByteArray, srcIndex: Int, len: Int -) { +): ByteBuf { val index = writerIndex() ensureWritable(len) setBytesReverse(index, src, srcIndex, len) writerIndex(index + len) + return this } -public fun ByteBuf.writeBytesReverse(src: ByteBuf) { +public fun ByteBuf.writeBytesReverse(src: ByteBuf): ByteBuf { val srcIndex = src.readerIndex() val len = src.readableBytes() writeBytesReverse(src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } -public fun ByteBuf.writeBytesReverse(src: ByteBuf, len: Int) { +public fun ByteBuf.writeBytesReverse(src: ByteBuf, len: Int): ByteBuf { val srcIndex = src.readerIndex() writeBytesReverse(src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } public fun ByteBuf.writeBytesReverse( src: ByteBuf, srcIndex: Int, len: Int -) { +): ByteBuf { val index = writerIndex() ensureWritable(len) setBytesReverse(index, src, srcIndex, len) writerIndex(index + len) + return this } -public fun ByteBuf.getBytesReverseA(index: Int, dst: ByteArray) { +public fun ByteBuf.getBytesReverseA(index: Int, dst: ByteArray): ByteBuf { getBytesReverseA(index, dst, 0, dst.size) + return this } public fun ByteBuf.getBytesReverseA( @@ -1133,31 +1236,34 @@ public fun ByteBuf.getBytesReverseA( dst: ByteArray, dstIndex: Int, len: Int -) { +): ByteBuf { getBytes(index, dst, dstIndex, len) for (i in 0 until len) { dst[dstIndex + i] = (dst[dstIndex + i].toInt() - 128).toByte() } dst.reverse(dstIndex, dstIndex + len) + return this } -public fun ByteBuf.getBytesReverseA(index: Int, dst: ByteBuf) { +public fun ByteBuf.getBytesReverseA(index: Int, dst: ByteBuf): ByteBuf { val dstIndex = dst.writerIndex() val len = dst.writableBytes() dst.ensureWritable(len) getBytesReverseA(index, dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } public fun ByteBuf.getBytesReverseA( index: Int, dst: ByteBuf, len: Int -) { +): ByteBuf { val dstIndex = dst.writerIndex() dst.ensureWritable(len) getBytesReverseA(index, dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } public fun ByteBuf.getBytesReverseA( @@ -1165,49 +1271,55 @@ public fun ByteBuf.getBytesReverseA( dst: ByteBuf, dstIndex: Int, len: Int -) { +): ByteBuf { for (i in 0 until len) { dst.setByte(dstIndex + i, getByteA(index + len - i - 1).toInt()) } + return this } -public fun ByteBuf.readBytesReverseA(dst: ByteArray) { +public fun ByteBuf.readBytesReverseA(dst: ByteArray): ByteBuf { readBytesReverseA(dst, 0, dst.size) + return this } public fun ByteBuf.readBytesReverseA( dst: ByteArray, dstIndex: Int, len: Int -) { +): ByteBuf { val index = readerIndex() getBytesReverseA(index, dst, dstIndex, len) readerIndex(index + len) + return this } -public fun ByteBuf.readBytesReverseA(dst: ByteBuf) { +public fun ByteBuf.readBytesReverseA(dst: ByteBuf): ByteBuf { val dstIndex = dst.writerIndex() val len = dst.writableBytes() dst.ensureWritable(len) readBytesReverseA(dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } -public fun ByteBuf.readBytesReverseA(dst: ByteBuf, len: Int) { +public fun ByteBuf.readBytesReverseA(dst: ByteBuf, len: Int): ByteBuf { val dstIndex = dst.writerIndex() dst.ensureWritable(len) readBytesReverseA(dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } public fun ByteBuf.readBytesReverseA( dst: ByteBuf, dstIndex: Int, len: Int -) { +): ByteBuf { val index = readerIndex() getBytesReverseA(index, dst, dstIndex, len) readerIndex(index + len) + return this } public fun ByteBuf.readBytesReverseA(len: Int): ByteBuf { @@ -1220,8 +1332,9 @@ public fun ByteBuf.readBytesReverseA(len: Int): ByteBuf { } } -public fun ByteBuf.setBytesReverseA(index: Int, src: ByteArray) { +public fun ByteBuf.setBytesReverseA(index: Int, src: ByteArray): ByteBuf { setBytesReverseA(index, src, 0, src.size) + return this } public fun ByteBuf.setBytesReverseA( @@ -1229,27 +1342,30 @@ public fun ByteBuf.setBytesReverseA( src: ByteArray, srcIndex: Int, len: Int -) { +): ByteBuf { Unpooled.wrappedBuffer(src).use { buf -> setBytesReverseA(index, buf, srcIndex, len) } + return this } -public fun ByteBuf.setBytesReverseA(index: Int, src: ByteBuf) { +public fun ByteBuf.setBytesReverseA(index: Int, src: ByteBuf): ByteBuf { val srcIndex = src.readerIndex() val len = src.readableBytes() setBytesReverseA(index, src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } public fun ByteBuf.setBytesReverseA( index: Int, src: ByteBuf, len: Int -) { +): ByteBuf { val srcIndex = src.readerIndex() setBytesReverseA(index, src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } public fun ByteBuf.setBytesReverseA( @@ -1257,53 +1373,60 @@ public fun ByteBuf.setBytesReverseA( src: ByteBuf, srcIndex: Int, len: Int -) { +): ByteBuf { for (i in 0 until len) { setByteA(index + i, src.getByte(srcIndex + len - i - 1).toInt()) } + return this } -public fun ByteBuf.writeBytesReverseA(src: ByteArray) { +public fun ByteBuf.writeBytesReverseA(src: ByteArray): ByteBuf { writeBytesReverseA(src, 0, src.size) + return this } public fun ByteBuf.writeBytesReverseA( src: ByteArray, srcIndex: Int, len: Int -) { +): ByteBuf { val index = writerIndex() ensureWritable(len) setBytesReverseA(index, src, srcIndex, len) writerIndex(index + len) + return this } -public fun ByteBuf.writeBytesReverseA(src: ByteBuf) { +public fun ByteBuf.writeBytesReverseA(src: ByteBuf): ByteBuf { val srcIndex = src.readerIndex() val len = src.readableBytes() writeBytesReverseA(src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } -public fun ByteBuf.writeBytesReverseA(src: ByteBuf, len: Int) { +public fun ByteBuf.writeBytesReverseA(src: ByteBuf, len: Int): ByteBuf { val srcIndex = src.readerIndex() writeBytesReverseA(src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } public fun ByteBuf.writeBytesReverseA( src: ByteBuf, srcIndex: Int, len: Int -) { +): ByteBuf { val index = writerIndex() ensureWritable(len) setBytesReverseA(index, src, srcIndex, len) writerIndex(index + len) + return this } -public fun ByteBuf.getBytesReverseC(index: Int, dst: ByteArray) { +public fun ByteBuf.getBytesReverseC(index: Int, dst: ByteArray): ByteBuf { getBytesReverseC(index, dst, 0, dst.size) + return this } public fun ByteBuf.getBytesReverseC( @@ -1311,31 +1434,34 @@ public fun ByteBuf.getBytesReverseC( dst: ByteArray, dstIndex: Int, len: Int -) { +): ByteBuf { getBytes(index, dst, dstIndex, len) for (i in 0 until len) { dst[dstIndex + i] = (-dst[dstIndex + i].toInt()).toByte() } dst.reverse(dstIndex, dstIndex + len) + return this } -public fun ByteBuf.getBytesReverseC(index: Int, dst: ByteBuf) { +public fun ByteBuf.getBytesReverseC(index: Int, dst: ByteBuf): ByteBuf { val dstIndex = dst.writerIndex() val len = dst.writableBytes() dst.ensureWritable(len) getBytesReverseC(index, dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } public fun ByteBuf.getBytesReverseC( index: Int, dst: ByteBuf, len: Int -) { +): ByteBuf { val dstIndex = dst.writerIndex() dst.ensureWritable(len) getBytesReverseC(index, dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } public fun ByteBuf.getBytesReverseC( @@ -1343,49 +1469,55 @@ public fun ByteBuf.getBytesReverseC( dst: ByteBuf, dstIndex: Int, len: Int -) { +): ByteBuf { for (i in 0 until len) { dst.setByte(dstIndex + i, getByteC(index + len - i - 1).toInt()) } + return this } -public fun ByteBuf.readBytesReverseC(dst: ByteArray) { +public fun ByteBuf.readBytesReverseC(dst: ByteArray): ByteBuf { readBytesReverseC(dst, 0, dst.size) + return this } public fun ByteBuf.readBytesReverseC( dst: ByteArray, dstIndex: Int, len: Int -) { +): ByteBuf { val index = readerIndex() getBytesReverseC(index, dst, dstIndex, len) readerIndex(index + len) + return this } -public fun ByteBuf.readBytesReverseC(dst: ByteBuf) { +public fun ByteBuf.readBytesReverseC(dst: ByteBuf): ByteBuf { val dstIndex = dst.writerIndex() val len = dst.writableBytes() dst.ensureWritable(len) readBytesReverseC(dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } -public fun ByteBuf.readBytesReverseC(dst: ByteBuf, len: Int) { +public fun ByteBuf.readBytesReverseC(dst: ByteBuf, len: Int): ByteBuf { val dstIndex = dst.writerIndex() dst.ensureWritable(len) readBytesReverseC(dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } public fun ByteBuf.readBytesReverseC( dst: ByteBuf, dstIndex: Int, len: Int -) { +): ByteBuf { val index = readerIndex() getBytesReverseC(index, dst, dstIndex, len) readerIndex(index + len) + return this } public fun ByteBuf.readBytesReverseC(len: Int): ByteBuf { @@ -1398,8 +1530,9 @@ public fun ByteBuf.readBytesReverseC(len: Int): ByteBuf { } } -public fun ByteBuf.setBytesReverseC(index: Int, src: ByteArray) { +public fun ByteBuf.setBytesReverseC(index: Int, src: ByteArray): ByteBuf { setBytesReverseC(index, src, 0, src.size) + return this } public fun ByteBuf.setBytesReverseC( @@ -1407,27 +1540,30 @@ public fun ByteBuf.setBytesReverseC( src: ByteArray, srcIndex: Int, len: Int -) { +): ByteBuf { Unpooled.wrappedBuffer(src).use { buf -> setBytesReverseC(index, buf, srcIndex, len) } + return this } -public fun ByteBuf.setBytesReverseC(index: Int, src: ByteBuf) { +public fun ByteBuf.setBytesReverseC(index: Int, src: ByteBuf): ByteBuf { val srcIndex = src.readerIndex() val len = src.readableBytes() setBytesReverseC(index, src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } public fun ByteBuf.setBytesReverseC( index: Int, src: ByteBuf, len: Int -) { +): ByteBuf { val srcIndex = src.readerIndex() setBytesReverseC(index, src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } public fun ByteBuf.setBytesReverseC( @@ -1435,53 +1571,60 @@ public fun ByteBuf.setBytesReverseC( src: ByteBuf, srcIndex: Int, len: Int -) { +): ByteBuf { for (i in 0 until len) { setByteC(index + i, src.getByte(srcIndex + len - i - 1).toInt()) } + return this } -public fun ByteBuf.writeBytesReverseC(src: ByteArray) { +public fun ByteBuf.writeBytesReverseC(src: ByteArray): ByteBuf { writeBytesReverseC(src, 0, src.size) + return this } public fun ByteBuf.writeBytesReverseC( src: ByteArray, srcIndex: Int, len: Int -) { +): ByteBuf { val index = writerIndex() ensureWritable(len) setBytesReverseC(index, src, srcIndex, len) writerIndex(index + len) + return this } -public fun ByteBuf.writeBytesReverseC(src: ByteBuf) { +public fun ByteBuf.writeBytesReverseC(src: ByteBuf): ByteBuf { val srcIndex = src.readerIndex() val len = src.readableBytes() writeBytesReverseC(src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } -public fun ByteBuf.writeBytesReverseC(src: ByteBuf, len: Int) { +public fun ByteBuf.writeBytesReverseC(src: ByteBuf, len: Int): ByteBuf { val srcIndex = src.readerIndex() writeBytesReverseC(src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } public fun ByteBuf.writeBytesReverseC( src: ByteBuf, srcIndex: Int, len: Int -) { +): ByteBuf { val index = writerIndex() ensureWritable(len) setBytesReverseC(index, src, srcIndex, len) writerIndex(index + len) + return this } -public fun ByteBuf.getBytesReverseS(index: Int, dst: ByteArray) { +public fun ByteBuf.getBytesReverseS(index: Int, dst: ByteArray): ByteBuf { getBytesReverseS(index, dst, 0, dst.size) + return this } public fun ByteBuf.getBytesReverseS( @@ -1489,31 +1632,34 @@ public fun ByteBuf.getBytesReverseS( dst: ByteArray, dstIndex: Int, len: Int -) { +): ByteBuf { getBytes(index, dst, dstIndex, len) for (i in 0 until len) { dst[dstIndex + i] = (128 - dst[dstIndex + i].toInt()).toByte() } dst.reverse(dstIndex, dstIndex + len) + return this } -public fun ByteBuf.getBytesReverseS(index: Int, dst: ByteBuf) { +public fun ByteBuf.getBytesReverseS(index: Int, dst: ByteBuf): ByteBuf { val dstIndex = dst.writerIndex() val len = dst.writableBytes() dst.ensureWritable(len) getBytesReverseS(index, dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } public fun ByteBuf.getBytesReverseS( index: Int, dst: ByteBuf, len: Int -) { +): ByteBuf { val dstIndex = dst.writerIndex() dst.ensureWritable(len) getBytesReverseS(index, dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } public fun ByteBuf.getBytesReverseS( @@ -1521,49 +1667,55 @@ public fun ByteBuf.getBytesReverseS( dst: ByteBuf, dstIndex: Int, len: Int -) { +): ByteBuf { for (i in 0 until len) { dst.setByte(dstIndex + i, getByteS(index + len - i - 1).toInt()) } + return this } -public fun ByteBuf.readBytesReverseS(dst: ByteArray) { +public fun ByteBuf.readBytesReverseS(dst: ByteArray): ByteBuf { readBytesReverseS(dst, 0, dst.size) + return this } public fun ByteBuf.readBytesReverseS( dst: ByteArray, dstIndex: Int, len: Int -) { +): ByteBuf { val index = readerIndex() getBytesReverseS(index, dst, dstIndex, len) readerIndex(index + len) + return this } -public fun ByteBuf.readBytesReverseS(dst: ByteBuf) { +public fun ByteBuf.readBytesReverseS(dst: ByteBuf): ByteBuf { val dstIndex = dst.writerIndex() val len = dst.writableBytes() dst.ensureWritable(len) readBytesReverseS(dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } -public fun ByteBuf.readBytesReverseS(dst: ByteBuf, len: Int) { +public fun ByteBuf.readBytesReverseS(dst: ByteBuf, len: Int): ByteBuf { val dstIndex = dst.writerIndex() dst.ensureWritable(len) readBytesReverseS(dst, dstIndex, len) dst.writerIndex(dstIndex + len) + return this } public fun ByteBuf.readBytesReverseS( dst: ByteBuf, dstIndex: Int, len: Int -) { +): ByteBuf { val index = readerIndex() getBytesReverseS(index, dst, dstIndex, len) readerIndex(index + len) + return this } public fun ByteBuf.readBytesReverseS(len: Int): ByteBuf { @@ -1576,8 +1728,9 @@ public fun ByteBuf.readBytesReverseS(len: Int): ByteBuf { } } -public fun ByteBuf.setBytesReverseS(index: Int, src: ByteArray) { +public fun ByteBuf.setBytesReverseS(index: Int, src: ByteArray): ByteBuf { setBytesReverseS(index, src, 0, src.size) + return this } public fun ByteBuf.setBytesReverseS( @@ -1585,27 +1738,30 @@ public fun ByteBuf.setBytesReverseS( src: ByteArray, srcIndex: Int, len: Int -) { +): ByteBuf { Unpooled.wrappedBuffer(src).use { buf -> setBytesReverseS(index, buf, srcIndex, len) } + return this } -public fun ByteBuf.setBytesReverseS(index: Int, src: ByteBuf) { +public fun ByteBuf.setBytesReverseS(index: Int, src: ByteBuf): ByteBuf { val srcIndex = src.readerIndex() val len = src.readableBytes() setBytesReverseS(index, src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } public fun ByteBuf.setBytesReverseS( index: Int, src: ByteBuf, len: Int -) { +): ByteBuf { val srcIndex = src.readerIndex() setBytesReverseS(index, src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } public fun ByteBuf.setBytesReverseS( @@ -1613,107 +1769,119 @@ public fun ByteBuf.setBytesReverseS( src: ByteBuf, srcIndex: Int, len: Int -) { +): ByteBuf { for (i in 0 until len) { setByteS(index + i, src.getByte(srcIndex + len - i - 1).toInt()) } + return this } -public fun ByteBuf.writeBytesReverseS(src: ByteArray) { +public fun ByteBuf.writeBytesReverseS(src: ByteArray): ByteBuf { writeBytesReverseS(src, 0, src.size) + return this } public fun ByteBuf.writeBytesReverseS( src: ByteArray, srcIndex: Int, len: Int -) { +): ByteBuf { val index = writerIndex() ensureWritable(len) setBytesReverseS(index, src, srcIndex, len) writerIndex(index + len) + return this } -public fun ByteBuf.writeBytesReverseS(src: ByteBuf) { +public fun ByteBuf.writeBytesReverseS(src: ByteBuf): ByteBuf { val srcIndex = src.readerIndex() val len = src.readableBytes() writeBytesReverseS(src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } -public fun ByteBuf.writeBytesReverseS(src: ByteBuf, len: Int) { +public fun ByteBuf.writeBytesReverseS(src: ByteBuf, len: Int): ByteBuf { val srcIndex = src.readerIndex() writeBytesReverseS(src, srcIndex, len) src.readerIndex(srcIndex + len) + return this } public fun ByteBuf.writeBytesReverseS( src: ByteBuf, srcIndex: Int, len: Int -) { +): ByteBuf { val index = writerIndex() ensureWritable(len) setBytesReverseS(index, src, srcIndex, len) writerIndex(index + len) + return this } public fun ByteBuf.getBooleanA(index: Int): Boolean = getByteA(index).toInt() != 0 public fun ByteBuf.readBooleanA(): Boolean = readByteA().toInt() != 0 -public fun ByteBuf.setBooleanA(index: Int, `value`: Boolean) { +public fun ByteBuf.setBooleanA(index: Int, `value`: Boolean): ByteBuf { if (value) { setByteA(index, 1) } else { setByteA(index, 0) } + return this } -public fun ByteBuf.writeBooleanA(`value`: Boolean) { +public fun ByteBuf.writeBooleanA(`value`: Boolean): ByteBuf { if (value) { writeByteA(1) } else { writeByteA(0) } + return this } public fun ByteBuf.getBooleanC(index: Int): Boolean = getByteC(index).toInt() != 0 public fun ByteBuf.readBooleanC(): Boolean = readByteC().toInt() != 0 -public fun ByteBuf.setBooleanC(index: Int, `value`: Boolean) { +public fun ByteBuf.setBooleanC(index: Int, `value`: Boolean): ByteBuf { if (value) { setByteC(index, 1) } else { setByteC(index, 0) } + return this } -public fun ByteBuf.writeBooleanC(`value`: Boolean) { +public fun ByteBuf.writeBooleanC(`value`: Boolean): ByteBuf { if (value) { writeByteC(1) } else { writeByteC(0) } + return this } public fun ByteBuf.getBooleanS(index: Int): Boolean = getByteS(index).toInt() != 0 public fun ByteBuf.readBooleanS(): Boolean = readByteS().toInt() != 0 -public fun ByteBuf.setBooleanS(index: Int, `value`: Boolean) { +public fun ByteBuf.setBooleanS(index: Int, `value`: Boolean): ByteBuf { if (value) { setByteS(index, 1) } else { setByteS(index, 0) } + return this } -public fun ByteBuf.writeBooleanS(`value`: Boolean) { +public fun ByteBuf.writeBooleanS(`value`: Boolean): ByteBuf { if (value) { writeByteS(1) } else { writeByteS(0) } + return this }