Skip to content

Commit

Permalink
Updated javadocs
Browse files Browse the repository at this point in the history
  • Loading branch information
sksamuel committed May 5, 2024
1 parent deda350 commit 8203132
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,30 @@ import com.sksamuel.centurion.avro.generation.ReflectionSchemaBuilder
import kotlin.reflect.KClass

/**
* A [ReflectionSerdeFactory] will create a [SpecificSerde] for any given type using reflection based builders.
* A [ReflectionSerdeFactory] will create a [SpecificSerde] for a given type using
* reflection based builders.
*
* This instance is thread safe.
*/
object ReflectionSerdeFactory {

/**
* Creates a [SpecificSerde] reflectively from the given [kclass] using a [ReflectionSchemaBuilder].
* Creates a [SpecificSerde] reflectively from the given [kclass] using a [ReflectionSchemaBuilder],
* [SpecificRecordEncoder] and [SpecificRecordDecoder].
*/
fun <T : Any> create(
kclass: KClass<T>,
options: SerdeOptions = SerdeOptions()
): SpecificSerde<T> {
val schema = ReflectionSchemaBuilder(true).schema(kclass)
val encoder = SpecificRecordEncoder(kclass)
val decoder: SpecificRecordDecoder<T> = SpecificRecordDecoder(kclass)
val decoder = SpecificRecordDecoder(kclass)
return SpecificSerde(schema, encoder, decoder, options)
}

/**
* Creates a [SpecificSerde] reflectively from the given type parameter [T] using a [ReflectionSchemaBuilder].
* Creates a [SpecificSerde] reflectively from the given type parameter [T] using a [ReflectionSchemaBuilder],
* [SpecificRecordEncoder] and [SpecificRecordDecoder].
*/
inline fun <reified T : Any> create(options: SerdeOptions = SerdeOptions()): SpecificSerde<T> {
return create(T::class, options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ import org.apache.avro.file.Codec
import java.nio.ByteBuffer

/**
* A [Serde] provides an easy way to convert between a data class [T] and avro encoded bytes.
* A [Serde] provides an easy way to convert between a single data class instance [T]
* and avro encoded byte arrays.
*/
interface Serde<T : Any> {
fun serialize(obj: T): ByteArray
fun deserialize(bytes: ByteArray): T
}

/**
* A [CompressingSerde] wraps another [Serde] applying compression after serialization,
* and applying decompression before deserialization.
*
* Note: Compression is not super effective on objects with low repeatabilty of strings.
*/
class CompressingSerde<T : Any>(private val codec: Codec, private val serde: Serde<T>) : Serde<T> {

override fun serialize(obj: T): ByteArray {
Expand Down

0 comments on commit 8203132

Please sign in to comment.