parent
775d64b147
commit
c11ba8fdb4
@ -0,0 +1,99 @@
|
||||
// =============================================================================
|
||||
// GO·AT Framework
|
||||
// Copyright (c) 2025 ActiveThing (https://activething.com)
|
||||
// Author: Juan V. Navarro juanvnl@activething.com
|
||||
// =============================================================================
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
// =============================================================================
|
||||
// Date Create 12/06/2025
|
||||
// =============================================================================
|
||||
|
||||
package cdts
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto"
|
||||
"fmt"
|
||||
"math"
|
||||
"math/big"
|
||||
"reflect"
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
Bytes = []uint8
|
||||
Stack = []struct{ Line string }
|
||||
UUID = [16]byte
|
||||
|
||||
Reflect = reflect.Value
|
||||
Date = time.Time
|
||||
Duration= time.Duration
|
||||
|
||||
Stringer= fmt.Stringer
|
||||
|
||||
BigInt = big.Int
|
||||
HashAlg = crypto.Hash
|
||||
|
||||
Packable= interface { P () }
|
||||
MapPackable = interface { Map () }
|
||||
ListPackable = interface { List () }
|
||||
ObjPackable = interface { Object () }
|
||||
|
||||
Context = context.Context
|
||||
|
||||
|
||||
ints interface { int | int8 | int16 | int32 | int64 }
|
||||
uints interface { uint | uint8 | uint16 | uint32 | uint64 | uintptr | Duration | HashAlg }
|
||||
cmplx interface { complex64 | complex128 }
|
||||
lists interface { Bytes | Stack }
|
||||
)
|
||||
|
||||
|
||||
|
||||
var (
|
||||
|
||||
|
||||
g = struct {
|
||||
bigZero *BigInt
|
||||
uuidZero UUID
|
||||
maxCBType CBType
|
||||
maxCCType CCType
|
||||
|
||||
minTime,
|
||||
maxTime time.Time
|
||||
}{
|
||||
uuidZero : UUID{},
|
||||
bigZero : big.NewInt(0),
|
||||
maxCCType: ccMaxType,
|
||||
maxCBType: cbMaxType,
|
||||
|
||||
minTime: time.Unix(0, math.MinInt64),
|
||||
maxTime: time.Unix(0, math.MaxInt64),
|
||||
}
|
||||
|
||||
E = struct {
|
||||
|
||||
InvalidReflectValue string
|
||||
}{
|
||||
InvalidReflectValue: "::invalid_reflect_value",
|
||||
}
|
||||
)
|
||||
@ -0,0 +1,109 @@
|
||||
// =============================================================================
|
||||
// GO·AT Framework
|
||||
// Copyright (c) 2025 ActiveThing (https://activething.com)
|
||||
// Author: Juan V. Navarro juanvnl@activething.com
|
||||
// =============================================================================
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
// =============================================================================
|
||||
// Date Create 12/06/2025
|
||||
// =============================================================================
|
||||
|
||||
package cdts
|
||||
|
||||
|
||||
const (
|
||||
|
||||
CBTypeInvalid CBType = iota
|
||||
|
||||
CBTypeAny
|
||||
|
||||
CBTypeBool
|
||||
|
||||
CBTypeInt
|
||||
CBTypeInt8
|
||||
CBTypeInt16
|
||||
CBTypeInt32
|
||||
CBTypeInt64
|
||||
|
||||
CBTypeUint
|
||||
CBTypeUint8
|
||||
CBTypeUint16
|
||||
CBTypeUint32
|
||||
CBTypeUint64
|
||||
CBTypeUintptr
|
||||
CBTypeDuration
|
||||
|
||||
CBTypeFloat32
|
||||
CBTypeFloat64
|
||||
CBTypeComplex64
|
||||
CBTypeComplex128
|
||||
|
||||
|
||||
CBTypeBigInt
|
||||
CBTypeHashAlg
|
||||
|
||||
CBTypeString
|
||||
CBTypeUUID
|
||||
CBTypeBytes
|
||||
CBTypeStack
|
||||
|
||||
CBTypeDate
|
||||
CBTypeCValue
|
||||
CBTypeReflect
|
||||
|
||||
|
||||
CBTypeListPackable
|
||||
CBTypeMapPackable
|
||||
CBTypeObjPackable
|
||||
CBTypePackable
|
||||
|
||||
|
||||
CBTypeContext
|
||||
CBTypeError
|
||||
CBTypeStringer
|
||||
|
||||
CBTypeNil
|
||||
|
||||
cbMaxType
|
||||
|
||||
)
|
||||
|
||||
|
||||
type CBType uint8
|
||||
|
||||
func (c CBType) Check() CBType {
|
||||
if c >= g.maxCBType {
|
||||
return CBTypeInvalid
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func (c CBType) IsValid() bool { return c > CBTypeInvalid && c < g.maxCBType }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,214 @@
|
||||
// =============================================================================
|
||||
// GO·AT Framework
|
||||
// Copyright (c) 2025 ActiveThing (https://activething.com)
|
||||
// Author: Juan V. Navarro juanvnl@activething.com
|
||||
// =============================================================================
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
// =============================================================================
|
||||
// Date Create 13/06/2025
|
||||
// =============================================================================
|
||||
|
||||
package cdts
|
||||
|
||||
|
||||
type (
|
||||
|
||||
cBTypeInfo struct {
|
||||
valType CBType
|
||||
name string
|
||||
cByVal,
|
||||
cByPtr,
|
||||
cByLazy,
|
||||
cByList func(any) CValue
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
|
||||
func newCVTypeInfo (cbtype CBType, name string, opts ...func(info *cBTypeInfo)) *cBTypeInfo {
|
||||
vi := &cBTypeInfo{
|
||||
valType: cbtype,
|
||||
name : name,
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(vi)
|
||||
}
|
||||
return vi
|
||||
}
|
||||
|
||||
|
||||
|
||||
func optInvalidCreators() func(*cBTypeInfo) {
|
||||
return func (i *cBTypeInfo) {
|
||||
i.cByVal = createCInvalid
|
||||
i.cByPtr = createCInvalid
|
||||
i.cByLazy = createCInvalid
|
||||
i.cByList = createCInvalid
|
||||
}
|
||||
}
|
||||
|
||||
func optSameCreators (cf func(any) CValue) func(info *cBTypeInfo) {
|
||||
return func(i *cBTypeInfo) {
|
||||
i.cByVal = cf
|
||||
i.cByPtr = cf
|
||||
i.cByLazy = cf
|
||||
i.cByList = cf
|
||||
}
|
||||
}
|
||||
|
||||
func optWithCreators(cvalue, cptr, clazy, clist func(any) CValue) func (*cBTypeInfo) {
|
||||
return func ( i *cBTypeInfo) {
|
||||
i.cByVal = cvalue
|
||||
i.cByPtr = cptr
|
||||
i.cByLazy = clazy
|
||||
i.cByList = clist
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func optAnyCreators [T any](byValueFn func(v T) CValue) func (*cBTypeInfo) {
|
||||
var cf func(any) CValue
|
||||
if byValueFn != nil {
|
||||
cf = func(v any) CValue {
|
||||
return byValueFn(v.(T))
|
||||
}
|
||||
} else {
|
||||
cf = CreateCAny
|
||||
}
|
||||
return func (i *cBTypeInfo) {
|
||||
i.cByVal = cf
|
||||
i.cByPtr = CreateCAny
|
||||
i.cByLazy = CreateCAny
|
||||
i.cByList = CreateCAny
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
func optAnyPCreators [T any](byPtrFnc func(v *T) CValue) func (*cBTypeInfo) {
|
||||
return func(i *cBTypeInfo) {
|
||||
cf := func(v any) CValue { return byPtrFnc(v.(*T)) }
|
||||
i.cByPtr = cf
|
||||
i.cByList= buildCreatorPByList[T](i.valType)
|
||||
i.cByLazy= buildCreatorPByLazy[T](i.valType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
func optNormalCreators [T any](byValueFn func(v T) CValue) func(*cBTypeInfo) {
|
||||
return func(i *cBTypeInfo) {
|
||||
vf := func(v any) CValue { return byValueFn(v.(T))}
|
||||
i.cByVal = vf
|
||||
i.cByPtr = buildCreatorByPtr [T](i.valType,byValueFn)
|
||||
i.cByList = buildCreatorByList[T](i.valType)
|
||||
i.cByLazy = buildCreatorByLazy[T](i.valType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
func buildCreatorByPtr [T any](cbType CBType, byValueFn func(v T) CValue) func(any) CValue {
|
||||
return func(v any) CValue {
|
||||
vf := byValueFn
|
||||
vl,ok := v.(*T)
|
||||
if !ok {
|
||||
//todo error
|
||||
}
|
||||
if vl == nil {
|
||||
return CValue{CVType: CVType{ v: cbType}, CState: CStateNil}
|
||||
}
|
||||
return vf(*vl)
|
||||
}
|
||||
}
|
||||
|
||||
func buildCreatorByList[T any](btype CBType) func(any) CValue {
|
||||
return func(v any) CValue {
|
||||
vl,ok := v.([]T)
|
||||
if !ok {
|
||||
//todo error
|
||||
}
|
||||
vt := CreateCVTypeList(btype)
|
||||
ln := len(vl)
|
||||
vs := CStateZero
|
||||
if ln == 0 {
|
||||
if vl == nil {
|
||||
return CValue{ CVType : vt , CState: CStateNil }
|
||||
}
|
||||
vs = CStateZero
|
||||
}
|
||||
return CValue{ CVType : vt , CState: vs, anyVal: vl, intVal: int64(ln) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func buildCreatorPByList[T any](btype CBType) func(any) CValue {
|
||||
return func(v any) CValue {
|
||||
vl,ok := v.([]*T)
|
||||
if !ok {
|
||||
//todo error
|
||||
}
|
||||
vt := CreateCVTypeList(btype)
|
||||
ln := len(vl)
|
||||
vs := CStateZero
|
||||
if ln == 0 {
|
||||
if vl == nil {
|
||||
return CValue{ CVType : vt , CState: CStateNil }
|
||||
}
|
||||
vs = CStateZero
|
||||
}
|
||||
return CValue{ CVType : vt , CState: vs, anyVal: vl, intVal: int64(ln) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
func buildCreatorByLazy[T any](btype CBType) func(any) CValue {
|
||||
return func(v any) CValue {
|
||||
vl,ok := v.(func()T)
|
||||
if !ok {
|
||||
//todo error
|
||||
}
|
||||
vt := CreateCVTypeLazy(btype)
|
||||
if vl == nil {
|
||||
return CValue{ CVType: vt, CState: CStateNil }
|
||||
}
|
||||
return CValue{ CVType: vt, anyVal: vl }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func buildCreatorPByLazy[T any](btype CBType) func(any) CValue {
|
||||
return func(v any) CValue {
|
||||
vl,ok := v.(func()*T)
|
||||
if !ok {
|
||||
//todo error
|
||||
}
|
||||
vt := CreateCVTypeLazy(btype)
|
||||
if vl == nil {
|
||||
return CValue{ CVType: vt, CState: CStateNil }
|
||||
}
|
||||
return CValue{ CVType: vt, anyVal: vl }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
// =============================================================================
|
||||
// GO·AT Framework
|
||||
// Copyright (c) 2025 ActiveThing (https://activething.com)
|
||||
// Author: Juan V. Navarro juanvnl@activething.com
|
||||
// =============================================================================
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
// =============================================================================
|
||||
// Date Create 12/06/2025
|
||||
// =============================================================================
|
||||
|
||||
package cdts
|
||||
|
||||
|
||||
const (
|
||||
|
||||
CCTypeNone CCType = iota
|
||||
CCTypeLazy
|
||||
CCTypeList
|
||||
CCTypeMap
|
||||
|
||||
ccMaxType
|
||||
)
|
||||
|
||||
|
||||
type CCType uint8
|
||||
|
||||
|
||||
func (c CCType) IsValid () bool { return c > CCTypeNone && c < g.maxCCType }
|
||||
|
||||
@ -0,0 +1,61 @@
|
||||
// =============================================================================
|
||||
// GO·AT Framework
|
||||
// Copyright (c) 2025 ActiveThing (https://activething.com)
|
||||
// Author: Juan V. Navarro juanvnl@activething.com
|
||||
// =============================================================================
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
// =============================================================================
|
||||
// Date Create 12/06/2025
|
||||
// =============================================================================
|
||||
|
||||
package cdts
|
||||
|
||||
|
||||
const (
|
||||
|
||||
CStateInvalid CState = 1 << iota
|
||||
CStateError
|
||||
CStateNil
|
||||
CStateZero
|
||||
CStateVersion
|
||||
CStateReflected
|
||||
CStateSensitive
|
||||
CStateEncoded
|
||||
|
||||
CStateNone CState = 0
|
||||
|
||||
cStateOps= CStateSensitive | CStateEncoded
|
||||
)
|
||||
|
||||
type CState uint8
|
||||
|
||||
|
||||
func (s CState) IsStateInvalid () bool { return s&CStateInvalid != 0 }
|
||||
func (s CState) IsStateError () bool { return s&CStateError != 0 }
|
||||
func (s CState) IsStateNil () bool { return s&CStateNil != 0 }
|
||||
func (s CState) IsStateZero () bool { return s&CStateZero != 0 }
|
||||
func (s CState) IsStateNilOrZero() bool { return s&(CStateZero |CStateNil) != 0 }
|
||||
func (s CState) IsStateVersion () bool { return s&CStateVersion != 0 }
|
||||
func (s CState) IsStateReflected() bool { return s&CStateReflected != 0 }
|
||||
func (s CState) IsStateSensitive() bool { return s&CStateSensitive != 0 }
|
||||
func (s CState) IsStateEncoded () bool { return s&CStateEncoded != 0 }
|
||||
|
||||
|
||||
@ -0,0 +1,257 @@
|
||||
// =============================================================================
|
||||
// GO·AT Framework
|
||||
// Copyright (c) 2025 ActiveThing (https://activething.com)
|
||||
// Author: Juan V. Navarro juanvnl@activething.com
|
||||
// =============================================================================
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
// =============================================================================
|
||||
// Date Create 12/06/2025
|
||||
// =============================================================================
|
||||
|
||||
package cdts
|
||||
|
||||
import (
|
||||
"math"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
|
||||
CValue struct {
|
||||
_ [0]func()
|
||||
|
||||
CVType
|
||||
CState
|
||||
|
||||
intVal int64
|
||||
strVal string
|
||||
anyVal any
|
||||
}
|
||||
)
|
||||
|
||||
func CreateCAny (v any) CValue {
|
||||
if v == nil {
|
||||
return CValue{ CVType: CVType{v: CBTypeAny }, CState : CStateNil }
|
||||
}
|
||||
return CValue{ CVType: CVType{v: CBTypeAny }, anyVal: v }
|
||||
}
|
||||
|
||||
func CreateCBool (v bool) CValue {
|
||||
if !v {
|
||||
return CValue{ CVType: CVType{ v: CBTypeBool }, CState : CStateZero}
|
||||
}
|
||||
return CValue{ CVType: CVType{ v: CBTypeBool }, intVal: 1 }
|
||||
}
|
||||
|
||||
func CreateCInt (v int ) CValue { return createCInts [int ](v,CBTypeInt )}
|
||||
func CreateCInt8 (v int8 ) CValue { return createCInts [int8 ](v,CBTypeInt8 )}
|
||||
func CreateCInt16 (v int16 ) CValue { return createCInts [int16 ](v,CBTypeInt16 )}
|
||||
func CreateCInt32 (v int32 ) CValue { return createCInts [int32 ](v,CBTypeInt32 )}
|
||||
func CreateCInt64 (v int64 ) CValue { return createCInts [int64 ](v,CBTypeInt64 )}
|
||||
|
||||
func CreateCUint (v uint ) CValue { return createCUints[uint ](v,CBTypeUint )}
|
||||
func CreateCUint8 (v uint8 ) CValue { return createCUints[uint8 ](v,CBTypeUint8 )}
|
||||
func CreateCUint16(v uint16) CValue { return createCUints[uint16](v,CBTypeUint16)}
|
||||
func CreateCUint32(v uint32) CValue { return createCUints[uint32](v,CBTypeUint32)}
|
||||
func CreateCUint64(v uint64) CValue { return createCUints[uint64](v,CBTypeUint64)}
|
||||
|
||||
func CreateCUintptr (v uintptr ) CValue { return createCUints[uintptr ](v,CBTypeUintptr )}
|
||||
func CreateCDuration(v Duration) CValue { return createCUints[Duration](v,CBTypeDuration)}
|
||||
|
||||
func CreateCFloat32 (v float32) CValue {
|
||||
if v == 0 {
|
||||
return CValue{ CVType: CVType{ v: CBTypeFloat32}, CState: CStateZero }
|
||||
}
|
||||
return CValue{ CVType: CVType{ v: CBTypeFloat32}, intVal: int64(math.Float32bits(v)) }
|
||||
}
|
||||
func CreateCFloat64 (v float64) CValue {
|
||||
if v == 0 {
|
||||
return CValue{ CVType: CVType{ v: CBTypeFloat64}, CState: CStateZero }
|
||||
}
|
||||
b := math.Float64bits(v)
|
||||
if b > math.MaxInt64 {
|
||||
return CValue{ CVType: CVType{ v: CBTypeFloat64 }, CState : CStateVersion, anyVal: v }
|
||||
}
|
||||
return CValue{ CVType: CVType{ v: CBTypeFloat64}, intVal: int64(b) }
|
||||
}
|
||||
|
||||
func CreateCComplex64 (v complex64 ) CValue { return createCCmplx[complex64 ](v,CBTypeComplex64 ) }
|
||||
func CreateCComplex128(v complex128) CValue { return createCCmplx[complex128](v,CBTypeComplex128) }
|
||||
|
||||
|
||||
func CreateCHashAlg(v HashAlg) CValue { return createCUints[HashAlg](v,CBTypeHashAlg ) }
|
||||
|
||||
func CreateCBigInt (v *BigInt) CValue {
|
||||
if v.Cmp(g.bigZero) == 0 {
|
||||
return CValue{ CVType: CVType{ v: CBTypeBigInt }, CState : CStateZero }
|
||||
}
|
||||
return CValue{ CVType: CVType{ v: CBTypeBigInt }, anyVal: v }
|
||||
}
|
||||
|
||||
|
||||
func CreateCString (v string) CValue {
|
||||
if v == "" {
|
||||
return CValue{ CVType: CVType{ v: CBTypeString }, CState : CStateZero }
|
||||
}
|
||||
return CValue{ CVType: CVType{ v: CBTypeString }, strVal: v }
|
||||
}
|
||||
|
||||
func CreateCBytes (v Bytes) CValue { return createCList[Bytes](v,CBTypeBytes) }
|
||||
|
||||
func CreateCStack (v Stack) CValue { return createCList[Stack](v,CBTypeStack) }
|
||||
|
||||
func CreateCUUID (v UUID) CValue {
|
||||
if v == g.uuidZero {
|
||||
return CValue{ CVType: CVType{ v: CBTypeUUID }, CState: CStateZero }
|
||||
}
|
||||
return CValue{ CVType: CVType{ v: CBTypeUUID }, anyVal: v }
|
||||
}
|
||||
|
||||
|
||||
|
||||
func CreateCDate (v Date) CValue {
|
||||
if v.IsZero() { // Comprobación directa para el valor cero
|
||||
return CValue{ CVType: CVType{ v: CBTypeDate }, CState: CStateZero}
|
||||
}
|
||||
if v.After(g.minTime) && v.Before(g.maxTime) {
|
||||
return CValue{ CVType: CVType{ v : CBTypeDate }, CState: CStateVersion, intVal: v.UnixNano(), anyVal: v.Location()}
|
||||
}
|
||||
return CValue{ CVType: CVType{ v : CBTypeDate }, anyVal: v }
|
||||
}
|
||||
|
||||
func CreateCCValue (v CValue) CValue { return CValue{ CVType: CVType{ v: CBTypeCValue }, anyVal: v } }
|
||||
|
||||
func CreateCReflect(v reflect.Value) CValue {
|
||||
if !v.IsValid() {
|
||||
return CValue{ CVType: CVType{ v: CBTypeReflect}, CState: CStateInvalid }
|
||||
}
|
||||
return CValue{ CVType: CVType{ v: CBTypeReflect}, anyVal: v }
|
||||
}
|
||||
|
||||
|
||||
func CreateCListPackable (v ListPackable ) CValue { return createCIfcs[ListPackable ](v,CBTypeListPackable )}
|
||||
func CreateCMapPackable (v MapPackable ) CValue { return createCIfcs[MapPackable ](v,CBTypeMapPackable )}
|
||||
func CreateCObjectPackable(v ObjPackable) CValue { return createCIfcs[ObjPackable](v, CBTypeObjPackable)}
|
||||
func CreateCPackable (v Packable ) CValue { return createCIfcs[Packable ](v,CBTypePackable )}
|
||||
|
||||
func CreateCContext (v Context) CValue { return createCIfcs[Context ](v,CBTypeContext) }
|
||||
|
||||
func CreateCError (v error ) CValue { return createCIfcs[error ](v,CBTypeError ) }
|
||||
|
||||
func CreateCStringer (v Stringer) CValue { return createCIfcs[Stringer](v,CBTypeStringer ) }
|
||||
|
||||
|
||||
func CreateCNil (_ any) CValue { return CValue{ CVType: CVType{ v: CBTypeNil }, CState: CStateNil } }
|
||||
|
||||
|
||||
func createCInvalid (_ any) CValue {
|
||||
return CValue{ CVType: CVType{ v: CBTypeInvalid}, CState : CStateInvalid }
|
||||
}
|
||||
|
||||
func createCInvalidError (value any, state CState, err string) CValue {
|
||||
s := CStateError|CStateInvalid
|
||||
if value == nil {
|
||||
s|=CStateNil
|
||||
}
|
||||
return CValue{ CVType: CVType{ v : CBTypeInvalid }, CState: s,strVal: err, anyVal: value }
|
||||
}
|
||||
|
||||
|
||||
func (v CValue) WithState (state CState) CValue {
|
||||
v.CState|= state&cStateOps
|
||||
return v
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
func createCInts [T ints ] (v T, t CBType) CValue {
|
||||
if v == 0 {
|
||||
return CValue{ CVType: CVType{ v: t }, CState : CStateZero }
|
||||
}
|
||||
return CValue{ CVType: CVType{ v: t }, intVal: int64(v) }
|
||||
}
|
||||
|
||||
func createCUints[T uints] (v T, t CBType) CValue {
|
||||
if v == 0 {
|
||||
return CValue{ CVType: CVType{ v: t }, CState : CStateZero }
|
||||
}
|
||||
if t == CBTypeUint64 || t == CBTypeUintptr && v > math.MaxInt64 {
|
||||
return CValue{ CVType: CVType{ v: t }, CState : CStateVersion, anyVal: v }
|
||||
}
|
||||
return CValue{ CVType: CVType{ v: t }, intVal: int64(v) }
|
||||
}
|
||||
|
||||
func createCCmplx[T cmplx] (v T, t CBType) CValue {
|
||||
if v == 0 {
|
||||
return CValue{ CVType: CVType{ v: t }, CState : CStateZero }
|
||||
}
|
||||
return CValue{ CVType: CVType{ v: t }, anyVal: v }
|
||||
}
|
||||
|
||||
func createCList [T lists] (v T, t CBType) CValue {
|
||||
if v == nil {
|
||||
return CValue{ CVType: CVType{ v: t }, CState : CStateNil }
|
||||
}
|
||||
ln := len(v)
|
||||
if ln == 0 {
|
||||
return CValue{ CVType: CVType{ v: t }, CState : CStateZero, anyVal: v }
|
||||
}
|
||||
return CValue{ CVType: CVType{ v: t }, anyVal: v , intVal: int64(ln)}
|
||||
}
|
||||
|
||||
func createCIfcs[T any] (v T, t CBType) CValue {
|
||||
if v == nil {
|
||||
return CValue{ CVType: CVType{ v: t }, CState : CStateNil }
|
||||
}
|
||||
return CValue{ CVType: CVType{ v: t }, anyVal: v }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,71 @@
|
||||
// =============================================================================
|
||||
// GO·AT Framework
|
||||
// Copyright (c) 2025 ActiveThing (https://activething.com)
|
||||
// Author: Juan V. Navarro juanvnl@activething.com
|
||||
// =============================================================================
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
// =============================================================================
|
||||
// Date Create 12/06/2025
|
||||
// =============================================================================
|
||||
|
||||
package cdts
|
||||
|
||||
|
||||
type (
|
||||
|
||||
CVType struct {
|
||||
v CBType // Define el tipo del valor
|
||||
k CBType // Indica el tipo de la key en caso de mapas
|
||||
c CCType // Indica el tipo de valor compuesto que es list o mapas
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
func CreateCVType(vtype CBType) CVType {
|
||||
return CVType{v: vtype.Check() } }
|
||||
|
||||
func CreateCVTypeLazy(vtype CBType) CVType {
|
||||
return CVType{ v: vtype.Check() , c: CCTypeLazy} }
|
||||
|
||||
func CreateCVTypeList(vtype CBType) CVType {
|
||||
return CVType{ v: vtype.Check() , c: CCTypeList} }
|
||||
|
||||
func CreateCVTypeMap(vtype, ktype CBType) CVType {
|
||||
return CVType{ v: vtype.Check(), k: ktype.Check(), c: CCTypeMap } }
|
||||
|
||||
|
||||
|
||||
func (i CVType) Type () (CBType, CCType) { return i.v, i.c }
|
||||
|
||||
func (i CVType) VType () CBType { return i.v }
|
||||
|
||||
func (i CVType) KType () CBType {
|
||||
// Si no es un tipo mapa, devolvemos
|
||||
// un tipo no valido
|
||||
if i.c != CCTypeMap {
|
||||
return CBTypeInvalid
|
||||
}
|
||||
return i.k
|
||||
}
|
||||
|
||||
func (i CVType) CType () CCType { return i.c }
|
||||
|
||||
|
||||
Loading…
Reference in new issue