decodini

package
v0.0.0-...-fe2ba74 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode[T any](dec *Decoding, tr *Tree) (T, error)

func DecodeInto

func DecodeInto(dec *Decoding, tr *Tree, into any) error

func Transmute

func Transmute[T any](tr *Transmutation, from any) (T, error)

Transmute encodes the given `from` value into a tree, and decodes the tree into a variable of type `T`.

func TransmuteInto

func TransmuteInto(tr *Transmutation, from, to any) error

TransmuteInto encodes the given `from` value into a tree and decodes the tree directly into the given `to` value.

Types

type DecodeError

type DecodeError struct {
	From *Tree
	Into DecodeTarget
	Err  error
}

func (*DecodeError) Error

func (e *DecodeError) Error() string

Error returns the error message.

func (*DecodeError) PathString

func (e *DecodeError) PathString() string

PathSTring returns a dot-separated string representation of the path.

func (*DecodeError) Unwrap

func (e *DecodeError) Unwrap() error

Unwrap returns the underlying error.

type DecodeTarget

type DecodeTarget struct {
	Name  any
	Value reflect.Value
	// contains filtered or unexported fields
}

func (DecodeTarget) IsPrimitive

func (d DecodeTarget) IsPrimitive() bool

func (DecodeTarget) IsStructField

func (d DecodeTarget) IsStructField() bool

func (DecodeTarget) StructField

func (d DecodeTarget) StructField() reflect.StructField

type Decoder

type Decoder func(tr *Tree, target DecodeTarget) error

type Decoding

type Decoding struct {
	StructTag string

	// Decoder is a custom decoder. If nil is returned, the default decoding
	// mechanism is used.
	Decoder func(tr *Tree, target DecodeTarget) Decoder

	Unmatched func(tr *Tree, target DecodeTarget) (*Tree, error)
}

type Encoding

type Encoding struct {
	StructTag string
}

type Transmutation

type Transmutation struct {
	Encoding *Encoding
	Decoding *Decoding
}

type Tree

type Tree struct {
	// contains filtered or unexported fields
}

func DecodeIgnoreUnmatched

func DecodeIgnoreUnmatched(*Tree, DecodeTarget) (*Tree, error)

func Encode

func Encode(enc *Encoding, val any) *Tree

Encode encodes the given value into a (lazy) Tree.

func (*Tree) BreadthFirst

func (t *Tree) BreadthFirst() iter.Seq[*Tree]

BreadthFirst returns a sequence of the tree nodes in breadth-first order.

func (*Tree) Child

func (t *Tree) Child(name any) *Tree

Child returns the child of this node with the given name.

func (*Tree) Children

func (t *Tree) Children() iter.Seq[*Tree]

Children returns a sequence of the children of this node, preserving their order.

func (*Tree) DepthFirst

func (t *Tree) DepthFirst() iter.Seq[*Tree]

DepthFirst returns a sequence of the tree nodes in depth-first order.

func (*Tree) IsNil

func (t *Tree) IsNil() bool

IsNil returns true if this node's value is nil.

func (*Tree) IsPrimitive

func (t *Tree) IsPrimitive() bool

func (*Tree) IsStructField

func (t *Tree) IsStructField() bool

func (*Tree) Name

func (t *Tree) Name() any

Name returns the name of this node in the parent node. If this node is root or represents an embedded node (i.e. anonymous struct field), the name is nil.

func (*Tree) NumChildren

func (t *Tree) NumChildren() uint

NumChildren returns the number of children of this node.

func (*Tree) Parent

func (t *Tree) Parent() *Tree

Parent returns the parent of this node. If this is a root node, nil is returned.

func (*Tree) Path

func (t *Tree) Path() (path []any)

Path returns the path from the root to this node. The first element is the name of

func (*Tree) SetValue

func (t *Tree) SetValue(val reflect.Value)

SetValue updates the value of this node to the given val. The original value is not further used.

func (*Tree) String

func (t *Tree) String() string

func (*Tree) StructField

func (t *Tree) StructField() reflect.StructField

func (*Tree) Value

func (t *Tree) Value() reflect.Value

Value returns the underlying reflect.Value of this node.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL