FateSchema
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 integersLongSchema: 64-bit signed integersDoubleSchema: 64-bit floating point numbersStringSchema: UTF-8 encoded strings with length prefixBooleanSchema: Single-byte boolean values
Collection Schemas
ArraySchema<T>: Arrays of any supported type TEnumSchema<T>: Enumeration types with ordinal encoding
Class Schemas
ReflectedClassSchema<T>: Automatic serialization via reflectionTypedClassSchema<T>: Reflection-based with embedded type informationCustomStructSchema<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
The type of objects this schema can serialize and deserialize