/// <summary> /// Deserialize an object of type <typeparamref name="T"/> from a byte array. /// </summary> /// <param name="topic"> /// The topic associated with the data (ignored by this deserializer). /// </param> /// <param name="data"> /// A byte array containing the object serialized in the format produced /// by <see cref="AvroSerializer{T}" />. /// </param> /// <returns> /// The deserialized <typeparamref name="T"/> value. /// </returns> public T Deserialize(string topic, byte[] data) { if (deserializerImpl == null) { deserializerImpl = (typeof(T) == typeof(GenericRecord)) ? (IAvroDeserializerImpl <T>) new GenericDeserializerImpl(schemaRegistryClient) : new SpecificDeserializerImpl <T>(schemaRegistryClient); } return(deserializerImpl.Deserialize(topic, data)); }
/// <summary> /// Deserialize an object of type <typeparamref name="T"/> from a byte array. /// </summary> /// <param name="topic"> /// The topic associated with the data (ignored by this deserializer). /// </param> /// <param name="data"> /// A byte array containing the object serialized in the format produced /// by <see cref="AvroSerializer{T}" />. /// </param> /// <param name="isNull"> /// True if the data is null, false otherwise. /// </param> /// <returns> /// The deserialized <typeparamref name="T"/> value. /// </returns> public T Deserialize(string topic, ReadOnlySpan <byte> data, bool isNull) { if (deserializerImpl == null) { deserializerImpl = (typeof(T) == typeof(GenericRecord)) ? (IAvroDeserializerImpl <T>) new GenericDeserializerImpl(schemaRegistryClient) : new SpecificDeserializerImpl <T>(schemaRegistryClient); } return(deserializerImpl.Deserialize(topic, data.ToArray())); }
/// <summary> /// Deserialize an object of type <typeparamref name="T"/> /// from a byte array. /// </summary> /// <param name="data"> /// The raw byte data to deserialize. /// </param> /// <param name="isNull"> /// True if this is a null value. /// </param> /// <param name="context"> /// Context relevant to the deserialize operation. /// </param> /// <returns> /// A <see cref="System.Threading.Tasks.Task" /> that completes /// with the deserialized value. /// </returns> public async Task <T> DeserializeAsync(ReadOnlyMemory <byte> data, bool isNull, SerializationContext context) { try { if (deserializerImpl == null) { deserializerImpl = (typeof(T) == typeof(GenericRecord)) ? (IAvroDeserializerImpl <T>) new GenericDeserializerImpl(schemaRegistryClient) : new SpecificDeserializerImpl <T>(schemaRegistryClient); } // TODO: change this interface such that it takes ReadOnlyMemory<byte>, not byte[]. return(await deserializerImpl.Deserialize(context.Topic, isNull?null : data.ToArray())); } catch (AggregateException e) { throw e.InnerException; } }
/// <summary> /// Deserialize an object of type <typeparamref name="T"/> /// from a byte array. /// </summary> /// <param name="data"> /// The raw byte data to deserialize. /// </param> /// <param name="isNull"> /// True if this is a null value. /// </param> /// <param name="messageMetadata"> /// Properties of the message the data is associated with in /// addition to the key or value. /// </param> /// <param name="source"> /// The TopicPartition from which the message was consumed. /// </param> /// <param name="isKey"> /// True if deserializing the message key, false if deserializing the /// message value. /// </param> /// <returns> /// A <see cref="System.Threading.Tasks.Task" /> that completes /// with the deserialized value. /// </returns> public async Task <T> DeserializeAsync(ReadOnlyMemory <byte> data, bool isNull, bool isKey, MessageMetadata messageMetadata, TopicPartition source) { try { if (deserializerImpl == null) { deserializerImpl = (typeof(T) == typeof(GenericRecord)) ? (IAvroDeserializerImpl <T>) new GenericDeserializerImpl(schemaRegistryClient) : new SpecificDeserializerImpl <T>(schemaRegistryClient); } // TODO: change this interface such that it takes ReadOnlyMemory<byte>, not byte[]. return(await deserializerImpl.Deserialize(source.Topic, isNull?null : data.ToArray())); } catch (AggregateException e) { throw new DeserializationException("Error occured deserializing Avro data.", e.InnerException); } catch (Exception e) { throw new DeserializationException("Error occured deserializing Avro data.", e); } }