Skip to content

Commit a977288

Browse files
authored
Merge pull request #69 from SLNE-Development/feat/add-encode-and-decode-methods-to-codec
✨ feat(codec): add encode and decode methods to AbstractCodec
2 parents a71f864 + ca985bb commit a977288

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
kotlin.code.style=official
22
kotlin.stdlib.default.dependency=false
33
org.gradle.parallel=true
4-
version=1.7.1
4+
version=1.8.0

surf-redis-api/api/surf-redis-api.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ public final class dev/slne/surf/redis/cache/SimpleSetRedisCache$DefaultImpls {
126126

127127
public abstract class dev/slne/surf/redis/codec/AbstractCodec : org/redisson/client/codec/BaseCodec {
128128
public fun <init> ()V
129+
public final fun decode (Lio/netty/buffer/ByteBuf;)Ljava/lang/Object;
130+
public final fun encode (Lio/netty/buffer/ByteBuf;Ljava/lang/Object;)V
129131
public fun getValueDecoder ()Lorg/redisson/client/protocol/Decoder;
130132
public fun getValueEncoder ()Lorg/redisson/client/protocol/Encoder;
131133
protected abstract fun read (Lio/netty/buffer/ByteBuf;)Ljava/lang/Object;

surf-redis-api/src/main/kotlin/dev/slne/surf/redis/codec/AbstractCodec.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,22 @@ abstract class AbstractCodec<T : Any> : BaseCodec() {
2828
}
2929
}
3030

31-
override fun getValueEncoder(): Encoder? {
31+
override fun getValueEncoder(): Encoder {
3232
return encoder
3333
}
3434

35-
override fun getValueDecoder(): Decoder<in Any>? {
35+
override fun getValueDecoder(): Decoder<in Any> {
3636
return decoder
3737
}
3838

3939
protected abstract fun write(buf: ByteBuf, value: T)
4040
protected abstract fun read(buf: ByteBuf): T
41+
42+
fun encode(buf: ByteBuf, value: T) {
43+
write(buf, value)
44+
}
45+
46+
fun decode(buf: ByteBuf): T {
47+
return read(buf)
48+
}
4149
}

0 commit comments

Comments
 (0)