gotype

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2022 License: Apache-2.0 Imports: 10 Imported by: 298

Documentation

Overview

This file has been generated from 'fold_map_inline.yml', do not edit

This file has been generated from 'fold_refl_sel.yml', do not edit

This file has been generated from 'stacks.yml', do not edit

This file has been generated from 'unfold_arr.yml', do not edit

This file has been generated from 'unfold_err.yml', do not edit

This file has been generated from 'unfold_ignore.yml', do not edit

This file has been generated from 'unfold_lookup_go.yml', do not edit

This file has been generated from 'unfold_map.yml', do not edit

This file has been generated from 'unfold_primitive.yml', do not edit

This file has been generated from 'unfold_refl.yml', do not edit

This file has been generated from 'unfold_user_primitive.yml', do not edit

This file has been generated from 'unfold_user_processing.yml', do not edit

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fold

func Fold(v interface{}, vs structform.Visitor, opts ...FoldOption) error

Types

type BaseUnfoldState added in v0.0.6

type BaseUnfoldState struct{}

BaseUnfoldState implements UnfoldState, but returns an error for every callback possible. One case embedd BaseUnfoldState in a custom struct, so to reduce the number of methods to implement.

func (*BaseUnfoldState) OnArrayFinished added in v0.0.6

func (*BaseUnfoldState) OnArrayFinished(ctx UnfoldCtx) error

func (*BaseUnfoldState) OnArrayStart added in v0.0.6

func (*BaseUnfoldState) OnArrayStart(ctx UnfoldCtx, length int, bt structform.BaseType) error

func (*BaseUnfoldState) OnBool added in v0.0.6

func (*BaseUnfoldState) OnBool(ctx UnfoldCtx, b bool) error

func (*BaseUnfoldState) OnFloat added in v0.0.6

func (*BaseUnfoldState) OnFloat(ctx UnfoldCtx, f float64) error

func (*BaseUnfoldState) OnInt added in v0.0.6

func (*BaseUnfoldState) OnInt(ctx UnfoldCtx, i int64) error

func (*BaseUnfoldState) OnKey added in v0.0.6

func (*BaseUnfoldState) OnKey(ctx UnfoldCtx, key string) error

func (*BaseUnfoldState) OnNil added in v0.0.6

func (*BaseUnfoldState) OnNil(ctx UnfoldCtx) error

func (*BaseUnfoldState) OnObjectFinished added in v0.0.6

func (*BaseUnfoldState) OnObjectFinished(ctx UnfoldCtx) error

func (*BaseUnfoldState) OnObjectStart added in v0.0.6

func (*BaseUnfoldState) OnObjectStart(ctx UnfoldCtx, length int, bt structform.BaseType) error

func (*BaseUnfoldState) OnString added in v0.0.6

func (*BaseUnfoldState) OnString(ctx UnfoldCtx, str string) error

func (*BaseUnfoldState) OnUint added in v0.0.6

func (*BaseUnfoldState) OnUint(ctx UnfoldCtx, u uint64) error

type Expander added in v0.0.6

type Expander interface {
	Expand() UnfoldState
}

Expander supports the creation of an UnfoldState for handling the unfolding into the current value.

type FoldOption added in v0.0.6

type FoldOption func(*initFoldOptions) error

func Folders

func Folders(in ...interface{}) FoldOption

type Folder

type Folder interface {
	Fold(structform.ExtVisitor) error
}

type IsZeroer added in v0.0.9

type IsZeroer interface {
	IsZero() bool
}

IsZeroer interface allows custom types to be reported as empty. If the `omitempty` struct tag option is set and the custom type implements IsZero(), which returns true, then the field will not be reported.

type Iterator

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

func NewIterator

func NewIterator(vs structform.Visitor, opts ...FoldOption) (*Iterator, error)

func (*Iterator) Fold

func (i *Iterator) Fold(v interface{}) error

type UnfoldCtx added in v0.0.6

type UnfoldCtx interface {
	// Done signals the context that the current state is finished.
	// The current state will be removed from the stack and processing continues
	// with the current state.
	Done()

	// Cont replaces the current state with the new state. All unfolding
	// will continue with the new state
	Cont(st UnfoldState)

	// Push adds a new parsing state on top of the state stack. Unfolding
	// will continue with the new state.
	Push(st UnfoldState)
}

UnfoldCtx provides access to the shared unfolding stack. It is used with UnfoldState, so to implement very custom parsing.

type UnfoldOption added in v0.0.6

type UnfoldOption func(*initUnfoldOptions) error

func Unfolders added in v0.0.6

func Unfolders(in ...interface{}) UnfoldOption

Unfolders accepts a list of primitive, processing, or stateful unfolders.

Primitive unfolder must implement a function matching the type: func(to *Target, from P) error Where to is an arbitrary go type that the result should be written to and P must be one of: bool, string, uint(8|16|32|64), int(8|16|32|64), float(32|64)

