Table of Contents

Class AvroSerializer

Namespace
Excalibur.Dispatch.Serialization.Avro
Assembly
Excalibur.Dispatch.Serialization.Avro.dll

Apache Avro implementation of ISerializer.

[RequiresUnreferencedCode("Apache.Avro uses runtime schema compilation. AvroSerializer uses Activator.CreateInstance for ISpecificRecord deserialization.")]
[RequiresDynamicCode("Apache.Avro uses runtime schema compilation. AvroSerializer uses Activator.CreateInstance which requires dynamic code generation.")]
public sealed class AvroSerializer : ISerializer
Inheritance
AvroSerializer
Implements
Inherited Members
Extension Methods

Remarks

Schema-based binary serializer optimized for streaming and Kafka scenarios. Types must implement Avro.Specific.ISpecificRecord for Avro schema support.

Serializer ID: Avro (5)

Constraint: Types must implement Avro.Specific.ISpecificRecord. Runtime checks enforce this since ISerializer uses unconstrained generics.

Constructors

AvroSerializer()

Initializes a new instance with default options.

public AvroSerializer()

Properties

ContentType

Gets the IANA content type for this serializer (e.g., "application/json", "application/x-msgpack").

public string ContentType { get; }

Property Value

string

Remarks

Used for ASP.NET Core content negotiation via Accept and Content-Type headers.

Name

Gets the unique name of this serializer (e.g., "MemoryPack", "System.Text.Json", "MessagePack").

public string Name { get; }

Property Value

string

Remarks

This name is used for serializer lookup by name via ISerializerRegistry. The name should remain constant across versions for compatibility.

Version

Gets the version of the serializer library (e.g., "2.1.0").

public string Version { get; }

Property Value

string

Remarks

Used for diagnostics and migration scenarios. This is the version of the underlying serialization library, not a format version.

Methods

DeserializeObject(ReadOnlySpan<byte>, Type)

Deserializes a runtime-typed value from bytes.

public object DeserializeObject(ReadOnlySpan<byte> data, Type type)

Parameters

data ReadOnlySpan<byte>

The byte span containing serialized data.

type Type

The runtime type to deserialize to.

Returns

object

The deserialized object.

Exceptions

ArgumentNullException

Thrown when type is null.

SerializationException

Thrown when deserialization fails.

Deserialize<T>(ReadOnlySpan<byte>)

Deserializes a value from a contiguous byte span.

public T Deserialize<T>(ReadOnlySpan<byte> data)

Parameters

data ReadOnlySpan<byte>

The byte span containing serialized data.

Returns

T

The deserialized value.

Type Parameters

T

The type to deserialize to.

Exceptions

SerializationException

Thrown when deserialization fails.

SerializeObject(object, Type)

Serializes a runtime-typed value to bytes.

public byte[] SerializeObject(object value, Type type)

Parameters

value object

The value to serialize.

type Type

The runtime type to use for serialization.

Returns

byte[]

The serialized byte array.

Remarks

This overload is necessary for binary serializers (MemoryPack, MessagePack) that require concrete types when the compile-time type is an interface.

Exceptions

ArgumentNullException

Thrown when value or type is null.

SerializationException

Thrown when serialization fails.

Serialize<T>(T, IBufferWriter<byte>)

Serializes a value to a buffer writer. Allocation depends on the implementation, writer and value.

public void Serialize<T>(T value, IBufferWriter<byte> bufferWriter)

Parameters

value T

The value to serialize.

bufferWriter IBufferWriter<byte>

The buffer writer to write serialized data to.

Type Parameters

T

The type to serialize.

Remarks

Null-argument contract (canonical across all implementations): a null value is rejected with ArgumentNullException, mirroring SerializeObject(object, Type). This guarantees that swapping the configured serializer (MemoryPack, MessagePack, System.Text.Json, Avro, Protobuf, …) does not change the observable null-handling behavior. For value types T the guard is a no-op.

Exceptions

ArgumentNullException

Thrown when value or bufferWriter is null.

SerializationException

Thrown when serialization fails.