mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
41 lines
731 B
Go
41 lines
731 B
Go
//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
|
|
cm yaml.CommentMap
|
|
}
|
|
|
|
func NewGoccyYAMLDecoder() Decoder {
|
|
return &goccyYamlDecoder{}
|
|
}
|
|
|
|
func (dec *goccyYamlDecoder) Init(reader io.Reader) error {
|
|
dec.cm = yaml.CommentMap{}
|
|
dec.decoder = *yaml.NewDecoder(reader, yaml.CommentToMap(dec.cm), yaml.UseOrderedMap())
|
|
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{}
|
|
candidateNode.UnmarshalGoccyYAML(ast, dec.cm)
|
|
|
|
return candidateNode, nil
|
|
}
|