JavaOptionalSchema

class JavaOptionalSchema<T : Any>(val valueSchema: FateSchema<T>) : FateSchema<Optional<T>>

A schema for java.util.Optional, encoded exactly like OptionalSchema.

Optional<T> means the same as Kotlin's T?, so it has the same OPTIONAL tag and the same bytes. A reader cannot tell the two apart.

Optional<Double> infers from a declared property. The raw class has no type argument, so schemaOfClass(Optional::class.java) is rejected, the same as a raw Map.

A null Optional reference is rejected, not recorded as absent. Optional is never supposed to be null, so a null there is a bug.

Parameters

T

the value type when present

valueSchema

schema used to encode the value when it is present

Constructors

Link copied to clipboard
constructor(valueSchema: FateSchema<T>)

Properties

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

Functions

Link copied to clipboard
open override fun encodeObject(buffer: ByteBuffer, obj: Optional<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: Optional<T>): Int

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