structure

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPrimitive

func IsPrimitive(name string) bool

IsPrimitive returns true, if name matches any case.

Types

type Field

type Field struct {
	Name string
	Tag  string
	Node *Node
}

Field has a field information in structure

type Node

type Node struct {

	// for identical
	IdenticalName string

	// for array
	ArrayLen uint64

	// for struct
	ImportPath  string
	PackageName string
	StructName  string

	// for array / map / pointer
	Key   *Node
	Value *Node

	Parent *Node
	// contains filtered or unexported fields
}

Node is a collection of field information.

func CreateArrayNode

func CreateArrayNode(len uint64, parent *Node) *Node

CreateArrayNode creates a node of array type.

func CreateIdentNode

func CreateIdentNode(ident *ast.Ident, parent *Node) *Node

CreateIdentNode creates a node of ident type.

func CreateMapNode

func CreateMapNode(parent *Node) *Node

CreateMapNode creates a node of map type.

func CreatePointerNode

func CreatePointerNode(parent *Node) *Node

CreatePointerNode creates a node of pointer type.

func CreateSliceNode

func CreateSliceNode(parent *Node) *Node

CreateSliceNode creates a node of slice type.

func CreateStructNode

func CreateStructNode(importPath, packageName, structName string, parent *Node) *Node

CreateStructNode creates a node of struct type.

func (Node) CanGenerate

func (n Node) CanGenerate(structures []*Structure) (bool, []string)

CanGenerate return true, if it satisfied conditions by this node.

func (Node) Elm

func (n Node) Elm() *Node

Elm gets the child node, if field-type is slice, array or pointer.

func (*Node) GetPointerInfo

func (n *Node) GetPointerInfo() (ptrCount int, isParentTypeArrayOrMap bool)

GetPointerInfo gets some pointer information to create codes.

func (Node) HasParent

func (n Node) HasParent() bool

HasParent returns true, if parent node exists.

func (Node) IsArray

func (n Node) IsArray() bool

IsArray returns true, if field-type is array.

func (Node) IsIdentical

func (n Node) IsIdentical() bool

IsIdentical returns true, if field-type is ident.

func (Node) IsMap

func (n Node) IsMap() bool

IsMap returns true, if field-type is map.

func (Node) IsParentPointer

func (n Node) IsParentPointer() bool

IsParentPointer returns true, if HasParent is true and parent node is pointer.

func (Node) IsPointer

func (n Node) IsPointer() bool

IsPointer returns true, if field-type is pointer.

func (Node) IsSlice

func (n Node) IsSlice() bool

IsSlice returns true, if field-type is slice.

func (Node) IsStruct

func (n Node) IsStruct() bool

IsStruct returns true, if field-type is struct.

func (Node) KeyValue

func (n Node) KeyValue() (*Node, *Node)

KeyValue gets child nodes, if field-type is map.

func (*Node) SetKeyNode

func (n *Node) SetKeyNode(key *Node)

SetKeyNode sets node to key field.

func (*Node) SetValueNode

func (n *Node) SetValueNode(value *Node)

SetValueNode sets node to value field.

func (Node) TypeJenChain

func (n Node) TypeJenChain(structures []*Structure, statements ...*Statement) *Statement

TypeJenChain is a helper method to create code.

type Structure

type Structure struct {
	ImportPath string
	Package    string
	Name       string
	Fields     []Field
	NoUseQual  bool

	Others []*Structure
	File   *ast.File

	CanGen  bool
	Reasons []string
}

Structure has information needed for code generation

func (*Structure) CalcArraySizeFuncName

func (st *Structure) CalcArraySizeFuncName() string

CalcArraySizeFuncName gets the function name for each structure

func (*Structure) CalcMapSizeFuncName

func (st *Structure) CalcMapSizeFuncName() string

CalcMapSizeFuncName gets the function name for each structure

func (*Structure) CreateCode

func (st *Structure) CreateCode(f *File)

CreateCode creates codes to serialize structure

func (*Structure) DecodeArrayFuncName

func (st *Structure) DecodeArrayFuncName() string

DecodeArrayFuncName gets the function name for each structure

func (*Structure) DecodeMapFuncName

func (st *Structure) DecodeMapFuncName() string

DecodeMapFuncName gets the function name for each structure

func (*Structure) EncodeArrayFuncName

func (st *Structure) EncodeArrayFuncName() string

EncodeArrayFuncName gets the function name for each structure

func (*Structure) EncodeMapFuncName

func (st *Structure) EncodeMapFuncName() string

EncodeMapFuncName gets the function name for each structure

Jump to

Keyboard shortcuts

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