Skip to content

Commit

Permalink
Added variant to SpecificRecordDecoder
Browse files Browse the repository at this point in the history
  • Loading branch information
sksamuel committed Apr 27, 2024
1 parent 187e831 commit 6a8bc5d
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ class SpecificRecordDecoder<T : Any>(
override fun decode(schema: Schema, value: Any?): T {
if (value == null) error("SpecificRecordDecoder does not support null types")
require(value is GenericRecord) { "SpecificRecordDecoder only supports GenericRecords: was $value" }
return decode(value)
}

fun decode(record: GenericRecord): T {
val args = members.map { (pos, field, decoder) ->
val arg = value.get(pos)
val arg = record.get(pos)
decoder.decode(field.schema(), arg)
}
return constructor.call(*args.toTypedArray())
Expand Down

0 comments on commit 6a8bc5d

Please sign in to comment.