Processing unfolders first unfold a structure into a temporary structure, followed by a post-processing function used to fill in the original target. Processing unfolders for type T have the signature: func(to *T) (cell interface{}, process func(to *T, cell interface{}) error)

A processing unfolder returns a temporary value for unfolding. The Unfolder will process the temporary value (held in cell), like any regular supported value. The process function is executed if the parsing step did succeed. The address to the target structure and the original cell are reported to the process function, reducing the need for allocation storage on the heap in most simple cases.

Stateful unfolders have the function signature: func(to *T) UnfoldState. The state returned by the initialization function is used for parsing. Although stateful unfolders allow for the most complex unfolding possible, they add the most overhead in managing state and allocations. If possible prefer primitive unfolders, followed by processing unfolder.

type UnfoldState added in v0.0.6

type UnfoldState interface {
	// primitives
	OnNil(ctx UnfoldCtx) error
	OnBool(ctx UnfoldCtx, b bool) error
	OnString(ctx UnfoldCtx, str string) error
	OnInt(ctx UnfoldCtx, i int64) error
	OnUint(ctx UnfoldCtx, u uint64) error
	OnFloat(ctx UnfoldCtx, f float64) error

	// array types
	OnArrayStart(ctx UnfoldCtx, length int, bt structform.BaseType) error
	OnArrayFinished(ctx UnfoldCtx) error

	// object types
	OnObjectStart(ctx UnfoldCtx, length int, bt structform.BaseType) error
	OnObjectFinished(ctx UnfoldCtx) error
	OnKey(ctx UnfoldCtx, key string) error
}

UnfoldState defines a custom user defined unfolder. When unfolding a stack is used to keep state. The UnfoldCtx provides methods to manipluate the stack of active unfolders. The current UnfoldState will be used as long as it has not been remove or replaced using one of the UnfoldCtx control methods.

type Unfolder

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

func NewUnfolder

func NewUnfolder(to interface{}, opts ...UnfoldOption) (*Unfolder, error)

func (*Unfolder) Cont added in v0.0.6

func (ctx *Unfolder) Cont(st UnfoldState)

func (*Unfolder) Done added in v0.0.6

func (ctx *Unfolder) Done()

func (*Unfolder) EnableKeyCache

func (u *Unfolder) EnableKeyCache(max int)

func (*Unfolder) OnArrayFinished

func (u *Unfolder) OnArrayFinished() error

func (*Unfolder) OnArrayStart

func (u *Unfolder) OnArrayStart(len int, baseType structform.BaseType) error

func (*Unfolder) OnBool

func (u *Unfolder) OnBool(b bool) error

func (*Unfolder) OnByte

func (u *Unfolder) OnByte(b byte) error

func (*Unfolder) OnFloat32

func (u *Unfolder) OnFloat32(f float32) error

func (*Unfolder) OnFloat64

func (u *Unfolder) OnFloat64(f float64) error

func (*Unfolder) OnInt

func (u *Unfolder) OnInt(i int) error

func (*Unfolder) OnInt16

func (u *Unfolder) OnInt16(i int16) error

func (*Unfolder) OnInt32

func (u *Unfolder) OnInt32(i int32) error

func (*Unfolder) OnInt64

func (u *Unfolder) OnInt64(i int64) error

func (*Unfolder) OnInt8

func (u *Unfolder) OnInt8(i int8) error

func (*Unfolder) OnKey

func (u *Unfolder) OnKey(s string) error

func (*Unfolder) OnKeyRef

func (u *Unfolder) OnKeyRef(s []byte) error

func (*Unfolder) OnNil

func (u *Unfolder) OnNil() error

func (*Unfolder) OnObjectFinished

func (u *Unfolder) OnObjectFinished() error

func (*Unfolder) OnObjectStart

func (u *Unfolder) OnObjectStart(len int, baseType structform.BaseType) error

func (*Unfolder) OnString

func (u *Unfolder) OnString(s string) error

func (*Unfolder) OnStringRef

func (u *Unfolder) OnStringRef(s []byte) error

func (*Unfolder) OnUint

func (u *Unfolder) OnUint(v uint) error

func (*Unfolder) OnUint16

func (u *Unfolder) OnUint16(v uint16) error

func (*Unfolder) OnUint32

func (u *Unfolder) OnUint32(v uint32) error

func (*Unfolder) OnUint64

func (u *Unfolder) OnUint64(v uint64) error

func (*Unfolder) OnUint8

func (u *Unfolder) OnUint8(v uint8) error

func (*Unfolder) Push added in v0.0.6

func (ctx *Unfolder) Push(st UnfoldState)

func (*Unfolder) Reset added in v0.0.5

func (u *Unfolder) Reset()

Reset reinitializes the unfolder and removes all references to the target object. Use Reset if the unfolder is re-used and the target changed. References to the target can prevent the garbage collector from collecting the target after processing. Use Reset to set the target to `nil`. SetTarget must be called after Reset and before another Unfold operation.

func (*Unfolder) SetTarget

func (u *Unfolder) SetTarget(to interface{}) error

Jump to

Keyboard shortcuts

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