TranslatedSchema

class TranslatedSchema<T : Any, U : Any>(val baseSchema: FateSchema<U>, val toBase: (T) -> U) : FateSchema<T>

A schema that converts a T to a U and encodes the result with baseSchema.

It reports the same tag and schema bytes as baseSchema, so readers see a U.

Parameters

baseSchema

The schema for U

toBase

Converts a T to a U

Constructors

Link copied to clipboard
constructor(baseClass: Class<U>, toBase: (T) -> U)

Creates a schema for baseClass by inference and uses it as the base schema.

constructor(baseSchema: FateSchema<U>, toBase: (T) -> U)

Properties

Link copied to clipboard
Link copied to clipboard
open override val schema: ByteArray

The schema definition as bytes, which the writer puts in the log.

Link copied to clipboard
open override val schemaSize: Int

Number of bytes in this schema's definition.

Link copied to clipboard
open override val tag: Int

The integer that identifies this schema's type in the log.

Link copied to clipboard
val toBase: (T) -> U

Functions

Link copied to clipboard
open override fun encodeObject(buffer: ByteBuffer, obj: T)

Writes the given object into the buffer.

Link copied to clipboard
open fun encodeSchema(buffer: ByteBuffer)

Writes the whole schema definition, starting with the tag, into the buffer.

Link copied to clipboard
open override fun objSize(obj: T): Int

Returns the number of bytes encodeObject writes for the given object.