package avro

import (
	
)

// Decoder reads and decodes Avro values from an input stream.
type Decoder struct {
	s Schema
	r *Reader
}

// NewDecoder returns a new decoder that reads from reader r using schema s.
func ( string,  io.Reader) (*Decoder, error) {
	,  := Parse()
	if  != nil {
		return nil, 
	}

	return NewDecoderForSchema(, ), nil
}

// NewDecoderForSchema returns a new decoder that reads from r using schema.
func ( Schema,  io.Reader) *Decoder {
	return DefaultConfig.NewDecoder(, )
}

// Decode reads the next Avro encoded value from its input and stores it in the value pointed to by v.
func ( *Decoder) ( any) error {
	if .r.head == .r.tail && .r.reader != nil {
		if !.r.loadMore() {
			return io.EOF
		}
	}

	.r.ReadVal(.s, )

	//nolint:errorlint // Only direct EOF errors should be discarded.
	if .r.Error == io.EOF {
		return nil
	}
	return .r.Error
}

// Unmarshal parses the Avro encoded data and stores the result in the value pointed to by v.
// If v is nil or not a pointer, Unmarshal returns an error.
func ( Schema,  []byte,  any) error {
	return DefaultConfig.Unmarshal(, , )
}