variant

package
v0.2.19 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 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

This section is empty.

Types

type Array

type Array []Variant

Array array

func MakeReadonlyArray added in v0.2.17

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

MakeReadonlyArray 创建只读array

func MakeSerializedArray added in v0.2.17

func MakeSerializedArray[T any](arr []T) (ret Array, err error)

MakeSerializedArray 创建已序列化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) 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) 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) 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 {
	Svc, Addr, 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) 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) 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) 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) 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) 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) 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) 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) 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) 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 MakeReadonlyMapFromGoMap added in v0.2.18

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

MakeReadonlyMapFromGoMap 创建只读map

func MakeReadonlyMapFromSliceMap added in v0.2.18

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

MakeReadonlyMapFromSliceMap 创建只读map

func MakeReadonlyMapFromUnorderedSliceMap added in v0.2.18

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

MakeReadonlyMapFromUnorderedSliceMap 创建只读map

func MakeSerializedMapFromGoMap added in v0.2.18

func MakeSerializedMapFromGoMap[K comparable, V any](m map[K]V) (ret Map, err error)

MakeSerializedMapFromGoMap 创建已序列化map

func MakeSerializedMapFromSliceMap added in v0.2.18

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

MakeSerializedMapFromSliceMap 创建已序列化map

func MakeSerializedMapFromUnorderedSliceMap added in v0.2.18

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

MakeSerializedMapFromUnorderedSliceMap 创建已序列化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) Release added in v0.1.90

func (v Map) Release()

Release 释放资源

func (Map) Size

func (v Map) Size() int

Size 大小

func (*Map) ToUnorderedSliceMap added in v0.1.96

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

ToUnorderedSliceMap 转换为UnorderedSliceMap

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) 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 SerializedValue added in v0.2.17

type SerializedValue struct {
	Type TypeId                  // 类型Id
	Data binaryutil.RecycleBytes // 数据
}

SerializedValue 已序列化值

func MakeSerializedValue added in v0.2.17

func MakeSerializedValue(v ValueReader) (ret *SerializedValue, err error)

MakeSerializedValue 创建已序列化值

func (*SerializedValue) Indirect added in v0.2.17

func (v *SerializedValue) Indirect() any

Indirect 原始值

func (*SerializedValue) Read added in v0.2.17

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

Read implements io.Reader

func (*SerializedValue) Release added in v0.2.17

func (v *SerializedValue) Release()

Release 释放资源

func (*SerializedValue) Size added in v0.2.17

func (v *SerializedValue) Size() int

Size 大小

func (*SerializedValue) TypeId added in v0.2.17

func (v *SerializedValue) TypeId() TypeId

TypeId 类型

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

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

ValueReader 读取值

type ValueWriter

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

ValueWriter 写入值

type Variant

type Variant struct {
	TypeId          TypeId           // 类型Id
	Value           Value            // 值
	Reflected       reflect.Value    // 反射值
	ReadonlyValue   ValueReader      // 只读值
	SerializedValue *SerializedValue // 已序列化值
}

Variant 可变类型

func CastReadonlyVariant added in v0.2.17

func CastReadonlyVariant(a any) (Variant, error)

CastReadonlyVariant 转换只读可变类型

func CastSerializedVariant added in v0.2.17

func CastSerializedVariant(a any) (ret Variant, err error)

CastSerializedVariant 转换已序列化可变类型

func MakeReadonlyVariant added in v0.2.17

func MakeReadonlyVariant(v ValueReader) (Variant, error)

MakeReadonlyVariant 创建只读可变类型

func MakeSerializedVariant added in v0.2.17

func MakeSerializedVariant(v ValueReader) (Variant, error)

MakeSerializedVariant 创建已序列化可变类型

func (Variant) Convert added in v0.2.17

func (v Variant) Convert(valueRT reflect.Type) (reflect.Value, error)

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) Serialized added in v0.2.17

func (v Variant) Serialized() bool

Serialized 是否已序列化

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