confluent-kafka-dotnet
Show / Hide Table of Contents

Class AvroDeserializer<T>

(async) Avro deserializer. Use this deserializer with GenericRecord, types generated using the avrogen.exe tool or one of the following primitive types: int, long, float, double, boolean, string, byte[].

Inheritance
object
AvroDeserializer<T>
Implements
IAsyncDeserializer<T>
IClusterIdAware
ISerdeDisposable
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Confluent.SchemaRegistry.Serdes
Assembly: Confluent.SchemaRegistry.Serdes.Avro.dll
Syntax
public class AvroDeserializer<T> : IAsyncDeserializer<T>, IClusterIdAware, ISerdeDisposable
Type Parameters
Name Description
T
Remarks

Serialization format: byte 0: Magic byte use to identify the protocol format. bytes 1-4: Unique global id of the Avro schema that was used for encoding (as registered in Confluent Schema Registry), big endian. following bytes: The serialized data.

Constructors

AvroDeserializer(ISchemaRegistryClient)

Declaration
public AvroDeserializer(ISchemaRegistryClient schemaRegistryClient)
Parameters
Type Name Description
ISchemaRegistryClient schemaRegistryClient

AvroDeserializer(ISchemaRegistryClient, AvroDeserializerConfig, RuleRegistry)

Declaration
public AvroDeserializer(ISchemaRegistryClient schemaRegistryClient, AvroDeserializerConfig config = null, RuleRegistry ruleRegistry = null)
Parameters
Type Name Description
ISchemaRegistryClient schemaRegistryClient
AvroDeserializerConfig config
RuleRegistry ruleRegistry

AvroDeserializer(ISchemaRegistryClient, IEnumerable<KeyValuePair<string, string>>)

Initialize a new AvroDeserializer instance.

Declaration
public AvroDeserializer(ISchemaRegistryClient schemaRegistryClient, IEnumerable<KeyValuePair<string, string>> config = null)
Parameters
Type Name Description
ISchemaRegistryClient schemaRegistryClient

An implementation of ISchemaRegistryClient used for communication with Confluent Schema Registry.

IEnumerable<KeyValuePair<string, string>> config

Deserializer configuration properties (refer to AvroDeserializerConfig).

Methods

DeserializeAsync(ReadOnlyMemory<byte>, bool, SerializationContext)

Deserialize an object of type T from a byte array.

Declaration
public Task<T> DeserializeAsync(ReadOnlyMemory<byte> data, bool isNull, SerializationContext context)
Parameters
Type Name Description
ReadOnlyMemory<byte> data

The raw byte data to deserialize.

bool isNull

True if this is a null value.

SerializationContext context

Context relevant to the deserialize operation.

Returns
Type Description
Task<T>

A Task that completes with the deserialized value.

DisposeOwnedResources()

Release the resources this instance created itself.

Resources supplied by the application are not released. Implementations must tolerate being called more than once.

Declaration
public void DisposeOwnedResources()

SetClusterIdResolver(Func<Task<string>>)

Supply a resolver for the id of the Kafka cluster the client is connected to.

The resolver returns a task that completes once the client has reached a broker, with null if it cannot do so within the client's timeout; invoking it never blocks the caller. Concurrent invocations share a single resolution. Implementations are expected to invoke it lazily, only when the id is actually needed.

The resolver is bound to the client that supplied it, and throws ObjectDisposedException once that client has been disposed. A serializer or deserializer handed to a producer or consumer must therefore not be used after that client is disposed, unless the cluster id it needs was specified via configuration.

A serializer or deserializer instance holds a single resolver. If one instance is shared by several clients, the resolver supplied last replaces the earlier ones, so every client sharing the instance resolves the cluster id of the last client it was handed to. Do not share an instance between clients connected to different clusters; let the client creates the serde instance through the builder.

Implementations must ignore the resolver when the cluster id is not relevant to their configuration, or when it was specified explicitly via configuration, so that a configured cluster id is never overwritten.

Declaration
public void SetClusterIdResolver(Func<Task<string>> clusterIdResolver)
Parameters
Type Name Description
Func<Task<string>> clusterIdResolver

Resolves the Kafka cluster id.

Implements

IAsyncDeserializer<T>
IClusterIdAware
ISerdeDisposable
In this article