2021-12-16 06:50:09 +00:00
|
|
|
package yqlib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
|
|
|
yaml "gopkg.in/yaml.v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Decoder interface {
|
2021-12-17 11:31:52 +00:00
|
|
|
Init(reader io.Reader)
|
2021-12-16 06:50:09 +00:00
|
|
|
Decode(node *yaml.Node) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type yamlDecoder struct {
|
2021-12-17 11:31:52 +00:00
|
|
|
decoder yaml.Decoder
|
2021-12-16 06:50:09 +00:00
|
|
|
}
|
|
|
|
|
2021-12-17 11:31:52 +00:00
|
|
|
func NewYamlDecoder() Decoder {
|
|
|
|
return &yamlDecoder{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dec *yamlDecoder) Init(reader io.Reader) {
|
|
|
|
dec.decoder = *yaml.NewDecoder(reader)
|
2021-12-16 06:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (dec *yamlDecoder) Decode(rootYamlNode *yaml.Node) error {
|
|
|
|
return dec.decoder.Decode(rootYamlNode)
|
|
|
|
}
|