variant

package
v0.1.92 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2024 License: LGPL-2.1 Imports: 12 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCast = errors.New("gap: invalid cast")         // 类型转换错误
	ErrNotDeclared = errors.New("gap: variant not declared") // 类型未注册
)

Functions

func CastVariantReflected added in v0.1.88

func CastVariantReflected(variant Variant, valueRT reflect.Type) (reflect.Value, error)

CastVariantReflected 转换反射可变类型

Types

type Array

type Array []Variant

Array array

func MakeArrayBuffReadonly added in v0.1.90

func MakeArrayBuffReadonly[T any](arr []T) (Array, error)

MakeArrayBuffReadonly 创建只读array

func MakeArrayReadonly added in v0.1.88

func MakeArrayReadonly[T any](arr []T) (Array, error)

MakeArrayReadonly 创建只读array

func (Array) Indirect

func (v Array) Indirect() any

Indirect 原始值

func (Array) Read

func (v Array) Read(p []byte) (int, error)

Read implements io.Reader

func (Array) Release added in v0.1.90

func (v Array) Release()

Release 释放资源

func (Array) Size

func (v Array) Size() int

Size 大小

func (Array) TypeId added in v0.1.57

func (Array) TypeId() TypeId

TypeId 类型

func (*Array) Write

func (v *Array) Write(p []byte) (int, error)

Write implements io.Writer

type Bool

type Bool bool

Bool builtin bool

func (Bool) Indirect

func (v Bool) Indirect() any

Indirect 原始值

func (Bool) Read

func (v Bool) Read(p []byte) (int, error)

Read implements io.Reader

func (Bool) Release added in v0.1.90

func (Bool) Release()

Release 释放资源

func (Bool) Size

func (Bool) Size() int

Size 大小

func (Bool) TypeId added in v0.1.57

func (Bool) TypeId() TypeId

TypeId 类型

func (*Bool) Write

func (v *Bool) Write(p []byte) (int, error)

Write implements io.Writer

type Byte

type Byte byte

Byte builtin byte

func (Byte) Indirect

func (v Byte) Indirect() any

Indirect 原始值

func (Byte) Read

func (v Byte) Read(p []byte) (int, error)

Read implements io.Reader

func (Byte) Release added in v0.1.90

func (Byte) Release()

Release 释放资源

func (Byte) Size

func (Byte) Size() int

Size 大小

func (Byte) TypeId added in v0.1.57

func (Byte) TypeId() TypeId

TypeId 类型

func (*Byte) Write

func (v *Byte) Write(p []byte) (int, error)

Write implements io.Writer

type Bytes

type Bytes []byte

Bytes bytes

func (Bytes) Indirect

func (v Bytes) Indirect() any

Indirect 原始值

func (Bytes) Read

func (v Bytes) Read(p []byte) (int, error)

Read implements io.Reader

func (Bytes) Release added in v0.1.90

func (Bytes) Release()

Release 释放资源

func (Bytes) Size

func (v Bytes) Size() int

Size 大小

func (Bytes) TypeId added in v0.1.57

func (Bytes) TypeId() TypeId

TypeId 类型

func (*Bytes) Write

func (v *Bytes) Write(p []byte) (int, error)

Write implements io.Writer

type Call added in v0.1.69

type Call struct {
	Src, Transit string
}

type CallChain added in v0.1.69

type CallChain []Call

func (CallChain) First added in v0.1.92

func (v CallChain) First() Call

func (CallChain) Indirect added in v0.1.69

func (v CallChain) Indirect() any

Indirect 原始值

func (CallChain) Last added in v0.1.92

func (v CallChain) Last() Call

func (CallChain) Read added in v0.1.69

func (v CallChain) Read(p []byte) (int, error)

Read implements io.Reader

func (CallChain) Release added in v0.1.90

func (CallChain) Release()

Release 释放资源

func (CallChain) Size added in v0.1.69

func (v CallChain) Size() int

Size 大小

