Class TypeSerializerBase<T>
Abstract base class for strongly-typed serializers, implementing the bridge between the generic ITypeSerializer<T> contract and the non-generic ITypeSerializer contract required for runtime type dispatch.
Inheritance
Inherited Members
Namespace: Scylla.Core.Util.Serialization
Assembly: ScyllaCore.dll
Syntax
public abstract class TypeSerializerBase<T> : ITypeSerializer<T>, ITypeSerializer
Type Parameters
| Name | Description |
|---|---|
| T | The concrete type this serializer handles. All read and write operations are
expressed in terms of |
Remarks
Deriving from TypeSerializerBase<T> is the recommended approach for
implementing custom serializers. Subclasses only need to override
Write(T, IScyllaWriter, ISerializationContext) and Read(IScyllaReader, ISerializationContext); the non-generic
WriteObject(object, IScyllaWriter, ISerializationContext) and ReadObject(IScyllaReader, ISerializationContext) methods delegate to those
overrides automatically via an explicit cast, keeping boilerplate to a minimum.
Each built-in serializer (e.g., IntSerializer, Vector3Serializer) inherits from this class. Custom serializers registered via RegisterSerializer<T>(ITypeSerializer<T>) or RegisterSerializer<T>(ITypeSerializer<T>) typically do as well, though they may alternatively implement ITypeSerializer<T> directly and be wrapped in a TypeSerializerAdapter<T>.
Thread safety: instances of this class carry no mutable state; thread safety of
Write(T, IScyllaWriter, ISerializationContext) and Read(IScyllaReader, ISerializationContext) is the responsibility of the subclass.
The singleton Instance fields present on most built-in serializers are safe
to share across threads because those subclasses also carry no instance state.
Properties
TargetType
Gets the Type that this serializer is responsible for handling. The engine uses this value as the dictionary key when storing and retrieving serializers from its registry.
Declaration
public Type TargetType { get; }
Property Value
| Type | Description |
|---|---|
| Type | The exact Type this serializer handles. For
TypeSerializerAdapter<T>, this is always |
Methods
Read(IScyllaReader, ISerializationContext)
Reads and returns a value of type T from the specified reader.
Declaration
public abstract T Read(IScyllaReader reader, ISerializationContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| IScyllaReader | reader | The reader positioned at the start of the serialized value. Never |
| ISerializationContext | context | The active serialization context, providing depth tracking, reference tracking,
and access to SerializationSettings. Never |
Returns
| Type | Description |
|---|---|
| T | The deserialized value of type |
ReadObject(IScyllaReader, ISerializationContext)
Implements the non-generic ReadObject(IScyllaReader, ISerializationContext) contract by delegating to Read(IScyllaReader, ISerializationContext) and boxing the result as object.
Declaration
public object ReadObject(IScyllaReader reader, ISerializationContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| IScyllaReader | reader | The reader positioned at the start of the serialized value. Never |
| ISerializationContext | context | The active serialization context. Never |
Returns
| Type | Description |
|---|---|
| object | The deserialized value boxed as object. For value types this causes a heap allocation; prefer the generic Read(IScyllaReader, ISerializationContext) overload when the concrete type is known at the call site. |
Write(T, IScyllaWriter, ISerializationContext)
Writes a value of type T to the specified writer.
Declaration
public abstract 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 writer that receives the serialized output. Never |
| ISerializationContext | context | The active serialization context, providing depth tracking, reference tracking,
and access to SerializationSettings. Never |
WriteObject(object, IScyllaWriter, ISerializationContext)
Implements the non-generic WriteObject(object, IScyllaWriter, ISerializationContext) contract by
casting value to T and delegating to
Write(T, IScyllaWriter, ISerializationContext).
Declaration
public void WriteObject(object value, IScyllaWriter writer, ISerializationContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| object | value | The boxed or polymorphic value to serialize. Must be assignable to
|
| IScyllaWriter | writer | The writer that receives the serialized output. Never |
| ISerializationContext | context | The active serialization context. Never |