internal

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilValue          = errors.New("input value is nil")
	ErrUnsupportedType   = errors.New("unsupported type")
	ErrConversionFailed  = errors.New("conversion failed")
	ErrOverflow          = errors.New("value overflow")
	ErrInvalidFormat     = errors.New("invalid format")
	ErrInvalidTimeFormat = errors.New("invalid time format")
	ErrInvalidJSONFormat = errors.New("invalid JSON format")
)

define errors

Functions

func AddStringToCache

func AddStringToCache(value interface{}, result string)

AddStringToCache adds string to cache.

func AddTimeToCache

func AddTimeToCache(value interface{}, result time.Time)

AddTimeToCache adds time to cache.

func CacheConversion

func CacheConversion(source, target reflect.Type, convertible bool)

CacheConversion caches a type conversion result

func ClearAllCaches

func ClearAllCaches()

ClearAllCaches clears all caches

func ClearAllReflectCaches

func ClearAllReflectCaches()

ClearAllReflectCaches clears all reflection-related caches

func ClearConversionCache

func ClearConversionCache()

ClearConversionCache clears the type conversion cache

func ClearDecoderCache added in v1.1.0

func ClearDecoderCache()

ClearDecoderCache clears the decoder cache.

func ClearStringCache

func ClearStringCache()

Clear string cache

func ClearTimeCache

func ClearTimeCache()

Clear time cache

func ClearTypeInfoCache

func ClearTypeInfoCache()

ClearTypeInfoCache clears the type information cache

func GetCachedConversion

func GetCachedConversion(source, target reflect.Type) (bool, bool)

GetCachedConversion gets a cached type conversion result

func GetStringFromCache

func GetStringFromCache(value interface{}) (string, bool)

GetStringFromCache gets string from cache.

func GetTimeFromCache

func GetTimeFromCache(value interface{}) (time.Time, bool)

GetTimeFromCache gets time from cache.

func SetConversionCacheSize

func SetConversionCacheSize(size int)

SetConversionCacheSize sets the type conversion cache size

func SetDecoder added in v1.1.0

func SetDecoder(key DecoderCacheKey, decoder *Decoder)

SetDecoder stores a decoder in the cache.

func SetStringCacheSize

func SetStringCacheSize(size int)

Set string cache size

func SetTimeCacheSize

func SetTimeCacheSize(size int)

Set time cache size

func SetTypeInfoCacheSize

func SetTypeInfoCacheSize(size int)

SetTypeInfoCacheSize sets the type information cache size

Types

type ConversionError

type ConversionError struct {
	Value      interface{}
	Type       string
	TargetType string
	Err        error
}

ConversionError represents a conversion error.

func NewConversionError

func NewConversionError(value interface{}, targetType string, err error) *ConversionError

NewConversionError creates a new conversion error.

func (*ConversionError) Error

func (e *ConversionError) Error() string

Error implements the error interface.

func (*ConversionError) Unwrap

func (e *ConversionError) Unwrap() error

Unwrap returns the underlying error.

type ConversionPair

type ConversionPair struct {
	Source reflect.Type
	Target reflect.Type
}

ConversionPair represents a source-target type pair for conversion caching

type Decoder added in v1.1.0

type Decoder struct {
	// Fields is a map from the source map key to the field decoder.
	// It's used for fast lookups.
	Fields map[string]*FieldDecoder
	// FieldArr is an array of all field decoders.
	FieldArr []*FieldDecoder
}

Decoder holds the complete decoding plan for a struct type.

func GetDecoder added in v1.1.0

func GetDecoder(key DecoderCacheKey) (*Decoder, bool)

GetDecoder gets a decoder for a given type from the cache.

type DecoderCacheKey added in v1.1.0

type DecoderCacheKey struct {
	DestType reflect.Type
	NumHooks int
}

DecoderCacheKey is the key for the decoder cache. It includes the destination type and the number of hooks, as different hooks can result in different decoding plans.

type FieldDecoder added in v1.1.0

type FieldDecoder struct {
	// Field represents the struct field to be decoded into.
	Field reflect.StructField
	// Index is the field's index in the struct.
	Index []int
	// Name is the key name in the source map to look for.
	Name string
}

FieldDecoder holds the decoding plan for a single struct field.

type TypeInfo

type TypeInfo struct {
	// Basic type information
	Type        reflect.Type
	Kind        reflect.Kind
	IsBasic     bool
	IsContainer bool

	// Struct field information
	Fields     map[string]reflect.StructField
	FieldNames []string

	// Method information
	Methods map[string]reflect.Method

	// Type conversion information
	ConvertibleTo map[reflect.Type]bool
	AssignableTo  map[reflect.Type]bool
}

TypeInfo stores reflection information about a type

func GetTypeInfo

func GetTypeInfo(t reflect.Type) *TypeInfo

GetTypeInfo gets reflection information about a type, preferably from cache

func (*TypeInfo) IsAssignableTo

func (ti *TypeInfo) IsAssignableTo(target reflect.Type) bool

IsAssignableTo checks if the type can be assigned to the target type, result is cached

func (*TypeInfo) IsConvertibleTo

func (ti *TypeInfo) IsConvertibleTo(target reflect.Type) bool

IsConvertibleTo checks if the type can be converted to the target type, result is cached

Jump to

Keyboard shortcuts

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