func (CallChain) TypeId added in v0.1.69

func (CallChain) TypeId() TypeId

TypeId 类型

func (*CallChain) Write added in v0.1.69

func (v *CallChain) Write(p []byte) (int, error)

Write implements io.Writer

type Double

type Double float64

Double builtin double

func (Double) Indirect

func (v Double) Indirect() any

Indirect 原始值

func (Double) Read

func (v Double) Read(p []byte) (int, error)

Read implements io.Reader

func (Double) Release added in v0.1.90

func (Double) Release()

Release 释放资源

func (Double) Size

func (Double) Size() int

Size 大小

func (Double) TypeId added in v0.1.57

func (Double) TypeId() TypeId

TypeId 类型

func (*Double) Write

func (v *Double) Write(p []byte) (int, error)

Write implements io.Writer

type Error

type Error struct {
	Code    int32
	Message string
}

Error builtin error

func Errorf added in v0.1.92

func Errorf(code int32, format string, args ...any) *Error

func Errorln added in v0.1.92

func Errorln(code int32, message string) *Error

func MakeError

func MakeError(err error) *Error

func (Error) Error

func (v Error) Error() string

func (*Error) Indirect

func (v *Error) Indirect() any

Indirect 原始值

func (Error) OK

func (v Error) OK() bool

func (Error) Read

func (v Error) Read(p []byte) (int, error)

Read implements io.Reader

func (Error) Release added in v0.1.90

func (Error) Release()

Release 释放资源

func (Error) Size

func (v Error) Size() int

Size 大小

func (Error) TypeId added in v0.1.57

func (Error) TypeId() TypeId

TypeId 类型

func (*Error) Write

func (v *Error) Write(p []byte) (int, error)

Write implements io.Writer

type Float

type Float float32

Float builtin float

func (Float) Indirect

func (v Float) Indirect() any

Indirect 原始值

func (Float) Read

func (v Float) Read(p []byte) (int, error)

Read implements io.Reader

func (Float) Release added in v0.1.90

func (Float) Release()

Release 释放资源

func (Float) Size

func (Float) Size() int

Size 大小

func (Float) TypeId added in v0.1.57

func (Float) TypeId() TypeId

TypeId 类型

func (*Float) Write

func (v *Float) Write(p []byte) (int, error)

Write implements io.Writer

type IVariantCreator

type IVariantCreator interface {
	// Declare 注册类型
	Declare(v Value)
	// Undeclare 取消注册类型
	Undeclare(typeId TypeId)
	// New 创建对象指针
	New(typeId TypeId) (Value, error)
	// NewReflected 创建反射对象指针
	NewReflected(typeId TypeId) (reflect.Value, error)
}

IVariantCreator 可变类型对象构建器接口

func VariantCreator

func VariantCreator() IVariantCreator

VariantCreator 可变类型对象构建器

type Int

type Int int

Int builtin int

func (Int) Indirect

func (v Int) Indirect() any

Indirect 原始值

func (Int) Read

func (v Int) Read(p []byte) (int, error)

Read implements io.Reader

func (Int) Release added in v0.1.90

func (Int) Release()

Release 释放资源

func (Int) Size

func (v Int) Size() int

Size 大小

func (Int) TypeId added in v0.1.57

func (Int) TypeId() TypeId

TypeId 类型

func (*Int) Write

func (v *Int) Write(p []byte) (int, error)

Write implements io.Writer

type Int16

type Int16 int16

Int16 builtin int16

func (Int16) Indirect

func (v Int16) Indirect() any

Indirect 原始值

func (Int16) Read

func (v Int16) Read(p []byte) (int, error)

Read implements io.Reader

func (Int16) Release added in v0.1.90

func (Int16) Release()

Release 释放资源

func (Int16) Size

func (Int16) Size() int

Size 大小

func (Int16) TypeId added in v0.1.57

func (Int16) TypeId() TypeId

TypeId 类型

func (*Int16) Write

