Table of Contents

Interface IBinaryComponentSerializer

Namespace
KeenEyes.Serialization
Assembly
KeenEyes.Core.dll

Interface for AOT-compatible binary component serialization.

public interface IBinaryComponentSerializer

Examples

// Use generated serializer for binary serialization
var serializer = new ComponentSerializer();
var binary = SnapshotManager.ToBinary(snapshot, serializer);
var restored = SnapshotManager.FromBinary(binary, serializer);

Remarks

This interface extends serialization capabilities to support efficient binary formats. It is implemented by generated code when components are marked with [Component(Serializable = true)]. The source generator creates a strongly-typed implementation that avoids runtime reflection.

Binary serialization provides significant performance and size benefits over JSON:

  • Smaller file sizes (typically 50-80% reduction)
  • Faster serialization/deserialization
  • No string parsing overhead

Methods

ReadFrom(string, BinaryReader)

Reads a component from a binary reader.

object? ReadFrom(string typeName, BinaryReader reader)

Parameters

typeName string

The fully-qualified type name of the component.

reader BinaryReader

The binary reader to read from.

Returns

object

The deserialized component, or null if the type is not registered.

WriteTo(Type, object, BinaryWriter)

Writes a component to a binary writer.

bool WriteTo(Type type, object value, BinaryWriter writer)

Parameters

type Type

The type of the component.

value object

The component value to serialize.

writer BinaryWriter

The binary writer to write to.

Returns

bool

True if the component was serialized; false if the type is not registered.