This repository was archived by the owner on Nov 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +40
-1
lines changed
src/main/kotlin/io/github/dockyardmc/tide/stream Expand file tree Collapse file tree 3 files changed +40
-1
lines changed Original file line number Diff line number Diff line change 11kotlin.code.style =official
2- tide.version =3.7
2+ tide.version =3.8
Original file line number Diff line number Diff line change @@ -32,6 +32,9 @@ interface StreamCodec<T> {
3232 return UnionStreamCodec (this , keyFunc, serializers)
3333 }
3434
35+ fun wrapped (): WrappedStreamCodec <T > {
36+ return WrappedStreamCodec <T >(this )
37+ }
3538
3639 companion object {
3740 val UNIT = object : StreamCodec <Unit > {
@@ -180,6 +183,23 @@ interface StreamCodec<T> {
180183 }
181184 }
182185
186+ val LONG_ARRAY = object : StreamCodec <LongArray > {
187+
188+ override fun write (buffer : ByteBuf , value : LongArray ) {
189+ VAR_INT .write(buffer, value.size)
190+ value.forEach { long -> buffer.writeLong(long) }
191+ }
192+
193+ override fun read (buffer : ByteBuf ): LongArray {
194+ val size = VAR_INT .read(buffer)
195+ val longs = mutableListOf<Long >()
196+ for (i in 0 until size) {
197+ longs.add(buffer.readLong())
198+ }
199+ return longs.toLongArray()
200+ }
201+ }
202+
183203 fun <T > recursive (self : (StreamCodec <T >) -> StreamCodec <T >): RecursiveStreamCodec <T > {
184204 return RecursiveStreamCodec <T >(self)
185205 }
Original file line number Diff line number Diff line change 1+ package io.github.dockyardmc.tide.stream
2+
3+ import io.netty.buffer.ByteBuf
4+ import io.netty.buffer.Unpooled
5+
6+ class WrappedStreamCodec <T >(val inner : StreamCodec <T >) : StreamCodec<T> {
7+
8+ override fun write (buffer : ByteBuf , value : T ) {
9+ val innerBuffer = Unpooled .buffer()
10+ inner.write(innerBuffer, value)
11+ StreamCodec .BYTE_ARRAY .write(buffer, innerBuffer)
12+ }
13+
14+ override fun read (buffer : ByteBuf ): T {
15+ val innerBuffer = StreamCodec .BYTE_ARRAY .read(buffer)
16+ return inner.read(innerBuffer)
17+ }
18+
19+ }
You can’t perform that action at this time.
0 commit comments