Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Commit 2d323d3

Browse files
committed
get rid of Buffer object with just one method
1 parent e6d2323 commit 2d323d3

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/main/kotlin/io/github/dockyardmc/data/DataComponentPatch.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class DataComponentPatch(internal val components: Int2ObjectMap<DataComponent?>,
211211
entry.value!!.write(buffer)
212212
} else {
213213
// Need to length prefix it, so write to another buffer first then copy.
214-
val componentData = Buffer.makeArray { b -> entry.value!!.write(b) }
214+
val componentData = byteBufBytes { b -> entry.value!!.write(b) }
215215
buffer.writeByteArray(componentData)
216216
}
217217
}

src/main/kotlin/io/github/dockyardmc/extentions/ExtendedByteBuf.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,10 @@ fun ByteBuf.writeVarIntArray(array: List<Int>) {
7575
array.forEach { this.writeVarInt(it) }
7676
}
7777

78-
object Buffer {
79-
fun makeArray(writer: (ByteBuf) -> Unit): ByteArray {
80-
val tempBuffer = Unpooled.buffer()
81-
writer.invoke(tempBuffer)
82-
return tempBuffer.array()
83-
}
78+
inline fun byteBufBytes(writer: (ByteBuf) -> Unit): ByteArray {
79+
val tempBuffer = Unpooled.buffer()
80+
writer.invoke(tempBuffer)
81+
return tempBuffer.array()
8482
}
8583

8684
fun ByteBuf.writeLongArray(array: List<Long>) {

0 commit comments

Comments
 (0)