variant

package
v0.1.53 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: LGPL-2.1 Imports: 7 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotVariant    = errors.New("gap: not variant")            // 非可变类型
	ErrNotRegistered = errors.New("gap: variant not registered") // 类型未注册
)

Functions

This section is empty.

Types

type Array

type Array []Variant

Array 数组

func MakeArray

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

MakeArray 创建可变类型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) Size

func (v Array) Size() int

Size 大小

func (Array) Type

func (Array) Type() TypeId

Type 类型

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) Size

func (Bool) Size() int

Size 大小

func (Bool) Type

func (Bool) Type() TypeId

Type 类型

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) Size

func (Byte) Size() int

Size 大小

func (Byte) Type

func (Byte) Type() TypeId

Type 类型

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) Size

func (v Bytes) Size() int

Size 大小

func (Bytes) Type

func (Bytes) Type() TypeId

Type 类型

func (*Bytes) Write

func (v *Bytes) 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) Size

func (Double) Size() int

Size 大小

func (Double) Type

func (Double) Type() TypeId

Type 类型

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 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) Size

func (v Error) Size() int

Size 大小

func (Error) Type

func (Error) Type() TypeId

Type 类型

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) Size

func (Float) Size() int

Size 大小

func (Float) Type

func (Float) Type() TypeId

Type 类型

func (*Float) Write

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

Write implements io.Writer

type IVariantCreator

type IVariantCreator interface {
	// Register 注册类型
	Register(v Value)
	// Deregister 取消注册类型
	Deregister(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) Size

func (v Int) Size() int

Size 大小

func (Int) Type

func (Int) Type() TypeId

Type 类型

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) Size

func (Int16) Size() int

Size 大小

func (Int16) Type

func (Int16) Type() TypeId

Type 类型

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) Size

func (Int32) Size() int

Size 大小

func (Int32) Type

func (Int32) Type() TypeId

Type 类型

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) Size

func (v Int64) Size() int

Size 大小

func (Int64) Type

func (Int64) Type() TypeId

Type 类型

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) Size

func (Int8) Size() int

Size 大小

func (Int8) Type

func (Int8) Type() TypeId

Type 类型

func (*Int8) Write

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

Write implements io.Writer

type KV

type KV struct {
	K, V Variant
}

KV kv

type Map

type Map []KV

Map map

func MakeMap

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

MakeMap 创建可变类型map

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) Size

func (v Map) Size() int

Size 大小

func (Map) Type

func (Map) Type() TypeId

Type 类型

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) Size

func (Null) Size() int

Size 大小

func (Null) Type

func (Null) Type() TypeId

Type 类型

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) Size

func (v String) Size() int

Size 大小

func (String) Type

func (String) Type() TypeId

Type 类型

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_Customize = 128 // 自定义类型起点
)

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) Size

func (v Uint) Size() int

Size 大小

func (Uint) Type

func (Uint) Type() TypeId

Type 类型

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) Size

func (Uint16) Size() int

Size 大小

func (Uint16) Type

func (Uint16) Type() TypeId

Type 类型

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) Size

func (Uint32) Size() int

Size 大小

func (Uint32) Type

func (Uint32) Type() TypeId

Type 类型

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) Size

func (v Uint64) Size() int

Size 大小

func (Uint64) Type

func (Uint64) Type() TypeId

Type 类型

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) Size

func (Uint8) Size() int

Size 大小

func (Uint8) Type

func (Uint8) Type() TypeId

Type 类型

func (*Uint8) Write

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

Write implements io.Writer

type Value

type Value interface {
	ValueReader
	ValueWriter
}

Value 值

type ValueReader

type ValueReader interface {
	io.Reader
	// Size 大小
	Size() int
	// Type 类型
	Type() TypeId
	// Indirect 原始值
	Indirect() any
}

ValueReader 读取值

type ValueWriter

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

ValueWriter 写入值

type Variant

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

Variant 可变类型

func CastVariant

func CastVariant(a any) (Variant, error)

CastVariant 转换为可变类型

func MakeVariant

func MakeVariant(v ValueReader) (Variant, error)

MakeVariant 创建可变类型

func (Variant) Read

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

Read implements io.Reader

func (Variant) Size

func (v Variant) Size() int

Size 大小

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