Interface ITypeSerializer<T>
Generic interface for custom type serialization handlers. Implement this interface
to provide complete, type-safe control over how a specific type T
is written to and read from a Scylla serialization format.
Namespace: Scylla.Core.Util.Serialization
Assembly: ScyllaCore.dll
Syntax
public interface ITypeSerializer<T>
Type Parameters
| Name | Description |
|---|---|
| T | The type this serializer handles. Can be any reference type, value type, or interface.
The serializer must be able to fully round-trip any valid instance of
|
Remarks
Custom type serializers bypass the reflection-based default serialization path entirely, giving full control over the wire format. This is the preferred extension point for:
-
Types that cannot be annotated with
[ScyllaSerializable](e.g., third-party or Unity types such asVector3,Color, orQuaternion). - Types requiring a compact or non-standard wire representation for performance or compatibility reasons.
- Types with constructor-only initialization patterns or private state that reflection cannot reach.
Register serializers globally via RegisterSerializer<T>(ITypeSerializer<T>), or limit them to a single operation via RegisterSerializer<T>(ITypeSerializer<T>). Per-operation registrations take priority over global ones when both exist for the same type.
When the engine needs to invoke the serializer at runtime it wraps it in a TypeSerializerAdapter<T>, which bridges the typed Write(T, IScyllaWriter, ISerializationContext) and Read(IScyllaReader, ISerializationContext) methods to the non-generic ITypeSerializer interface used internally.
public class Vector3Serializer : ITypeSerializer<Vector3>
{
public void Write(Vector3 value, IScyllaWriter writer, ISerializationContext context)
{
writer.WriteStartArray();
writer.WriteFloat(value.x);
writer.WriteFloat(value.y);
writer.WriteFloat(value.z);
writer.WriteEndArray();
}
public Vector3 Read(IScyllaReader reader, ISerializationContext context)
{
reader.ReadStartArray();
var x = reader.ReadFloat();
var y = reader.ReadFloat();
var z = reader.ReadFloat();
reader.ReadEndArray();
return new Vector3(x, y, z);
}
}
Methods
Read(IScyllaReader, ISerializationContext)
Reads and reconstructs a value of type T from
reader.
Declaration
T Read(IScyllaReader reader, ISerializationContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| IScyllaReader | reader | The format-specific reader positioned at the beginning of the serialized value
for |
| ISerializationContext | context | The active serialization context providing settings, depth tracking, and reference
tracking. Must not be |
Returns
| Type | Description |
|---|---|
| T | The deserialized value of type |
See Also
Write(T, IScyllaWriter, ISerializationContext)
Writes the strongly-typed value to writer
using this serializer's format-specific encoding.
Declaration
void Write(T value, IScyllaWriter writer, ISerializationContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | The value to serialize. For reference types this may be |
| IScyllaWriter | writer | The format-specific writer that receives the serialized output. Must not be
|
| ISerializationContext | context | The active serialization context. Use PushDepth()
and PopDepth() when recursively serializing
nested objects, and consult ReferenceTracker
when handling reference types that may participate in cycles. Must not be
|