2023-03-01 02:19:06 +00:00
|
|
|
//go:build !yq_nojson
|
|
|
|
|
2022-07-27 02:26:22 +00:00
|
|
|
package yqlib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/goccy/go-json"
|
|
|
|
)
|
|
|
|
|
|
|
|
type jsonDecoder struct {
|
|
|
|
decoder json.Decoder
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewJSONDecoder() Decoder {
|
|
|
|
return &jsonDecoder{}
|
|
|
|
}
|
|
|
|
|
2022-10-28 03:16:46 +00:00
|
|
|
func (dec *jsonDecoder) Init(reader io.Reader) error {
|
2022-07-27 02:26:22 +00:00
|
|
|
dec.decoder = *json.NewDecoder(reader)
|
2022-10-28 03:16:46 +00:00
|
|
|
return nil
|
2022-07-27 02:26:22 +00:00
|
|
|
}
|
|
|
|
|
2022-10-28 03:16:46 +00:00
|
|
|
func (dec *jsonDecoder) Decode() (*CandidateNode, error) {
|
2022-07-27 02:26:22 +00:00
|
|
|
|
2023-10-18 01:11:53 +00:00
|
|
|
var dataBucket CandidateNode
|
2022-07-27 02:26:22 +00:00
|
|
|
err := dec.decoder.Decode(&dataBucket)
|
|
|
|
if err != nil {
|
2022-10-28 03:16:46 +00:00
|
|
|
return nil, err
|
2022-07-27 02:26:22 +00:00
|
|
|
}
|
|
|
|
|
2023-10-18 01:11:53 +00:00
|
|
|
return &dataBucket, nil
|
2022-07-27 02:26:22 +00:00
|
|
|
}
|