/// <summary> /// Initializes a new instance of the <see cref="StreamReader{T}"/> class for Avro records. /// </summary> /// <param name="readerSchema">The reader schema.</param> /// <param name="stream">The input stream.</param> /// <param name="leaveOpen">If set to <c>true</c> leaves the input stream open.</param> /// <param name="codecFactory">The codec factory.</param> public StreamReader(string readerSchema, Stream stream, bool leaveOpen, CodecFactory codecFactory) { if (stream == null) { throw new ArgumentNullException("stream"); } if (codecFactory == null) { throw new ArgumentNullException("codecFactory"); } this.stream = stream; this.decoder = new BinaryDecoder(stream, leaveOpen); this.header = ObjectContainerHeader.Read(this.decoder); this.codec = codecFactory.Create(this.header.CodecName); this.serializer = (IAvroSerializer <T>)AvroSerializer.CreateGenericDeserializerOnly(this.header.Schema, readerSchema ?? this.header.Schema); }
/// <summary> /// Initializes a new instance of the <see cref="StreamReader{T}"/> class for static types. /// </summary> /// <param name="stream">The stream.</param> /// <param name="leaveOpen">If set to <c>true</c> leaves the input stream open.</param> /// <param name="settings">The settings.</param> /// <param name="codecFactory">The codec factory.</param> public StreamReader(Stream stream, bool leaveOpen, AvroSerializerSettings settings, CodecFactory codecFactory) { if (stream == null) { throw new ArgumentNullException("stream"); } if (settings == null) { throw new ArgumentNullException("settings"); } if (codecFactory == null) { throw new ArgumentNullException("codecFactory"); } this.stream = stream; this.decoder = new BinaryDecoder(stream, leaveOpen); this.header = ObjectContainerHeader.Read(this.decoder); this.codec = codecFactory.Create(this.header.CodecName); this.serializer = AvroSerializer.CreateDeserializerOnly <T>(this.header.Schema, settings); }
public void Container_GenericWriterUsingCodecFactoryWithNullCodecName() { const string WriterSchema = @"{ ""name"":""RecordContainingArray"", ""type"":""record"", ""fields"": [ {""name"":""IntField"", ""type"":""int""}, ] }"; var codecFactory = new CodecFactory(); using (AvroContainer.CreateGenericWriter(WriterSchema, this.resultStream, codecFactory.Create(null))) { } }