func (v *Int16) Write(p []byte) (int, error)

Write implements io.Writer

type Int32

type Int32 int32

Int32 builtin int32

func (Int32) Indirect

func (v Int32) Indirect() any

Indirect 原始值

func (Int32) Read

func (v Int32) Read(p []byte) (int, error)

Read implements io.Reader

func (Int32) Release added in v0.1.90

func (Int32) Release()

Release 释放资源

func (Int32) Size

func (Int32) Size() int

Size 大小

func (Int32) TypeId added in v0.1.57

func (Int32) TypeId() TypeId

TypeId 类型

func (*Int32) Write

func (v *Int32) Write(p []byte) (int, error)

Write implements io.Writer

type Int64

type Int64 int64

Int64 builtin int64

func (Int64) Indirect

func (v Int64) Indirect() any

Indirect 原始值

func (Int64) Read

func (v Int64) Read(p []byte) (int, error)

Read implements io.Reader

func (Int64) Release added in v0.1.90

func (Int64) Release()

Release 释放资源

func (Int64) Size

func (v Int64) Size() int

Size 大小

func (Int64) TypeId added in v0.1.57

func (Int64) TypeId() TypeId

TypeId 类型

func (*Int64) Write

func (v *Int64) Write(p []byte) (int, error)

Write implements io.Writer

type Int8

type Int8 int8

Int8 builtin int8

func (Int8) Indirect

func (v Int8) Indirect() any

Indirect 原始值

func (Int8) Read

func (v Int8) Read(p []byte) (int, error)

Read implements io.Reader

func (Int8) Release added in v0.1.90

func (Int8) Release()

Release 释放资源

func (Int8) Size

func (Int8) Size() int

Size 大小

func (Int8) TypeId added in v0.1.57

func (Int8) TypeId() TypeId

TypeId 类型

func (*Int8) Write

func (v *Int8) Write(p []byte) (int, error)

Write implements io.Writer

type Map

Map map

func MakeMapReadonlyFromGoMap added in v0.1.88

func MakeMapReadonlyFromGoMap[K comparable, V any](m map[K]V) (Map, error)

MakeMapReadonlyFromGoMap 创建只读map

func MakeMapReadonlyFromSliceMap added in v0.1.88

func MakeMapReadonlyFromSliceMap[K cmp.Ordered, V any](m generic.SliceMap[K, V]) (Map, error)

MakeMapReadonlyFromSliceMap 创建只读map

func MakeMapReadonlyFromUnorderedSliceMap added in v0.1.88

func MakeMapReadonlyFromUnorderedSliceMap[K comparable, V any](m generic.UnorderedSliceMap[K, V]) (Map, error)

MakeMapReadonlyFromUnorderedSliceMap 创建只读map

func (*Map) CastUnorderedSliceMap added in v0.1.88

func (v *Map) CastUnorderedSliceMap() *generic.UnorderedSliceMap[Variant, Variant]

CastUnorderedSliceMap 转换为UnorderedSliceMap

func (Map) Indirect

func (v Map) Indirect() any

Indirect 原始值

func (Map) Read

func (v Map) Read(p []byte) (int, error)

Read implements io.Reader

func (Map) Release added in v0.1.90

func (v Map) Release()

Release 释放资源

func (Map) Size

func (v Map) Size() int

Size 大小

func (Map) TypeId added in v0.1.57

func (Map) TypeId() TypeId

TypeId 类型

func (*Map) Write

func (v *Map) Write(p []byte) (int, error)

Write implements io.Writer

type Null

type Null struct{}

Null builtin null

func (Null) Indirect

func (Null) Indirect() any

Indirect 原始值

func (Null) Read

func (Null) Read(p []byte) (int, error)

Read implements io.Reader

func (Null) Release added in v0.1.90

func (Null) Release()

Release 释放资源

func (Null) Size

func (Null) Size() int

Size 大小

func (Null) TypeId added in v0.1.57

func (Null) TypeId() TypeId

