palm

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2023 License: Unlicense Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeNull = 0
	TypeBool = 1
	TypeNum  = 2
	TypeStr  = 3
	TypeMap  = 4
	TypeArr  = 5
)

Variables

This section is empty.

Functions

func From

func From[T any](obj T, ctx IMarshalSchemaContext) calm.ResultT[ITree]

func FromDefault

func FromDefault[T any](obj T) calm.ResultT[ITree]

func IsArr

func IsArr(tree ITree) bool

func IsBool

func IsBool(tree ITree) bool

func IsMap

func IsMap(tree ITree) bool

func IsNull

func IsNull(tree ITree) bool

func IsNum

func IsNum(tree ITree) bool

func IsStr

func IsStr(tree ITree) bool

func To

func To[T any](tree ITree, ctx IMarshalSchemaContext) calm.ResultT[T]

func ToAny

func ToAny(v ITree) any

func ToDefault

func ToDefault[T any](tree ITree) calm.ResultT[T]

func ToUrlValues

func ToUrlValues(v ITree) calm.ResultT[url.Values]

Types

type IMarshalErr

type IMarshalErr interface {
	Path() string
	Reason() string
}

func NewMarshalErr

func NewMarshalErr(reason string) IMarshalErr

func NewMarshalErrType

func NewMarshalErrType(want, actual int32) IMarshalErr

func WrapMarshalErr

func WrapMarshalErr(err IMarshalErr, path string) IMarshalErr

type IMarshalSchema

type IMarshalSchema interface {
	Zero(value reflect.Value)
	Read(value reflect.Value) ITree
	Write(value reflect.Value, tree ITree) IMarshalErr
}

IMarshalSchema The interface for a marshal-able type

Note:

There has always been an interest to speed up encode/decode by skipping reflection.
However, this cannot be achieved without exposing golang's internal api.
I will stick with reflect.Value for this for the foreseeable future.
If anyone is interested in doing so, maybe checkout Masaaki Goshima(https://github.com/goccy)'s work
and implement said mechanism on your own fork

type IMarshalSchemaContext

type IMarshalSchemaContext interface {
	With() IMarshalSchemaResolutionContext
	Supply(t reflect.Type, schema IMarshalSchema)
	// contains filtered or unexported methods
}

func DefaultSchemaContext

func DefaultSchemaContext() IMarshalSchemaContext

func MakeSchemaContext

func MakeSchemaContext(parent IMarshalSchemaContext) IMarshalSchemaContext

type IMarshalSchemaResolutionContext

type IMarshalSchemaResolutionContext interface {
	Resolve(t reflect.Type) IMarshalSchema
}

type ITree

type ITree interface {
	Type() int32
	AsBool() calm.ResultT[bool]
	AsNum() calm.ResultT[float64]
	AsStr() calm.ResultT[string]
	AsMap() calm.ResultT[map[string]ITree]
	AsArr() calm.ResultT[[]ITree]
	SetBool(bool)
	SetNum(float64)
	SetStr(string)
	SetMap(map[string]ITree)
	SetArr([]ITree)
}

func FromAny

func FromAny(v any) ITree

func FromUrlValues

func FromUrlValues(v url.Values) ITree

func NewArr

func NewArr(v []ITree) ITree

func NewBool

func NewBool(v bool) ITree

func NewMap

func NewMap(v map[string]ITree) ITree

func NewNull

func NewNull() ITree

func NewNum

func NewNum(v float64) ITree

func NewStr

func NewStr(v string) ITree

Jump to

Keyboard shortcuts

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