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

Commit 51f637b

Browse files
committed
add RecursiveStreamCodec
1 parent 334de64 commit 51f637b

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
kotlin.code.style=official
2-
tide.version=3.0
2+
tide.version=3.2
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.github.dockyardmc.tide.stream
2+
3+
import io.netty.buffer.ByteBuf
4+
5+
class RecursiveStreamCodec<T>(self: (StreamCodec<T>) -> StreamCodec<T>) : StreamCodec<T> {
6+
7+
val delegate = self.invoke(this)
8+
9+
override fun write(buffer: ByteBuf, value: T) {
10+
delegate.write(buffer, value)
11+
}
12+
13+
override fun read(buffer: ByteBuf): T {
14+
return delegate.read(buffer)
15+
}
16+
17+
}

src/main/kotlin/io/github/dockyardmc/tide/stream/StreamCodec.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.github.dockyardmc.tide.stream
22

3+
import io.github.dockyardmc.tide.codec.Codec
34
import io.github.dockyardmc.tide.codec.CodecUtils
5+
import io.github.dockyardmc.tide.codec.RecursiveCodec
46
import io.netty.buffer.ByteBuf
57
import java.util.*
68

@@ -28,6 +30,7 @@ interface StreamCodec<T> {
2830
return ListStreamCodec<T>(this)
2931
}
3032

33+
3134
companion object {
3235
val UNIT = object : StreamCodec<Unit> {
3336

@@ -173,6 +176,10 @@ interface StreamCodec<T> {
173176
val leastSignificant = LONG.read(buffer)
174177
return UUID(mostSignificant, leastSignificant)
175178
}
179+
180+
fun <T> recursive(self: (StreamCodec<T>) -> StreamCodec<T>): RecursiveStreamCodec<T> {
181+
return RecursiveStreamCodec<T>(self)
182+
}
176183
}
177184

178185
val UUID_STRING = STRING.transform<UUID>({ uuid -> uuid.toString() }, { string -> java.util.UUID.fromString(string) })

0 commit comments

Comments
 (0)