TypeId 类型

func (Null) Write

func (Null) Write(p []byte) (int, error)

Write implements io.Writer

type String

type String string

String string

func (String) Indirect

func (v String) Indirect() any

Indirect 原始值

func (String) Read

func (v String) Read(p []byte) (int, error)

Read implements io.Reader

func (String) Release added in v0.1.90

func (String) Release()

Release 释放资源

func (String) Size

func (v String) Size() int

Size 大小

func (String) TypeId added in v0.1.57

func (String) TypeId() TypeId

TypeId 类型

func (*String) Write

func (v *String) Write(p []byte) (int, error)

Write implements io.Writer

type TypeId

type TypeId uint32

TypeId 类型Id

const (
	TypeId_None TypeId = iota
	TypeId_Int
	TypeId_Int8
	TypeId_Int16
	TypeId_Int32
	TypeId_Int64
	TypeId_Uint
	TypeId_Uint8
	TypeId_Uint16
	TypeId_Uint32
	TypeId_Uint64
	TypeId_Float
	TypeId_Double
	TypeId_Byte
	TypeId_Bool
	TypeId_Bytes
	TypeId_String
	TypeId_Null
	TypeId_Array
	TypeId_Map
	TypeId_Error
	TypeId_CallChain
	TypeId_Customize = 32 // 自定义类型起点
)

func MakeTypeId added in v0.1.57

func MakeTypeId(v any) TypeId

MakeTypeId 创建类型Id

func MakeTypeIdT added in v0.1.57

func MakeTypeIdT[T any]() TypeId

MakeTypeIdT 创建类型Id

func (TypeId) New

func (t TypeId) New() (Value, error)

New 创建对象指针

func (TypeId) NewReflected

func (t TypeId) NewReflected() (reflect.Value, error)

NewReflected 创建反射对象指针

func (TypeId) Read

func (t TypeId) Read(p []byte) (int, error)

Read implements io.Reader

func (TypeId) Size

func (t TypeId) Size() int

Size 大小

func (*TypeId) Write

func (t *TypeId) Write(p []byte) (int, error)

Write implements io.Writer

type Uint

type Uint uint

Uint builtin uint

func (Uint) Indirect

func (v Uint) Indirect() any

Indirect 原始值

func (Uint) Read

func (v Uint) Read(p []byte) (int, error)

Read implements io.Reader

func (Uint) Release added in v0.1.90

func (Uint) Release()

Release 释放资源

func (Uint) Size

func (v Uint) Size() int

Size 大小

func (Uint) TypeId added in v0.1.57

func (Uint) TypeId() TypeId

TypeId 类型

func (*Uint) Write

func (v *Uint) Write(p []byte) (int, error)

Write implements io.Writer

type Uint16

type Uint16 uint16

Uint16 builtin uint16

func (Uint16) Indirect

func (v Uint16) Indirect() any

Indirect 原始值

func (Uint16) Read

func (v Uint16) Read(p []byte) (int, error)

Read implements io.Reader

func (Uint16) Release added in v0.1.90

func (Uint16) Release()

Release 释放资源

func (Uint16) Size

func (Uint16) Size() int

Size 大小

func (Uint16) TypeId added in v0.1.57

func (Uint16) TypeId() TypeId

TypeId 类型

func (*Uint16) Write

func (v *Uint16) Write(p []byte) (int, error)

Write implements io.Writer

type Uint32

type Uint32 uint32

Uint32 builtin uint32

func (Uint32) Indirect

func (v Uint32) Indirect() any

Indirect 原始值

func (Uint32) Read

func (v Uint32) Read(p []byte) (int, error)

Read implements io.Reader

func (Uint32) Release added in v0.1.90

func (Uint32) Release()

Release 释放资源

func (Uint32) Size

func (Uint32) Size() int

Size 大小

func (Uint32) TypeId added in v0.1.57

func (Uint32) TypeId() TypeId

TypeId 类型

func (*Uint32) Write

