base

package
v1.3.5-alpha0828 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CfgIsTerminal = "isTerminal"
	CfgIsList     = "isList"
	CfgLength     = "length"
	CfgType       = "type"
	CfgGetResult  = "get result"
	CfgRawResult  = "raw result"
	CfgRootMap    = "rootNodeMap"
	CfgEndian     = "endian"
	CfgOperator   = "operator"
	CfgInList     = "inList"
	CfgParent     = "parent"
	CfgDel        = "del"
	CfgDelimiter  = "delimiter"
	CfgImport     = "import"
	CfgNodeResult = "node result"
	CfgLastNode   = "last node"
	CfgOptionFuns = "options functions"
)

Variables

This section is empty.

Functions

func GetNodePath

func GetNodePath(node *Node) string

func GetSubData

func GetSubData(d any, key string) (any, bool)

func GetValueByNode

func GetValueByNode(d any, node *Node) (any, bool)

func InterfaceToUint64

func InterfaceToUint64(d any) (uint64, bool)

func RegisterParser

func RegisterParser(name string, parser Parser)

func UnmarshalSubData added in v1.3.3

func UnmarshalSubData(d any, path string, v any) error

Types

type BaseKV

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

func (*BaseKV) ConvertUint64

func (c *BaseKV) ConvertUint64(k string) uint64

func (*BaseKV) DeleteItem

func (c *BaseKV) DeleteItem(k string)

func (*BaseKV) GetBool

func (c *BaseKV) GetBool(k string) bool

func (*BaseKV) GetItem

func (c *BaseKV) GetItem(k string) any

func (*BaseKV) GetString

func (c *BaseKV) GetString(k string) string

func (*BaseKV) GetUint64

func (c *BaseKV) GetUint64(k string) uint64

func (*BaseKV) Has

func (c *BaseKV) Has(k string) bool

func (*BaseKV) SetItem

func (c *BaseKV) SetItem(k string, v any)

type BaseParser

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

type BitReader

type BitReader struct {
	Reader *bitio.Reader
	// contains filtered or unexported fields
}

func NewBitReader

func NewBitReader(reader io.Reader) *BitReader

func (*BitReader) Backup

func (b *BitReader) Backup() error

func (*BitReader) PopBackup

func (b *BitReader) PopBackup() error

func (*BitReader) Read

func (r *BitReader) Read(p []byte) (n int, err error)

func (*BitReader) ReadBits

func (b *BitReader) ReadBits(n uint64) ([]byte, error)

func (*BitReader) Recovery

func (b *BitReader) Recovery() error

type BitWriter

type BitWriter struct {
	*bitio.Writer
	PreIsBit   bool
	PreByte    uint8
	PreByteLen uint8
}

func NewBitWriter

func NewBitWriter(writer io.Writer) *BitWriter

func (*BitWriter) WriteBits

func (b *BitWriter) WriteBits(bs []byte, length uint64) (err error)

type ConcatReader

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

func NewConcatReader

func NewConcatReader(readers ...io.Reader) *ConcatReader

func (*ConcatReader) Read

func (cr *ConcatReader) Read(p []byte) (n int, err error)

type Config

type Config struct {
	BaseKV
}

func AppendConfig

func AppendConfig(parent, config *Config) *Config

func CopyConfig

func CopyConfig(config *Config) *Config

func NewConfig

func NewConfig(config *Config) *Config

func NewEmptyConfig

func NewEmptyConfig() *Config

func (*Config) SetItem

func (c *Config) SetItem(k string, v any)

type Node

type Node struct {
	Name     string
	Origin   any
	Children []*Node
	Cfg      *Config
	Ctx      *NodeContext
}

func GetNodeByPath

func GetNodeByPath(node *Node, key string) *Node

func NewChildNodeTree

func NewChildNodeTree(parent *Node, name string, data any, ctx *NodeContext) (*Node, error)

func NewEmptyNode

func NewEmptyNode(name string, d any, cfg *Config, ctx *NodeContext) *Node

NewEmptyNode 默认初始化一个空节点

func NewNodeTree

func NewNodeTree(d yaml.MapSlice) (*Node, error)

func NewNodeTreeWithConfig

func NewNodeTreeWithConfig(parentCfg *Config, name string, data any, ctx *NodeContext) (*Node, error)

func ParseRule

func ParseRule(p string) (*Node, error)

func (*Node) AppendNode

func (n *Node) AppendNode(node *Node) error
func (n *Node) SetParentResultWriterByNode(node *Node) {
	nodeRes := node.Cfg.GetItem("resultWriter").(*NodeResult)
	n.Cfg.SetItem("parentResultWriter", func(d []byte, length uint64) error {
		return nodeRes.Write(d, length)
	})
}

func (*Node) Copy

func (n *Node) Copy() *Node

func (*Node) Generate

func (n *Node) Generate(data any) error

func (*Node) GenerateSubNode

func (n *Node) GenerateSubNode(data any, path string) error

func (*Node) Parse

func (n *Node) Parse(reader *BitReader) error

func (*Node) ParseSubNode

func (n *Node) ParseSubNode(data *BitReader, path string) error

func (*Node) Result

func (n *Node) Result() (*NodeValue, error)

type NodeConfigFun

type NodeConfigFun func(config *Config)

type NodeContext

type NodeContext struct {
	BaseKV
}

type NodeValue

type NodeValue struct {
	Origin    *Node
	Name      string
	Value     any
	ListValue bool
	AppendSub func(value *NodeValue) error
}

func (*NodeValue) Child

func (n *NodeValue) Child(name string) *NodeValue

func (*NodeValue) Children

func (n *NodeValue) Children() []*NodeValue

func (*NodeValue) IsList

func (n *NodeValue) IsList() bool

func (*NodeValue) IsStruct

func (n *NodeValue) IsStruct() bool

func (*NodeValue) IsValue

func (n *NodeValue) IsValue() bool

type Parser

type Parser interface {
	Parse(data *BitReader, node *Node) error
	Generate(data any, node *Node) error
	OnRoot(node *Node) error
	Result(node *Node) (*NodeValue, error)
}

Jump to

Keyboard shortcuts

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