Skip to content

Commit

Permalink
Add information about current codec into decode context
Browse files Browse the repository at this point in the history
  • Loading branch information
OptimumCode committed May 20, 2024
1 parent 6a750fd commit 2d3a6f4
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ enum class ValueType(val codec: ValueCodec<*>) {
class DecodeContext private constructor(
internal val batchInfoProvider: BatchInfoProvider
) {
internal lateinit var currentCodec: ValueCodec<*>
companion object {
private val DEFAULT = DecodeContext(BatchInfoProvider.Empty)
@JvmStatic
Expand Down Expand Up @@ -112,6 +113,7 @@ abstract class AbstractCodec<T>(final override val type: UByte) : ValueCodec<T>
protected abstract fun write(buffer: ByteBuf, value: T)

override fun decode(context: DecodeContext, source: ByteBuf): T {
context.currentCodec = this
val tag = source.readByte().toUByte()
check(tag == this.type) { "Unexpected type tag: $tag (expected: ${this.type})" }
val length = source.readIntLE()
Expand Down Expand Up @@ -425,7 +427,7 @@ private inline fun ByteBuf.forEachValue(context: DecodeContext, action: (codec:

when (val codec = ValueType.forId(type).codec) {
is UnknownValueCodec -> LOGGER.warn {
"Skipping unknown type $type value: ${
"Skipping unknown type $type when decoding with ${context.currentCodec::class.simpleName} value: ${
ByteBufUtil.hexDump(
codec.decode(
context,
Expand Down

0 comments on commit 2d3a6f4

Please sign in to comment.