func (v *Uint32) Write(p []byte) (int, error)

Write implements io.Writer

type Uint64

type Uint64 uint64

Uint64 builtin uint64

func (Uint64) Indirect

func (v Uint64) Indirect() any

Indirect 原始值

func (Uint64) Read

func (v Uint64) Read(p []byte) (int, error)

Read implements io.Reader

func (Uint64) Release added in v0.1.90

func (Uint64) Release()

Release 释放资源

func (Uint64) Size

func (v Uint64) Size() int

Size 大小

func (Uint64) TypeId added in v0.1.57

func (Uint64) TypeId() TypeId

TypeId 类型

func (*Uint64) Write

func (v *Uint64) Write(p []byte) (int, error)

Write implements io.Writer

type Uint8

type Uint8 uint8

Uint8 builtin uint8

func (Uint8) Indirect

func (v Uint8) Indirect() any

Indirect 原始值

func (Uint8) Read

func (v Uint8) Read(p []byte) (int, error)

Read implements io.Reader

func (Uint8) Release added in v0.1.90

func (Uint8) Release()

Release 释放资源

func (Uint8) Size

func (Uint8) Size() int

Size 大小

func (Uint8) TypeId added in v0.1.57

func (Uint8) TypeId() TypeId

TypeId 类型

func (*Uint8) Write

func (v *Uint8) Write(p []byte) (int, error)

Write implements io.Writer

type Value

type Value interface {
	ValueReader
	ValueWriter
}

Value 值

type ValueBuff added in v0.1.90

type ValueBuff struct {
	Type TypeId
	Buff binaryutil.RecycleBytes
}

ValueBuff ValueBuff

func MakeValueBuff added in v0.1.90

func MakeValueBuff(v ValueReader) (*ValueBuff, error)

MakeValueBuff 创建ValueBuff

func (*ValueBuff) Indirect added in v0.1.90

func (v *ValueBuff) Indirect() any

Indirect 原始值

func (*ValueBuff) Read added in v0.1.90

func (v *ValueBuff) Read(p []byte) (int, error)

Read implements io.Reader

func (*ValueBuff) Release added in v0.1.90

func (v *ValueBuff) Release()

Release 释放资源

func (*ValueBuff) Size added in v0.1.90

func (v *ValueBuff) Size() int

Size 大小

func (*ValueBuff) TypeId added in v0.1.90

func (v *ValueBuff) TypeId() TypeId

TypeId 类型

type ValueReader

type ValueReader interface {
	io.Reader
	// Size 大小
	Size() int
	// TypeId 类型
	TypeId() TypeId
	// Indirect 原始值
	Indirect() any
	// Release 释放资源
	Release()
}

ValueReader 读取值

type ValueWriter

type ValueWriter interface {
	io.Writer
	// Size 大小
	Size() int
	// TypeId 类型
	TypeId() TypeId
}

ValueWriter 写入值

type Variant

type Variant struct {
	TypeId        TypeId        // 类型Id
	ValueReadonly ValueReader   // 只读值
	Value         Value         // 值
	Reflected     reflect.Value // 反射值
}

Variant 可变类型

func CastVariantReadonly added in v0.1.88

func CastVariantReadonly(a any) (Variant, error)

CastVariantReadonly 转换只读可变类型

func MakeVariantReadonly added in v0.1.88

func MakeVariantReadonly(v ValueReader) (Variant, error)

MakeVariantReadonly 创建只读可变类型

func (Variant) Read

func (v Variant) Read(p []byte) (int, error)

Read implements io.Reader

func (Variant) Readonly added in v0.1.88

func (v Variant) Readonly() bool

Readonly 只读

func (Variant) Size

func (v Variant) Size() int

Size 大小

func (Variant) Valid added in v0.1.88

func (v Variant) Valid() bool

Valid 有效

func (*Variant) Write

func (v *Variant) Write(p []byte) (int, error)

Write implements io.Writer

Jump to

Keyboard shortcuts

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