FateSchema

sealed interface FateSchema<T>

Core interface for defining serialization schemas in the FateWeaver logging system.

FateSchema provides a type-safe, efficient binary serialization framework with the following features:

  • Type Safety: Each schema is parameterized with the specific type it can serialize

  • Self-Describing: Schemas embed their own structure information for compatibility

  • Efficient Encoding: Optimized binary format with minimal overhead

  • Schema Evolution: Version-aware serialization for backward compatibility

  • Extensible: Support for primitive types, collections, enums, and custom classes

Schema Types

The system supports several categories of schemas:

Primitive Schemas

  • IntSchema: 32-bit signed integers

  • LongSchema: 64-bit signed integers

  • DoubleSchema: 64-bit floating point numbers

  • StringSchema: UTF-8 encoded strings with length prefix

  • BooleanSchema: Single-byte boolean values

Collection Schemas

  • ArraySchema<T>: Arrays of any supported type T

  • EnumSchema<T>: Enumeration types with ordinal encoding

Class Schemas

  • ReflectedClassSchema<T>: Automatic serialization via reflection

  • TypedClassSchema<T>: Reflection-based with embedded type information

  • CustomStructSchema<T>: User-defined serialization with custom encoders

Binary Format

Each schema defines both its metadata format and object encoding format:

Schema Encoding (written once per channel):

[4 bytes: tag] [schema-specific metadata...]

Object Encoding (written for each logged object):

[variable: object data as defined by schema]

Usage Example

// Automatic schema inference
val userSchema = FateSchema.schemaOfClass(User::class.java)

// Manual schema creation
val customSchema = CustomStructSchema<Person>(
type = "Person",
componentNames = listOf("name", "age"),
componentSchemas = listOf(StringSchema, IntSchema),
encoder = { person -> listOf(person.name, person.age) }
)

// Size calculation and encoding
val person = Person("Alice", 30)
val objSize = customSchema.objSize(person)
val buffer = ByteBuffer.allocate(objSize)
customSchema.encodeObject(buffer, person)

Parameters

T

The type of objects this schema can serialize and deserialize

Inheritors

Types

Link copied to clipboard
object Companion
Link copied to clipboard

Registry of all supported schema types with their unique tag values.

Properties

Link copied to clipboard
open val schema: ByteArray

The complete schema definition as a byte array.

Link copied to clipboard
abstract val schemaSize: Int

Number of bytes required to encode this schema's metadata.

Link copied to clipboard
abstract val tag: Int

Unique identifier for this schema type within the FateWeaver format.

Functions

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

Encodes the given object into the provided buffer.

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

Encodes this schema's metadata into the provided buffer.

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

Calculates the number of bytes required to encode the given object.