/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using Avro.IO;
using Avro.Generic;
namespace Avro.Reflect
{
///
/// Reader wrapper class for reading data and storing into specific classes
///
/// Specific class type
public class ReflectReader : DatumReader
{
///
/// Reader class for reading data and storing into specific classes
///
private readonly ReflectDefaultReader _reader;
///
/// Default reader
///
public ReflectDefaultReader Reader { get => _reader; }
///
/// Schema for the writer class
///
public Schema WriterSchema { get => _reader.WriterSchema; }
///
/// Schema for the reader class
///
public Schema ReaderSchema { get => _reader.ReaderSchema; }
///
/// Constructs a generic reader for the given schemas using the DefaultReader. If the
/// reader's and writer's schemas are different this class performs the resolution.
///
/// The schema used while generating the data
/// The schema desired by the reader
/// Class cache
public ReflectReader(Schema writerSchema, Schema readerSchema, ClassCache cache = null)
{
_reader = new ReflectDefaultReader(typeof(T), writerSchema, readerSchema, cache);
}
///
/// Constructs a generic reader from an instance of a ReflectDefaultReader (non-generic)
///
///
public ReflectReader(ReflectDefaultReader reader)
{
_reader = reader;
}
///
/// Generic read function
///
/// object to store data read
/// decorder to use for reading data
///
public T Read(T reuse, Decoder dec)
{
return _reader.Read(reuse, dec);
}
///
/// Generic read function
///
/// decorder to use for reading data
///
public T Read(Decoder dec)
{
return _reader.Read(default(T), dec);
}
}
}