/// <summary> /// Reads an object off the stream. /// </summary> /// <typeparam name="T">The type of object to read. A single schema typically returns an object of a single .NET class. /// The only exception is UnionSchema, which can return a object of different types based on the branch selected. /// </typeparam> /// <param name="reuse">If not null, the implemenation will try to use to return the object</param> /// <param name="decoder">The decoder for deserialization</param> /// <returns></returns> public T Read <T>(T reuse, Decoder decoder) { if (!ReaderSchema.CanRead(WriterSchema)) { throw new AvroException("Schema mismatch. Reader: " + ReaderSchema + ", writer: " + WriterSchema); } return((T)Read(reuse, WriterSchema, ReaderSchema, decoder)); }
/// <summary> /// Constructs the default reader for the given schemas using the DefaultReader. If the /// reader's and writer's schemas are different this class performs the resolution. /// This default implemenation maps Avro types to .NET types as follows: /// </summary> /// <param name="writerSchema">The schema used while generating the data</param> /// <param name="readerSchema">The schema desired by the reader</param> public DefaultReader(Schema writerSchema, Schema readerSchema) { this.ReaderSchema = readerSchema; this.WriterSchema = writerSchema; if (!ReaderSchema.CanRead(WriterSchema)) { throw new AvroException("Schema mismatch. Reader: " + ReaderSchema + ", writer: " + WriterSchema); } }
/// <summary> /// Reads an object off the stream. /// </summary> /// <typeparam name="T">The type of object to read. A single schema typically returns an object of a single .NET class. /// The only exception is UnionSchema, which can return a object of different types based on the branch selected. /// </typeparam> /// <param name="reuse">If not null, the implemenation will try to use to return the object</param> /// <param name="IDecoder">The IDecoder for deserialization</param> /// <returns></returns> public T Read <T>(T reuse, IDecoder IDecoder) { if (!ReaderSchema.CanRead(WriterSchema)) { throw new AvroException("Schema mismatch. Reader: " + ReaderSchema + ", writer: " + WriterSchema); } var xd = Read(reuse, WriterSchema, ReaderSchema, IDecoder); return((T)xd); }
public object Read(IDecoder decoder) { if (!ReaderSchema.CanRead(WriterSchema)) { throw new AvroException("Schema mismatch. Reader: " + ReaderSchema + ", writer: " + WriterSchema); } var result = Read(WriterSchema, ReaderSchema, decoder); return(result); }