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
typeNamestringThe fully-qualified type name of the component.
readerBinaryReaderThe 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
typeTypeThe type of the component.
valueobjectThe component value to serialize.
writerBinaryWriterThe binary writer to write to.
Returns
- bool
True if the component was serialized; false if the type is not registered.