2023-10-05 06:53:42 +00:00
|
|
|
//go:build !yq_noyaml
|
|
|
|
|
|
|
|
package yqlib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
|
|
|
yaml "github.com/goccy/go-yaml"
|
|
|
|
"github.com/goccy/go-yaml/ast"
|
|
|
|
)
|
|
|
|
|
|
|
|
type goccyYamlDecoder struct {
|
|
|
|
decoder yaml.Decoder
|
2023-10-05 23:36:28 +00:00
|
|
|
cm yaml.CommentMap
|
2023-10-05 06:53:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewGoccyYAMLDecoder() Decoder {
|
|
|
|
return &goccyYamlDecoder{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dec *goccyYamlDecoder) Init(reader io.Reader) error {
|
2023-10-05 23:36:28 +00:00
|
|
|
dec.cm = yaml.CommentMap{}
|
2023-10-10 03:28:53 +00:00
|
|
|
dec.decoder = *yaml.NewDecoder(reader, yaml.CommentToMap(dec.cm), yaml.UseOrderedMap())
|
2023-10-05 06:53:42 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dec *goccyYamlDecoder) Decode() (*CandidateNode, error) {
|
|
|
|
|
|
|
|
var ast ast.Node
|
|
|
|
|
|
|
|
err := dec.decoder.Decode(&ast)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
candidateNode := &CandidateNode{}
|
2023-10-05 23:36:28 +00:00
|
|
|
candidateNode.UnmarshalGoccyYAML(ast, dec.cm)
|
2023-10-05 06:53:42 +00:00
|
|
|
|
|
|
|
return candidateNode, nil
|
|
|
|
}
|