func (e *Encoder) EncodeToNode(v interface{}) (ast.Node, error) {
	return e.EncodeToNodeContext(context.Background(), v)
}
EncodeToNode convert v to ast.Node.
package yaml
import (
	"context"
	"encoding"
	"fmt"
	"io"
	"math"
	"reflect"
	"sort"
	"strconv"
	"strings"
	"time"
	"github.com/goccy/go-yaml/ast"
	"github.com/goccy/go-yaml/internal/errors"
	"github.com/goccy/go-yaml/parser"
	"github.com/goccy/go-yaml/printer"
	"github.com/goccy/go-yaml/token"
	"golang.org/x/xerrors"
)
const (
	DefaultIndentSpaces = 2
)
type Encoder struct {
	writer                     io.Writer
	opts                       []EncodeOption
	indent                     int
	indentSequence             bool
	isFlowStyle                bool
	isJSONStyle                bool
	useJSONMarshaler           bool
	anchorCallback             func(*ast.AnchorNode, interface{}) error
	anchorPtrToNameMap         map[uintptr]string
	useLiteralStyleIfMultiline bool
	commentMap                 map[*Path]*Comment
	line        int
	column      int
	offset      int
	indentNum   int
	indentLevel int
}
func NewEncoder(w io.Writer, opts ...EncodeOption) *Encoder {
	return &Encoder{
		writer:             w,
		opts:               opts,
		indent:             DefaultIndentSpaces,
		anchorPtrToNameMap: map[uintptr]string{},
		line:               1,
		column:             1,
		offset:             0,
	}
}
func (e *Encoder) Close() error {
	return nil
}
func (e *Encoder) Encode(v interface{}) error {
	return e.EncodeContext(context.Background(), v)
}
func (e *Encoder) EncodeContext(ctx context.Context, v interface{}) error {
	node, err := e.EncodeToNodeContext(ctx, v)
	if err != nil {
		return errors.Wrapf(err, "failed to encode to node")
	}
	if err := e.setCommentByCommentMap(node); err != nil {
		return errors.Wrapf(err, "failed to set comment by comment map")
	}
	var p printer.Printer
	e.writer.Write(p.PrintNode(node))
	return nil
}