Skip to content

Commit

Permalink
refactor: rework direct decoding for more clear & compact resolving u…
Browse files Browse the repository at this point in the history
…nions
  • Loading branch information
Chuckame committed Sep 17, 2024
1 parent 6e8d555 commit ef9d446
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 353 deletions.
11 changes: 11 additions & 0 deletions src/main/kotlin/com/github/avrokotlin/avro4k/AvroDecoder.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.avrokotlin.avro4k

import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.SerializationException
import kotlinx.serialization.encoding.Decoder
import org.apache.avro.Schema
import org.apache.avro.generic.GenericFixed
Expand Down Expand Up @@ -317,4 +318,14 @@ internal inline fun <T : Any> AvroDecoder.findValueDecoder(
resolver(schema)
}
return foundResolver ?: throw error()
}

internal fun AvroDecoder.unsupportedWriterTypeError(
mainType: Schema.Type,
vararg fallbackTypes: Schema.Type,
): Throwable {
val fallbacksStr = if (fallbackTypes.isNotEmpty()) ", and also not matching to any compatible type (one of ${fallbackTypes.joinToString()})." else ""
return SerializationException(
"Unsupported schema '${currentWriterSchema.fullName}' for decoded type of ${mainType.getName()}$fallbacksStr. Actual schema: $currentWriterSchema"
)
}
Loading

0 comments on commit ef9d446

Please sign in to comment.