Class SpanEventSerializer
- Namespace
- Excalibur.Dispatch.Serialization
- Assembly
- Excalibur.Dispatch.dll
Event serializer implementation using the pluggable serialization infrastructure.
public sealed class SpanEventSerializer : IEventSerializer
- Inheritance
-
SpanEventSerializer
- Implements
- Inherited Members
- Extension Methods
Remarks
This serializer implements IEventSerializer by delegating to the configured ISerializer (the current/default serializer, typically JSON).
Constructors
SpanEventSerializer(ISerializer)
Initializes a new instance of SpanEventSerializer using the specified pluggable serializer.
public SpanEventSerializer(ISerializer pluggable)
Parameters
pluggableISerializerThe underlying pluggable serializer (typically MemoryPack).
Exceptions
- ArgumentNullException
Thrown when pluggable is null.
SpanEventSerializer(ISerializerRegistry)
Initializes a new instance of SpanEventSerializer using the registry to obtain the MemoryPack serializer.
public SpanEventSerializer(ISerializerRegistry registry)
Parameters
registryISerializerRegistryThe serializer registry.
Exceptions
- ArgumentNullException
Thrown when registry is null.
- InvalidOperationException
Thrown when no serializer is available.
Methods
DeserializeEvent(byte[], Type)
Deserializes an event from bytes.
public IDomainEvent DeserializeEvent(byte[] data, Type eventType)
Parameters
Returns
- IDomainEvent
The deserialized event.
DeserializeEvent(ReadOnlySpan<byte>, Type)
Deserializes an event from a read-only span (zero-copy).
[RequiresDynamicCode("Deserialization of events requires dynamic code generation for type inspection")]
[RequiresUnreferencedCode("Deserialization may reference types not preserved during trimming")]
public IDomainEvent DeserializeEvent(ReadOnlySpan<byte> data, Type eventType)
Parameters
dataReadOnlySpan<byte>eventTypeType
Returns
DeserializeSnapshot(ReadOnlySpan<byte>, Type)
Deserializes a snapshot from a read-only span (zero-copy).
[RequiresDynamicCode("Deserialization of snapshots requires dynamic code generation for type inspection")]
[RequiresUnreferencedCode("Deserialization may reference types not preserved during trimming")]
public object DeserializeSnapshot(ReadOnlySpan<byte> data, Type snapshotType)
Parameters
dataReadOnlySpan<byte>snapshotTypeType
Returns
GetSnapshotSize(object)
Gets the required buffer size for serializing a snapshot.
[RequiresDynamicCode("Size calculation may require dynamic code generation")]
[RequiresUnreferencedCode("Size calculation may reference types not preserved during trimming")]
public int GetSnapshotSize(object snapshot)
Parameters
snapshotobject
Returns
GetTypeName(Type)
Gets the type name for serialization.
public string GetTypeName(Type type)
Parameters
typeTypeThe type to get the name for.
Returns
- string
Type name for storage.
ResolveType(string)
Resolves a type from its stored name.
public Type ResolveType(string typeName)
Parameters
typeNamestringThe stored type name.
Returns
- Type
The resolved type.
SerializeEvent(IDomainEvent)
Serializes an event to bytes.
public byte[] SerializeEvent(IDomainEvent domainEvent)
Parameters
domainEventIDomainEventThe event to serialize.
Returns
- byte[]
Serialized event data.
SerializeSnapshot(object, Span<byte>)
Serializes a snapshot to a caller-provided span buffer.
[RequiresDynamicCode("Serialization of snapshots requires dynamic code generation for type inspection")]
[RequiresUnreferencedCode("Serialization may reference types not preserved during trimming")]
public int SerializeSnapshot(object snapshot, Span<byte> buffer)