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 ¶
- func Fold(v interface{}, vs structform.Visitor, opts ...FoldOption) error
- type BaseUnfoldState
- func (*BaseUnfoldState) OnArrayFinished(ctx UnfoldCtx) error
- func (*BaseUnfoldState) OnArrayStart(ctx UnfoldCtx, length int, bt structform.BaseType) error
- func (*BaseUnfoldState) OnBool(ctx UnfoldCtx, b bool) error
- func (*BaseUnfoldState) OnFloat(ctx UnfoldCtx, f float64) error
- func (*BaseUnfoldState) OnInt(ctx UnfoldCtx, i int64) error
- func (*BaseUnfoldState) OnKey(ctx UnfoldCtx, key string) error
- func (*BaseUnfoldState) OnNil(ctx UnfoldCtx) error
- func (*BaseUnfoldState) OnObjectFinished(ctx UnfoldCtx) error
- func (*BaseUnfoldState) OnObjectStart(ctx UnfoldCtx, length int, bt structform.BaseType) error
- func (*BaseUnfoldState) OnString(ctx UnfoldCtx, str string) error
- func (*BaseUnfoldState) OnUint(ctx UnfoldCtx, u uint64) error
- type Expander
- type FoldOption
- type Folder
- type IsZeroer
- type Iterator
- type UnfoldCtx
- type UnfoldOption
- type UnfoldState
- type Unfolder
- func (ctx *Unfolder) Cont(st UnfoldState)
- func (ctx *Unfolder) Done()
- func (u *Unfolder) EnableKeyCache(max int)
- func (u *Unfolder) OnArrayFinished() error
- func (u *Unfolder) OnArrayStart(len int, baseType structform.BaseType) error
- func (u *Unfolder) OnBool(b bool) error
- func (u *Unfolder) OnByte(b byte) error
- func (u *Unfolder) OnFloat32(f float32) error
- func (u *Unfolder) OnFloat64(f float64) error
- func (u *Unfolder) OnInt(i int) error
- func (u *Unfolder) OnInt16(i int16) error
- func (u *Unfolder) OnInt32(i int32) error
- func (u *Unfolder) OnInt64(i int64) error
- func (u *Unfolder) OnInt8(i int8) error
- func (u *Unfolder) OnKey(s string) error
- func (u *Unfolder) OnKeyRef(s []byte) error
- func (u *Unfolder) OnNil() error
- func (u *Unfolder) OnObjectFinished() error
- func (u *Unfolder) OnObjectStart(len int, baseType structform.BaseType) error
- func (u *Unfolder) OnString(s string) error
- func (u *Unfolder) OnStringRef(s []byte) error
- func (u *Unfolder) OnUint(v uint) error
- func (u *Unfolder) OnUint16(v uint16) error
- func (u *Unfolder) OnUint32(v uint32) error
- func (u *Unfolder) OnUint64(v uint64) error
- func (u *Unfolder) OnUint8(v uint8) error
- func (ctx *Unfolder) Push(st UnfoldState)
- func (u *Unfolder) Reset()
- func (u *Unfolder) SetTarget(to interface{}) error
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
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)
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) EnableKeyCache ¶
func (*Unfolder) OnArrayFinished ¶
func (u *Unfolder) OnArrayFinished() error
func (*Unfolder) OnArrayStart ¶
func (u *Unfolder) OnArrayStart(len int, baseType structform.BaseType) error
func (*Unfolder) OnObjectFinished ¶
func (u *Unfolder) OnObjectFinished() error
func (*Unfolder) OnObjectStart ¶
func (u *Unfolder) OnObjectStart(len int, baseType structform.BaseType) error
func (*Unfolder) OnStringRef ¶
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.
Source Files ¶
- 0gen.go
- defs.go
- error.go
- fold.go
- fold_arr.go
- fold_inline.go
- fold_map.go
- fold_map_inline.generated.go
- fold_opts.go
- fold_primitives.go
- fold_refl_sel.generated.go
- fold_reflect.go
- fold_user.go
- stacks.generated.go
- symbols.go
- tags.go
- unfold.go
- unfold_arr.generated.go
- unfold_err.generated.go
- unfold_ignore.generated.go
- unfold_lookup.go
- unfold_lookup_go.generated.go
- unfold_map.generated.go
- unfold_opts.go
- unfold_primitive.generated.go
- unfold_refl.generated.go
- unfold_refl.go
- unfold_struct.go
- unfold_user.go
- unfold_user_primitive.generated.go
- unfold_user_processing.generated.go