From d6e54986056dbcb7e5fbe3aefc0f4114e04420ae Mon Sep 17 00:00:00 2001 From: dev Date: Wed, 11 Jun 2025 12:50:32 +0200 Subject: [PATCH] cdts creado, refinando ctype y cvalue --- .idea/dictionaries/project.xml | 2 + src/base/cdts/a.go | 54 ++ src/base/cdts/cstate.go | 81 +++ src/base/cdts/ctype.go | 223 +++++++ src/base/cdts/ctype_info.go | 103 ++++ src/base/cdts/ctype_infos.go | 557 ++++++++++++++++++ src/base/cdts/cvalue.go | 286 +++++++++ src/base/cdts/types.go | 50 ++ src/base/go.mod | 3 + src/core/errs/a.go | 228 +++++++ src/core/errs/causer.go | 45 ++ src/core/errs/causers.go | 45 ++ src/core/errs/err.go | 129 ++++ src/core/errs/error_list.go | 122 ++++ src/core/errs/format.go | 143 +++++ src/core/errs/format_options.go | 131 ++++ src/core/errs/format_show.go | 93 +++ src/core/errs/formatter.go | 47 ++ src/core/errs/meta.go | 86 +++ src/core/errs/meta_type.go | 52 ++ src/core/errs/metadata_provider.go | 45 ++ src/core/errs/panic_err.go | 72 +++ src/core/errs/param_err.go | 111 ++++ src/core/errs/severity.go | 60 ++ .../list_baler.go => pkrs/list_packer.go} | 6 +- .../{blrs/map_baler.go => pkrs/map_packer.go} | 6 +- .../object_baler.go => pkrs/object_packer.go} | 6 +- .../{blrs/baleable.go => pkrs/packable.go} | 8 +- src/core/{blrs/baler.go => pkrs/packer.go} | 15 +- src/core/vals/a.go | 17 +- src/core/vals/cattribute.go | 154 +++++ src/core/vals/cattribute_type.go | 74 +++ src/core/vals/cfield.go | 16 +- src/core/vals/cvalue.go | 230 ++++---- src/core/vals/cvalue_state.go | 18 +- src/core/vals/cvalue_type.go | 158 ++--- src/core/vals/cvalue_type_infos.go | 175 +++--- src/core/vals/types.go | 5 +- 38 files changed, 3345 insertions(+), 311 deletions(-) create mode 100644 src/base/cdts/a.go create mode 100644 src/base/cdts/cstate.go create mode 100644 src/base/cdts/ctype.go create mode 100644 src/base/cdts/ctype_info.go create mode 100644 src/base/cdts/ctype_infos.go create mode 100644 src/base/cdts/cvalue.go create mode 100644 src/base/cdts/types.go create mode 100644 src/base/go.mod create mode 100644 src/core/errs/a.go create mode 100644 src/core/errs/causer.go create mode 100644 src/core/errs/causers.go create mode 100644 src/core/errs/err.go create mode 100644 src/core/errs/error_list.go create mode 100644 src/core/errs/format.go create mode 100644 src/core/errs/format_options.go create mode 100644 src/core/errs/format_show.go create mode 100644 src/core/errs/formatter.go create mode 100644 src/core/errs/meta.go create mode 100644 src/core/errs/meta_type.go create mode 100644 src/core/errs/metadata_provider.go create mode 100644 src/core/errs/panic_err.go create mode 100644 src/core/errs/param_err.go create mode 100644 src/core/errs/severity.go rename src/core/{blrs/list_baler.go => pkrs/list_packer.go} (96%) rename src/core/{blrs/map_baler.go => pkrs/map_packer.go} (96%) rename src/core/{blrs/object_baler.go => pkrs/object_packer.go} (95%) rename src/core/{blrs/baleable.go => pkrs/packable.go} (95%) rename src/core/{blrs/baler.go => pkrs/packer.go} (90%) create mode 100644 src/core/vals/cattribute.go create mode 100644 src/core/vals/cattribute_type.go diff --git a/.idea/dictionaries/project.xml b/.idea/dictionaries/project.xml index 5627239..c0729a2 100644 --- a/.idea/dictionaries/project.xml +++ b/.idea/dictionaries/project.xml @@ -1,7 +1,9 @@ + ctype cval + cvalue ntype vstate vtype diff --git a/src/base/cdts/a.go b/src/base/cdts/a.go new file mode 100644 index 0000000..9d9c757 --- /dev/null +++ b/src/base/cdts/a.go @@ -0,0 +1,54 @@ +// ============================================================================= +// 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 11/06/2025 +// ============================================================================= + +package cdts + +import ( + "math" + "time" +) + +var ( + + g = struct { + minTime, + maxTime time.Time + }{ + minTime: time.Unix(0, math.MinInt64), + maxTime: time.Unix(0, math.MaxInt64), + } + + + E = struct { + InvalidCValueReflected, + InvalidCValueForType string + }{ + InvalidCValueReflected : "::invalid_reflect_value", + InvalidCValueForType : "::invalid_value_for_type", + } +) diff --git a/src/base/cdts/cstate.go b/src/base/cdts/cstate.go new file mode 100644 index 0000000..b33bcca --- /dev/null +++ b/src/base/cdts/cstate.go @@ -0,0 +1,81 @@ +// ============================================================================= +// 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 10/06/2025 +// ============================================================================= + +package cdts + +import "strings" + +const ( + + CStateInvalid CState = 1 << iota // El valor almacenado es un valor invalido + CStateNil // Indica que el valor es nulo + CStateZero // Indica que el valor tiene valor 0 + CStateReflected // Indica que el valor guardado es un value.reflect + CStateShort // Indica que el valor es la versión corta del valor, por ejemplo: los dates + CStateSensitive // Indica que el valor es delicado, por ejemplo no mostrar o no serializar + CStateEncoded // Indica que el valor está codificado + CStateError // Indica que el valor no ha podido ser establecido por un error que esta representado en el + // valor + + CStateNone CState = 0 + + CStateOps CState = CStateEncoded|CStateSensitive +) + + +type CState uint8 + + +func (s CState) HasInvalid () bool { return s&CStateInvalid != 0 } +func (s CState) HasNil () bool { return s&CStateNil != 0 } +func (s CState) HasZero () bool { return s&CStateZero != 0 } +func (s CState) HasReflected() bool { return s&CStateReflected != 0 } +func (s CState) HasShort () bool { return s&CStateShort != 0 } +func (s CState) HasSensitive() bool { return s&CStateSensitive != 0 } +func (s CState) HasEncoded () bool { return s&CStateEncoded != 0 } +func (s CState) HasError () bool { return s&CStateError != 0 } + +func (s CState) HasNilOrZero() bool { return s&(CStateZero|CStateNil) != 0 } + +func (s CState) setOption (options CState) CState { return s|(options&CStateOps) } + + +func (s CState) String() string { + states := [...]string{"invalid","nil","zero","reflected","short","sensitive","encoded","error"} + c := make([]string,0,4) + for i:=0; i<7; i++ { + if s& (1< 0 && g.classValidator.MatchString(value) +} + +// IsValidClass checks if a string is a valid class name according to the rules defined by classValidator. +func IsValidClass(class string) bool { + return len(class) > 0 && g.classValidator.MatchString(class) +} + +// IsValidSubclass checks if 'subclass' is a valid subclass name for the 'parent' error. +// It verifies that both the parent and subclass are valid names and that the subclass is not identical +// to the final name of the parent (to prevent subclasses from having the same name as their direct parent). +func IsValidSubclass(parent Err, subclass string) bool { + if !IsValidErr(string(parent)) { + return false + } + if !IsValidClass(subclass) { // Should this be IsValidSubclass name? + return false + } + + // Extract the final name of the parent class (e.g., "format" from "modulo::validation.format") + parentName := string(parent) + if idx := strings.LastIndex(parentName, errClassSep); idx != -1 { + parentFinalName := parentName[idx+len(errClassSep):] + return subclass != parentFinalName + } + // If no errClassSep, use the class name after errModuleSep + if c, h := strings.CutPrefix(parentName, errModuleSep); h { + return subclass != c + } + // If neither errClassSep nor errModuleSep is present, compare with the full parent name. + return subclass != parentName +} + diff --git a/src/core/errs/causer.go b/src/core/errs/causer.go new file mode 100644 index 0000000..1b7817c --- /dev/null +++ b/src/core/errs/causer.go @@ -0,0 +1,45 @@ +// ============================================================================= +// Active-GO 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 17/05/2025 +// ============================================================================= + +package errs + +type ( + // Causer is an interface that can be implemented by errors that have an underlying cause. + // It is similar to Go 1.13+'s Unwrap interface, but specifically for a single cause. + Causer interface { + // Cause returns the error that caused this error. + Cause() error + } + + // CauseFnc is a function type that implements the Causer interface. + // It allows an anonymous function or an existing function to act as a cause. + CauseFnc func() error +) + +// Cause implements the Causer interface for CauseFnc, executing the underlying function. +func (f CauseFnc) Cause() error { return f() } diff --git a/src/core/errs/causers.go b/src/core/errs/causers.go new file mode 100644 index 0000000..5389963 --- /dev/null +++ b/src/core/errs/causers.go @@ -0,0 +1,45 @@ +// ============================================================================= +// Active-GO 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 17/05/2025 +// ============================================================================= + +package errs + +type ( + // Causers is an interface that can be implemented by errors that have multiple underlying causes. + // This is useful for errors that aggregate failures from multiple operations. + Causers interface { + // Causes returns a slice of errors that caused this error. + Causes() []error + } + + // CausesFnc is a function type that implements the Causers interface. + // It allows an anonymous function or an existing function to act as a provider of multiple causes. + CausesFnc func() []error +) + +// Causes implements the Causers interface for CausesFnc, executing the underlying function. +func (f CausesFnc) Causes() []error { return f() } diff --git a/src/core/errs/err.go b/src/core/errs/err.go new file mode 100644 index 0000000..9a748a8 --- /dev/null +++ b/src/core/errs/err.go @@ -0,0 +1,129 @@ +// ============================================================================= +// Active-GO 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 07/05/2025 +// ============================================================================= + +package errs + +import ( + + "errors" + "strings" +) + +// Err is the fundamental type for structured errors in this package. +// It represents an error with a hierarchical class name (e.g., "module::class.subclass"). +// It implements the standard Go error interface. +type Err string + +// CreateErr creates a new Err instance with the provided string value. +// It validates that the value is a valid error name. +// Panics if the value is not valid. +func CreateErr(value string) Err { + if !IsValidErr(value) { + // Panics with an error indicating an invalid Err value and the cause (the parameter error). + panic(E.InvalidErrValue) + } + return Err(value) +} + +// Module extracts the module name from the error, if present. +// The module is the part before the first "::". +// Returns an empty string if no module is present. +func (e Err) Module() string { + // Uses strings.CutSuffix to find and remove the "::" suffix if it exists. + if m, h := strings.CutSuffix(string(e), errModuleSep); h { + return m + } + return "" +} + +// Class extracts the class name from the error. +// The class is the part after the first "::", or the full name if no module is present. +func (e Err) Class() string { + s := string(e) + // Uses strings.CutPrefix to find and remove the "::" prefix if it exists. + if n, h := strings.CutPrefix(s, errModuleSep); h { + return n + } + return s +} + +// Parent returns the parent error in the subclass hierarchy, if it exists. +// For example, for "module::class.subclass", it returns "module::class". +// The second boolean value is true if a parent was found, false otherwise. +func (e Err) Parent() (Err, bool) { + s := string(e) + // Finds the last class separator ".". + if idx := strings.LastIndex(s, errClassSep); idx != -1 { + // Returns the substring up to the last separator as the parent error. + return Err(s[:idx]), true + } + return "", false +} + +// Error implements the standard Go error interface. +// It returns the string representation of the error. +func (e Err) Error() string { return string(e) } + +// String implements the fmt.Stringer interface. +// It returns the string representation of the error. +func (e Err) String() string { return string(e) } + +// IsSubclassOf checks if this Err error is a subclass of the 'parent' error. +// It checks if the string of this error starts with the string of the parent followed by the class separator ".". +// It also verifies that the errors are not identical and that this error is longer than the parent. +// Returns false if the parent is not of type Err. +func (e Err) IsSubclassOf(parent error) bool { + var p Err + // Attempts to convert the parent error to type Err. + if errors.As(parent, &p) { + s, ps := string(e), string(p) + // Checks if the string of this error starts with the parent string + "." + // and if the strings are different and this one is longer. + return s != ps && len(s) > len(ps) && strings.HasPrefix(s, ps+errClassSep) + } + return false +} + +// Is implements Go 1.13+'s errors.Is interface. +// It checks if this Err error is equal to the 'target' error or if it is a subclass of 'target'. +// The exact check (e == target) is performed first. +func (e Err) Is(target error) bool { + // Exact check first: if this Err error is identical to the target (if the target is also Err). + var t Err + if errors.As(target, &t) && e == t { + return true + } + + // Hierarchy check: if this error is a subclass of the target. + return IsSubclassOf(e, target) +} + +// Unwrap implements Go 1.13+'s errors.Unwrap interface. +// For the base Err type, there is no wrapped error, so it returns nil. +func (_ Err) Unwrap() error { return nil } + diff --git a/src/core/errs/error_list.go b/src/core/errs/error_list.go new file mode 100644 index 0000000..4ff1fb3 --- /dev/null +++ b/src/core/errs/error_list.go @@ -0,0 +1,122 @@ +// ============================================================================= +// Active-GO 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/05/2025 +// ============================================================================= + +package errs + +// ErrorList is a slice of errors with helper methods for managing the list. +// It can contain nil errors. +type ErrorList []error + +// Any returns true if the list contains at least one non-nil error. +func (l ErrorList) Any() bool { + for _, e := range l { + if e != nil { + return true + } + } + return false +} + +// Len returns the total length of the error list, including nil errors. +func (l ErrorList) Len() int { + return len(l) +} + +// Count returns the number of non-nil errors in the list. +func (l ErrorList) Count() int { + c := 0 + for _, e := range l { + if e != nil { + c++ + } + } + return c +} + +// First returns the first non-nil error in the list. +// If no non-nil error exists, returns nil. +func (l ErrorList) First() error { + for _, e := range l { + if e != nil { + return e + } + } + return nil +} + +// Last returns the last non-nil error in the list. +// If no non-nil error exists, returns nil. +func (l ErrorList) Last() error { + for i := len(l) - 1; i >= 0; i-- { + if l[i] != nil { + return l[i] + } + } + return nil +} + +// Append adds an error to the end of the list, regardless of whether it's nil. +// Returns the modified error list. +func (l ErrorList) Append(err error) ErrorList { + return append(l, err) +} + +// AppendNotNil adds an error to the list only if it's not nil. +// Returns the modified error list or the original list if the error was nil. +func (l ErrorList) AppendNotNil(err error) ErrorList { + if err != nil { + return append(l, err) + } + return l +} + +// Reset removes all errors from the list by resetting its length to zero. +// Returns the emptied error list. +func (l ErrorList) Reset() ErrorList { + return l[:0] +} + +// Clean removes any nil errors from the list. +// Returns a new error list containing only non-nil errors. +func (l ErrorList) Clean() ErrorList { + return l.filter(func(e error) bool { + return e != nil + }) +} + +// filter creates a new error list containing only errors that satisfy the filter function. +// This is an internal helper method. +func (l ErrorList) filter(filter func(error) bool) ErrorList { + rs := make([]error, 0, len(l)) + for _, e := range l { + if filter(e) { + rs = append(rs, e) + } + } + return rs +} diff --git a/src/core/errs/format.go b/src/core/errs/format.go new file mode 100644 index 0000000..44b5cc8 --- /dev/null +++ b/src/core/errs/format.go @@ -0,0 +1,143 @@ +// ============================================================================= +// Active-GO 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 16/05/2025 +// ============================================================================= + +package errs + +import ( + "errors" + "fmt" + "io" + "strings" +) + +// Format is the main entry point for formatting errors using the package's capabilities. +// It is typically called by types implementing fmt.Formatter. +// It delegates the actual formatting to the configured errorFormatter. +func Format(err error, f fmt.State, verb rune) { + // Delegates formatting to the global errorFormatter, passing formatting state, + // the error, current format options, initial indentation level (0), + // and formatting show options derived from the fmt verb and flags. + g.errorFormatter(f, err, g.formatOptions, 0, ShowOptionsFromVerb(f, verb)) +} + +// defaultFormatError provides a default implementation for formatting errors. +// It recursively formats the error and its wrapped errors (causes), displaying +// error messages, metadata, and stack traces based on the provided options and show flags. +func defaultFormatError(w io.Writer, err error, opts *FormatOptions, level int, show FormatShow) { + if err == nil { + return + } + + var el []error // Slice to collect wrapped errors (causes) for recursive formatting + var stack *Meta // Pointer to store the stack trace metadata if found + + // Determine which metadata to select based on show options. + sm := MetaTypeValue + if show.ShowStack() { + sm |= MetaTypeStack + } + // If not showing hierarchy, don't select cause metadata at the current level + // to avoid duplicating cause information in the flat metadata list. + if !show.ShowHierarchy() {º + sm |= MetaTypeCause + } + + // Calculate the indentation for the current level. + indent := strings.Repeat(opts.Indent, level) + + // Format the current error message. Use different formats for the root error (level 0) and causes. + if level == 0 { + _, _ = fmt.Fprintf(w, opts.FmtError, indent, err.Error()) + } else { + _, _ = fmt.Fprintf(w, opts.FmtCause, indent, err.Error()) + } + + // Iterate through the error chain using errors.Unwrap. + for e := err; e != nil; e = errors.Unwrap(e) { + // If showing metadata and the current error provides metadata. + if show.ShowMetas() { + if mp, ok := e.(MetadataProvider); ok { + // Get metadata based on the current selection criteria. + ml := mp.Metadata(sm) + for _, m := range ml { + // Handle stack trace metadata separately if selected. + if sm.SelectStack() && m.mType == MetaTypeStack { + stack = &m + // Remove MetaSelectStack from selection for subsequent metadata at this level. + sm &^= MetaTypeStack + continue + } + // If showing hierarchy, skip cause metadata here to avoid duplication. + if show.ShowHierarchy() && sm.SelectCause() && m.mType == MetaTypeCause { + continue + } + // Format other metadata. + _, _ = fmt.Fprintf(w, opts.FmtMeta, indent, m.Name, m.Value()) + } + } + } + // If showing hierarchy, collect the wrapped errors (causes) for recursive formatting. + if show.ShowHierarchy() { + switch cs := e.(type) { + case Causer: + // Handle single cause errors. + el = append(el, cs.Cause()) + case Causers: + // Handle errors with multiple causes. + el = append(el, cs.Causes()...) + case interface{ Unwrap() []error }: + // Handle errors implementing the Unwrap() []error interface (Go 1.20+). + el = cs.Unwrap() + } + } + } + + // Recursively format the collected wrapped errors (causes). + if len(el) > 0 { + // Adjust show options for deep formatting if not explicitly requested. + if !show.ShowDeepMetas() && show.ShowMetas() { + show &^= FormatShowMetas // Turn off showing metas in deeper levels if not deep. + } + if !show.ShowDeepStacks() && show.ShowStack() { + show &^= FormatShowStack // Turn off showing stacks in deeper levels if not deep. + } + for _, ce := range el { + // Recursively call defaultFormatError for each cause, increasing the indentation level. + defaultFormatError(w, ce, opts, level+1, show) + } + } + + // Format the stack trace if one was collected and formatting is enabled. + if stack != nil && !stack.State().HasNilOrZero() { + _, _ = fmt.Fprintf(w, opts.FmtStackH, indent) // Format stack header. + // Format each line of the stack trace. + for _, l := range stack.Value().([]string) { + _, _ = fmt.Fprintf(w, opts.FmtStackL, indent, l) + } + } +} diff --git a/src/core/errs/format_options.go b/src/core/errs/format_options.go new file mode 100644 index 0000000..42418c9 --- /dev/null +++ b/src/core/errs/format_options.go @@ -0,0 +1,131 @@ +// ============================================================================= +// Active-GO 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 17/05/2025 +// ============================================================================= + +package errs + +/* +// Basic ANSI color codes (Commented out, but values used in NewFormatOptionsColor) +const ( + ColorBlack = "\033[30m" + ColorRed = "\033[31m" + ColorGreen = "\033[32m" + ColorYellow = "\033[33m" + ColorBlue = "\033[34m" + ColorMagenta = "\033[35m" + ColorCyan = "\033[36m" + ColorWhite = "\033[37m" + + ColorGray = "\033[2m" + + ColorBrightBlack = "\033[90m" + ColorBrightRed = "\033[91m" + ColorBrightGreen = "\033[92m" + ColorBrightYellow = "\033[93m" + ColorBrightBlue = "\033[94m" + ColorBrightMagenta= "\033[95m" + ColorBrightCyan = "\033[96m" + ColorBrightWhite = "\033[97m" + + BgBlack = "\033[40m" + BgRed = "\033[41m" + BgGreen = "\033[42m" + BgYellow = "\033[43m" + BgBlue = "\033[44m" + BgMagenta = "\033[45m" + BgCyan = "\033[46m" + BgWhite = "\033[47m" + + BgBrightBlack = "\033[100m" + BgBrightRed = "\033[101m" + BgBrightGreen = "\033[102m" + BgBrightYellow = "\033[103m" + BgBrightBlue = "\033[104m" + BgBrightMagenta = "\033[105m" + BgBrightCyan = "\033[106m" + BgBrightWhite = "\033[107m" + + TextBold = "\033[1m" // Bold text + TextFaint = "\033[2m" // Faint text (dim) + TextUnderline = "\033[4m" // Underlined text + TextReverse = "\033[7m" // Swap foreground and background colors + + ColorReset = "\033[0m" // Reset all attributes + +) + +*/ + +type ( + // FormatOptions defines the options for controlling how errors are formatted. + FormatOptions struct { + // Show specifies which parts of the error (hierarchy, metas, stack) should be displayed. + Show FormatShow + // EnableColor indicates whether ANSI color codes should be included in the output. + EnableColor bool + + // Indent is the string used for each level of indentation in the formatted output. + Indent string + + // FmtError is the format string used for the root error message. + FmtError string + // FmtMeta is the format string used for displaying metadata. + FmtMeta string + // FmtCause is the format string used for displaying wrapped error messages (causes). + FmtCause string + // FmtStackH is the format string used for the stack trace header. + FmtStackH string + // FmtStackL is the format string used for each line of the stack trace. + FmtStackL string + } +) + +// NewFormatOptions creates a new FormatOptions instance with default plain text formatting. +func NewFormatOptions() *FormatOptions { + return &FormatOptions{ + Indent: " ", + FmtError: "%s%s\n", + FmtMeta: "%s * %s: %v\n", + FmtCause: "%s%s\n", + FmtStackH: "%s * stack:\n", + FmtStackL: "%s %s\n", + } +} + +// NewFormatOptionsColor creates a new FormatOptions instance with default ANSI color formatting. +func NewFormatOptionsColor() *FormatOptions { + return &FormatOptions{ + Indent: " ", + EnableColor: true, + // Format strings include ANSI color codes for different parts of the error output. + FmtError: "%s\033[31m%s\033[0m\n", // Red for the main error message + FmtMeta: "%s\033[2m * %s: %v\033[0m\n", // Faint/Dim for metadata + FmtCause: "%s\033[33m%s\033[0m\n", // Yellow for wrapped error messages (causes) + FmtStackH: "%s\033[37m * stack:\033[0m\n", // White for stack header + FmtStackL: "%s\033[37m %s\033[0m\n", // White for stack lines + } +} diff --git a/src/core/errs/format_show.go b/src/core/errs/format_show.go new file mode 100644 index 0000000..600cb10 --- /dev/null +++ b/src/core/errs/format_show.go @@ -0,0 +1,93 @@ +// ============================================================================= +// Active-GO 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\n// THE SOFTWARE.\n//\n// =============================================================================\n// Date Create 18/05/2025\n// ============================================================================= + +package errs + +import "fmt" + +const ( + // FormatShowHierarchy is a flag to show the error hierarchy (wrapped errors/causes). + FormatShowHierarchy FormatShow = 1 << iota + // FormatShowMetas is a flag to show metadata of the current error in the hierarchy. + FormatShowMetas + // FormatShowDeepMetas is a flag to show metadata for all errors in the hierarchy. + FormatShowDeepMetas + // FormatShowStack is a flag to show the stack trace of the root error. + FormatShowStack + // FormatShowDeepStacks is a flag to show stack traces for all errors in the hierarchy if defined. + FormatShowDeepStacks + + // FormatShowNone is a flag to show nothing extra (only the basic error message). + FormatShowNone FormatShow = 0 +) + +// FormatShow is a bitmask type used to control which parts of an error are displayed during formatting. +type FormatShow uint8 + +// ShowMetas returns true if the FormatShow includes the FormatShowMetas flag. +func (o FormatShow) ShowMetas() bool { return o&FormatShowMetas != 0 } + +// ShowHierarchy returns true if the FormatShow includes the FormatShowHierarchy flag. +func (o FormatShow) ShowHierarchy() bool { return o&FormatShowHierarchy != 0 } + +// ShowDeepMetas returns true if the FormatShow includes the FormatShowDeepMetas flag. +func (o FormatShow) ShowDeepMetas() bool { return o&FormatShowDeepMetas != 0 } + +// ShowStack returns true if the FormatShow includes the FormatShowStack flag. +func (o FormatShow) ShowStack() bool { return o&FormatShowStack != 0 } + +// ShowDeepStacks returns true if the FormatShow includes the FormatShowDeepStacks flag. +func (o FormatShow) ShowDeepStacks() bool { return o&FormatShowDeepStacks != 0 } + +// ShowOptionsFromVerb derives FormatShow options based on the fmt.State and verb. +// This function interprets standard fmt verbs and flags to determine what to display. +func ShowOptionsFromVerb(f fmt.State, verb rune) FormatShow { + s := FormatShowNone + switch verb { + case 's', 'q': + // For %s and %q, show nothing extra. + return s + + case 'v': + // For %v, check flags to determine what to show. + if f.Flag('+') { + // %+v -> Show hierarchy, metas, and full stack + s |= FormatShowHierarchy | + FormatShowMetas | + FormatShowDeepMetas | + FormatShowStack | + FormatShowDeepStacks + + } else if f.Flag('#') { + // %#v -> Show metas and stack of the principal error + s |= FormatShowMetas | + FormatShowStack + + } else { + // %v -> Show hierarchy and principal stack (optional based on your criterion) + s |= FormatShowHierarchy | + FormatShowStack + } + } + return s +} diff --git a/src/core/errs/formatter.go b/src/core/errs/formatter.go new file mode 100644 index 0000000..8deeb1b --- /dev/null +++ b/src/core/errs/formatter.go @@ -0,0 +1,47 @@ +// ============================================================================= +// Active-GO 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 20/05/2025 +// ============================================================================= + +package errs + + +type ( + + Formatter interface { + Format (err error) ([]byte,error) + } + + + FormatFnc func (error) ([]byte,error) +) + + + +func (f FormatFnc) Format (err error) ([]byte,error) { return f(err) } + + + diff --git a/src/core/errs/meta.go b/src/core/errs/meta.go new file mode 100644 index 0000000..5261edb --- /dev/null +++ b/src/core/errs/meta.go @@ -0,0 +1,86 @@ +// ============================================================================= +// 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 09/06/2025 +// ============================================================================= + +package errs + +import ( + "core/excs" + "core/vals" +) + + + +type ( + + Meta struct { + vals.CValue + name string + mType MetaType + } +) + + + +func CreateMeta (name string, cval vals.CValue) Meta { + if !IsValidMetaName(name) { + panic(E.InvalidMetaName) + } + return Meta { + CValue : cval, + name : name, + mType : MetaTypeValue, + } +} + +func CreateMetaStack (stack excs.Stack) Meta { + return Meta { + name : MetaCauseName, + CValue : vals.CreateCValueStack(stack), + mType : MetaTypeStack, + } +} + +func CreateMetaCause(cause error) Meta { + return Meta { + name : MetaCauseName, + CValue : vals.CreateCValueError(cause), + mType : MetaTypeCause, + } +} + + + +func (m Meta) Name() string { return m.name } + + + +// IsValidMetaName checks if a string is a valid metadata name according to the rules defined by metaValidator. +func IsValidMetaName(meta string) bool { + return len(meta) > 0 && g.metaValidator.MatchString(meta) +} + diff --git a/src/core/errs/meta_type.go b/src/core/errs/meta_type.go new file mode 100644 index 0000000..f85f587 --- /dev/null +++ b/src/core/errs/meta_type.go @@ -0,0 +1,52 @@ +// ============================================================================= +// Active-GO 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 18/05/2025 +// ============================================================================= + +package errs + +const ( + // MetaTypeValue is a flag to select general value metadata. + MetaTypeValue MetaType = 1 << iota + // MetaTypeCause is a flag to select cause metadata. + MetaTypeCause + // MetaTypeStack is a flag to select stack trace metadata. + MetaTypeStack + // MetaTypeAll is a flag to select all types of metadata. + MetaTypeAll = 7 // Combination of all selection flags +) + +// MetaType is a bitmask type used to select which types of metadata to retrieve. +type MetaType uint8 + +// SelectValue returns true if the MetaType includes the MetaTypeValue flag. +func (s MetaType) SelectValue() bool { return s&MetaTypeValue != 0 } + +// SelectCause returns true if the MetaType includes the MetaTypeCause flag. +func (s MetaType) SelectCause() bool { return s&MetaTypeCause != 0 } + +// SelectStack returns true if the MetaType includes the MetaTypeStack flag. +func (s MetaType) SelectStack() bool { return s&MetaTypeStack != 0 } diff --git a/src/core/errs/metadata_provider.go b/src/core/errs/metadata_provider.go new file mode 100644 index 0000000..c431423 --- /dev/null +++ b/src/core/errs/metadata_provider.go @@ -0,0 +1,45 @@ +// ============================================================================= +// Active-GO 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 16/05/2025 +// ============================================================================= + +package errs + +type ( + // MetadataProvider is an interface implemented by types that can provide metadata. + // Composed error types typically implement this interface. + MetadataProvider interface { + // Metadata returns a slice of Meta objects based on the provided selector. + Metadata(selector MetaType) []Meta } + + // MetadataFnc is a function type that implements the MetadataProvider interface. + // It allows an anonymous function or an existing function to act as a metadata provider. + MetadataFnc func(selector MetaType) []Meta + +) + +// Metadata implements the MetadataProvider interface for MetadataFnc, executing the underlying function. +func (f MetadataFnc) Metadata(selector MetaType) []Meta { return f(selector) } diff --git a/src/core/errs/panic_err.go b/src/core/errs/panic_err.go new file mode 100644 index 0000000..494f249 --- /dev/null +++ b/src/core/errs/panic_err.go @@ -0,0 +1,72 @@ +// ============================================================================= +// Active-GO 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/05/2025 +// ============================================================================= + +package errs + +const ( + // errPanic is the error class name used to represent panics converted to errors. + errPanic = moduleName + "panic" +) + +type ( + // PanicErr is an error type that wraps a recovered panic. + // It allows treating a panic as a structured error. + PanicErr struct { + Err // Embeds the Err type to inherit its methods and basic structure. + cause error // cause stores the recovered panic value, converted to an error type. + } +) + +// CreatePanicErr creates a new PanicErr instance from a recovered panic value. +// It converts the panic value to an error type using ToError. +func CreatePanicErr(cause any) PanicErr { + return PanicErr{ + Err: CreateErr(errPanic), // Creates a base error with the "panic" class. + cause: ToError(cause), // Converts the panic value to an error. + } +} + +// Cause implements the Causer interface for PanicErr. +// It returns the underlying error representing the panic value. +func (e PanicErr) Cause() error { return e.cause } + +// Unwrap implements Go 1.13+'s errors.Unwrap interface. +// It returns the underlying error representing the panic value, allowing +// the PanicErr to be unwrapped to access the original cause. +func (e PanicErr) Unwrap() error { return e.cause } + + + +func (e PanicErr) Metadata(selector MetaType) []Meta { + if !selector.SelectCause() { + return nil + } + return []Meta{ + CreateMetaCause(e.cause), + } +} \ No newline at end of file diff --git a/src/core/errs/param_err.go b/src/core/errs/param_err.go new file mode 100644 index 0000000..872dd96 --- /dev/null +++ b/src/core/errs/param_err.go @@ -0,0 +1,111 @@ +// ============================================================================= +// Active-GO 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/05/2025 +// ============================================================================= + +package errs + +import ( + "core/vals" + "fmt" +) + +const ( + errParam = moduleName + "invalid_param" + errParamNil = errParam + errClassSep + "nil" + errParamEmpty = errParam + errClassSep + "empty" + errParamRange = errParam + errClassSep + "range" + errParamRangeMin = errParamRange + errClassSep + "min" + errParamRangeMax = errParamRange + errClassSep + "max" +) + +type ( + ParamErr struct { + Err + name string + value any + } +) + +func createParamErr(err Err, name string, value any) ParamErr { + if name == "" { + + panic(CreateParamEmptyErr("name")) + } + return ParamErr{ + Err: err, + name: name, + value: value, + } +} + +func CreateParamErr (name string, value any) ParamErr { + return createParamErr(Err(errParam), name, value) +} + +func CreateParamNilErr (name string) ParamErr { + return createParamErr(Err(errParamNil),name, nil) +} + +func CreateParamEmptyErr(name string) ParamErr { + return createParamErr(Err(errParamEmpty),name,"") +} + +func CreateParamRange (name string, value any) ParamErr { + return createParamErr(Err(errParamRange),name,value) +} + +func CreateParamRangeMin(name string, value any) ParamErr { + return createParamErr(Err(errParamRangeMin), name, value) +} + +func CreateParamRangeMax(name string, value any) ParamErr { + return createParamErr(Err(errParamRangeMax), name, value) +} + + + + +func (e ParamErr) ParamName() string { return e.name } + +func (e ParamErr) ParamValue() any { return e.value } + +func (e ParamErr) Format(f fmt.State, v rune) { Format(e, f, v) } + +func (e ParamErr) Metadata(selector MetaType) []Meta { + if !selector.SelectValue() { + return nil + } + return []Meta { + CreateMeta("param_name", vals.CreateCValueString(e.name)), + vals.CreateCField("param_value", e.value), + } +} + +func (e ParamErr) Unwrap() error { + // ParamErr es típicamente un error hoja, no envuelve nada que continúe la cadena. + return nil +} diff --git a/src/core/errs/severity.go b/src/core/errs/severity.go new file mode 100644 index 0000000..5e6ae1e --- /dev/null +++ b/src/core/errs/severity.go @@ -0,0 +1,60 @@ +// ============================================================================= +// Active-GO 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 15/05/2025 +// ============================================================================= + +package errs + +const ( + // SeverityDebug indicates a severity level for debugging information. + SeverityDebug Severity = 1 << iota + // SeverityInfo indicates a severity level for general information. + SeverityInfo + // SeverityWarn indicates a severity level for warnings. + SeverityWarn + // SeverityError indicates a severity level for errors affecting functionality. + SeverityError + // SeverityCritical indicates a severity level for critical errors requiring immediate attention. + SeverityCritical + // SeverityFatal indicates a severity level for errors causing application termination. + SeverityFatal +) + +// Severity represents the severity level of an error. +// It is used to classify the importance of an error. +type Severity uint8 + +// String returns the string representation of the severity level. +// Returns "UNKNOWN" for undefined severity values. +func (s Severity) String() string { + // Checks if the severity value is within the expected range. + if s <= 0 || s > SeverityFatal { + return "UNKNOWN" + } + // Uses a string slice to map the severity value to its name. + // Note: Index 0 is not used as severity values start from 1 (1 << 0). + return [...]string{"DEBUG", "INFO", "WARNING", "ERROR", "FATAL", "CRITICAL"}[s-1] // Corrected index +} diff --git a/src/core/blrs/list_baler.go b/src/core/pkrs/list_packer.go similarity index 96% rename from src/core/blrs/list_baler.go rename to src/core/pkrs/list_packer.go index c06e433..2faf7bd 100644 --- a/src/core/blrs/list_baler.go +++ b/src/core/pkrs/list_packer.go @@ -26,8 +26,8 @@ // Date Create 28/05/2025 // ============================================================================= -package blrs +package pkrs -type ListBaler interface { - Add() Baler +type ListPacker interface { + Add() Packer } diff --git a/src/core/blrs/map_baler.go b/src/core/pkrs/map_packer.go similarity index 96% rename from src/core/blrs/map_baler.go rename to src/core/pkrs/map_packer.go index 1b1f8f9..511f30d 100644 --- a/src/core/blrs/map_baler.go +++ b/src/core/pkrs/map_packer.go @@ -26,8 +26,8 @@ // Date Create 28/05/2025 // ============================================================================= -package blrs +package pkrs -type MapBaler interface { - Key(key any) Baler +type MapPacker interface { + Key(key any) Packer } diff --git a/src/core/blrs/object_baler.go b/src/core/pkrs/object_packer.go similarity index 95% rename from src/core/blrs/object_baler.go rename to src/core/pkrs/object_packer.go index ddb9b89..becce00 100644 --- a/src/core/blrs/object_baler.go +++ b/src/core/pkrs/object_packer.go @@ -26,8 +26,8 @@ // Date Create 28/05/2025 // ============================================================================= -package blrs +package pkrs -type ObjectBaler interface { - Field(name string) Baler +type ObjectPacker interface { + Field(name string) Packer } diff --git a/src/core/blrs/baleable.go b/src/core/pkrs/packable.go similarity index 95% rename from src/core/blrs/baleable.go rename to src/core/pkrs/packable.go index 83c9f73..f341cd8 100644 --- a/src/core/blrs/baleable.go +++ b/src/core/pkrs/packable.go @@ -26,8 +26,10 @@ // Date Create 28/05/2025 // ============================================================================= -package blrs +package pkrs -type Baleable interface { - Bale(baler Baler) error + + +type Packable interface { + Pack(packer Packer) error } diff --git a/src/core/blrs/baler.go b/src/core/pkrs/packer.go similarity index 90% rename from src/core/blrs/baler.go rename to src/core/pkrs/packer.go index 2097751..bb0001e 100644 --- a/src/core/blrs/baler.go +++ b/src/core/pkrs/packer.go @@ -26,10 +26,13 @@ // Date Create 28/05/2025 // ============================================================================= -package blrs +package pkrs -type Baler interface { - Map(mapBaler MapBaler) error - List(listBaler ListBaler) error - Object(objBaler ObjectBaler) error -} +type ( + + Packer interface { + Map (mapPacker MapPacker) error + List (listPacker ListPacker) error + Object (objPacker ObjectPacker) error + } +) diff --git a/src/core/vals/a.go b/src/core/vals/a.go index ae0a735..81b37e6 100644 --- a/src/core/vals/a.go +++ b/src/core/vals/a.go @@ -28,14 +28,25 @@ package vals +import ( + "math" + "time" +) + var ( - G = struct { - TypeInfos *CValueTypeInfos + g = struct { + minTime, + maxTime time.Time }{ + minTime: time.Unix(0, math.MinInt64), + maxTime: time.Unix(0, math.MaxInt64), + } - + G = struct { + TypeInfos *CValueTypeInfos + }{ TypeInfos: newCValueTypeInfos(), } diff --git a/src/core/vals/cattribute.go b/src/core/vals/cattribute.go new file mode 100644 index 0000000..8f535b1 --- /dev/null +++ b/src/core/vals/cattribute.go @@ -0,0 +1,154 @@ +// ============================================================================= +// 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 10/06/2025 +// ============================================================================= + +package vals + +type ( + + CAttribute struct { + CValue + aType CAttributeType + name string + } +) + + + +func CreateCAttribute (name string, value any, attrType CAttributeType) CAttribute { + return CreateCAttributeWithCValue(name,CreateCValue(value), attrType) +} + + +func CreateCAttributeBool (name string, value bool, attrType CAttributeType) CAttribute { + return CreateCAttributeWithCValue(name,CreateCValueBool(value), attrType) } + + + +func CreateCAttributeInt (name string, value int, attrType CAttributeType) CAttribute { + return CreateCAttributeWithCValue(name,CreateCValueInt(value), attrType) } + +func CreateCAttributeInt8 (name string, value int8, attrType CAttributeType) CAttribute { + return CreateCAttributeWithCValue(name,CreateCValueInt8(value), attrType) } + +func CreateCAttributeInt16 (name string, value int16, attrType CAttributeType) CAttribute { + return CreateCAttributeWithCValue(name,CreateCValueInt16(value), attrType) } + +func CreateCAttributeInt32 (name string, value int32, attrType CAttributeType) CAttribute { + return CreateCAttributeWithCValue(name,CreateCValueInt32(value), attrType) } + +func CreateCAttributeInt64 (name string, value int64, attrType CAttributeType) CAttribute { + return CreateCAttributeWithCValue(name,CreateCValueInt64(value), attrType) } + + + + +func CreateCAttributeUint (name string, value uint, attrType CAttributeType) CAttribute { + return CreateCAttributeWithCValue(name,CreateCValueUint(value), attrType) } + +func CreateCAttributeUint8 (name string, value uint8, attrType CAttributeType) CAttribute { + return CreateCAttributeWithCValue(name,CreateCValueUint8(value), attrType) } + +func CreateCAttributeUint16 (name string, value uint16, attrType CAttributeType) CAttribute { + return CreateCAttributeWithCValue(name,CreateCValueUint16(value), attrType) } + +func CreateCAttributeUint32 (name string, value uint32, attrType CAttributeType) CAttribute { + return CreateCAttributeWithCValue(name,CreateCValueUint32(value), attrType) } + +func CreateCAttributeUint64 (name string, value uint64, attrType CAttributeType) CAttribute { + return CreateCAttributeWithCValue(name,CreateCValueUint64(value), attrType) } + +func CreateCAttributeUintptr (name string, value uintptr, attrType CAttributeType) CAttribute { + return CreateCAttributeWithCValue(name,CreateCValueUintptr(value),attrType) } + + + + +func CreateCAttributeFloat32 (name string, value float32, attrType CAttributeType) CAttribute { + return CreateCAttributeWithCValue(name,CreateCValueFloat32(value), attrType) } + +func CreateCAttributeFloat64 (name string, value float64, attrType CAttributeType) CAttribute { + return CreateCAttributeWithCValue(name,CreateCValueFloat64(value), attrType) } + +func CreateCAttributeComplex64 (name string, value complex64, attrType CAttributeType) CAttribute { + return CreateCAttributeWithCValue(name,CreateCValueComplex64(value), attrType) } + +func CreateCAttributeComplex128 (name string, value complex128, attrType CAttributeType) CAttribute { + return CreateCAttributeWithCValue(name,CreateCValueComplex128(value), attrType) } + + + +func CreateCAttributeDate (name string, value Date, attrType CAttributeType) CAttribute { + return CreateCAttributeWithCValue(name,CreateCValueDate(value),attrType) } + +func CreateCAttributeDuration (name string, value Duration, attrType CAttributeType) CAttribute { + return CreateCAttributeWithCValue(name,CreateCValueDuration(value),attrType) } + + + +func CreateCAttributeString (name string, value string, attrType CAttributeType) CAttribute { + return CreateCAttributeWithCValue(name,CreateCValueString(value), attrType) } + +func CreateCAttributeBytes (name string, value Bytes, attrType CAttributeType) CAttribute { + return CreateCAttributeWithCValue(name,CreateCValueBytes(value), attrType) } + +func CreateCAttributeStack (name string, value Stack, attrType CAttributeType) CAttribute { + return CreateCAttributeWithCValue(name,CreateCValueStack(value), attrType | CAttributeTypeStack ) } + +func CreateCAttributeCause (name string, value error, attrType CAttributeType) CAttribute { + return CreateCAttributeWithCValue(name,CreateCValueError(value), attrType|CAttributeTypeCause) } + + + + +func CreateCAttributeWithCValue (name string, cvalue CValue, attrType CAttributeType) CAttribute { + at := CAttribute{ + CValue: cvalue, + name : name, + aType : attrType, + } + if attrType.HasAttributePII() { + at.vState|= cValueStateSensitive + } + return at +} + + +func (a CAttribute) Name() string { return a.name } + +func (a CAttribute) AttrType() CAttributeType { return a.aType } + + + + + + + + + + + diff --git a/src/core/vals/cattribute_type.go b/src/core/vals/cattribute_type.go new file mode 100644 index 0000000..e97ed62 --- /dev/null +++ b/src/core/vals/cattribute_type.go @@ -0,0 +1,74 @@ +// ============================================================================= +// 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 10/06/2025 +// ============================================================================= + +package vals + + +const ( + + CAttributeTypeCause CAttributeType = 1 << iota + CAttributeTypeStack + CAttributeTypeIdentifier + CAttributeTypeIndexed + CAttributeTypeMeasurement + CAttributeTypePII + CAttributeTypeDebug + + CAttributeTypeDefault CAttributeType = 0 +) + + +type CAttributeType uint8 + + + +func (c CAttributeType) HasAttribute (attType CAttributeType) bool { return c&attType == c } + +func (c CAttributeType) IsAttributeDefault () bool { return c == 0 } + +func (c CAttributeType) HasAttributeCause () bool { return c&CAttributeTypeCause != 0 } +func (c CAttributeType) HasAttributeStack () bool { return c&CAttributeTypeStack != 0 } +func (c CAttributeType) HasAttributeIdentifier() bool { return c&CAttributeTypeIdentifier != 0 } +func (c CAttributeType) HasAttributePII () bool { return c&CAttributeTypePII != 0 } +func (c CAttributeType) HasAttributeIndexed () bool { return c&CAttributeTypeIndexed != 0 } +func (c CAttributeType) HasAttributeMeasurement() bool{ return c&CAttributeTypeMeasurement != 0 } +func (c CAttributeType) HasAttributeDebug () bool { return c&CAttributeTypeDebug != 0 } + + + + + + + + + + + + + + diff --git a/src/core/vals/cfield.go b/src/core/vals/cfield.go index 57f7dd9..88227e8 100644 --- a/src/core/vals/cfield.go +++ b/src/core/vals/cfield.go @@ -35,9 +35,23 @@ type ( CField struct { Name string - Value CValue + CValue } ) +func CreateCField (name string, value any) CField { + return CField{ + Name : name, + CValue: CreateCValue(value), + } +} + + +func CreateCFieldWithCValue (name string, cvalue CValue) CField { + return CField{ + Name : name, + CValue: cvalue, + } +} \ No newline at end of file diff --git a/src/core/vals/cvalue.go b/src/core/vals/cvalue.go index 71eaf3f..7f9c59c 100644 --- a/src/core/vals/cvalue.go +++ b/src/core/vals/cvalue.go @@ -29,7 +29,6 @@ package vals import ( - "core/blrs" "core/excs" "math" "reflect" @@ -39,8 +38,8 @@ import ( type CValue struct { _ [0]func() - vType CValueType - vState CValueState + vType CValueType + vState CValueState intVal int64 strVal string anyVal any @@ -54,14 +53,14 @@ func CreateCValue(value any) CValue { func createCValueAny (value any ) CValue { - if value == nil { return CValue{ vType: CValueTypeAny, vState: cValueStateNil|cValueStateZero } } - return CValue{ vType: CValueTypeAny, anyVal: value } + if value == nil { return CValue{ vType: cValueTypeAny, vState: cValueStateNil|cValueStateZero } } + return CValue{ vType: cValueTypeAny, anyVal: value } } func CreateCValueBool (value bool ) CValue { - if !value { return CValue{ vType: CValueTypeInt, vState: cValueStateZero } } - return CValue{ vType: CValueTypeInt, vState: cValueStateZero, intVal: 1} + if !value { return CValue{ vType: cValueTypeInt, vState: cValueStateZero } } + return CValue{ vType: cValueTypeInt, vState: cValueStateZero, intVal: 1} } @@ -69,28 +68,28 @@ func CreateCValueBool (value bool ) CValue { // Int's func CreateCValueInt (value int ) CValue { - if value == 0 { return CValue{ vType: CValueTypeInt, vState: cValueStateZero } } - return CValue{ vType: CValueTypeInt, intVal: int64(value) } + if value == 0 { return CValue{ vType: cValueTypeInt, vState: cValueStateZero } } + return CValue{ vType: cValueTypeInt, intVal: int64(value) } } func CreateCValueInt8 (value int8 ) CValue { - if value == 0 { return CValue{ vType: CValueTypeInt8, vState: cValueStateZero } } - return CValue{ vType: CValueTypeInt8, intVal: int64(value) } + if value == 0 { return CValue{ vType: cValueTypeInt8, vState: cValueStateZero } } + return CValue{ vType: cValueTypeInt8, intVal: int64(value) } } func CreateCValueInt16 (value int16 ) CValue { - if value == 0 { return CValue{ vType: CValueTypeInt16, vState: cValueStateZero } } - return CValue{ vType: CValueTypeInt16, intVal: int64(value) } + if value == 0 { return CValue{ vType: cValueTypeInt16, vState: cValueStateZero } } + return CValue{ vType: cValueTypeInt16, intVal: int64(value) } } func CreateCValueInt32 (value int32 ) CValue { - if value == 0 { return CValue{ vType: CValueTypeInt32, vState: cValueStateZero } } - return CValue{ vType: CValueTypeInt32, intVal: int64(value) } + if value == 0 { return CValue{ vType: cValueTypeInt32, vState: cValueStateZero } } + return CValue{ vType: cValueTypeInt32, intVal: int64(value) } } func CreateCValueInt64 (value int64 ) CValue { - if value == 0 { return CValue{ vType: CValueTypeInt64, vState: cValueStateZero } } - return CValue{ vType: CValueTypeInt64, intVal: value } + if value == 0 { return CValue{ vType: cValueTypeInt64, vState: cValueStateZero } } + return CValue{ vType: cValueTypeInt64, intVal: value } } @@ -98,34 +97,34 @@ func CreateCValueInt64 (value int64 ) CValue { // Uint's func CreateCValueUint (value uint ) CValue { - if value == 0 { return CValue{ vType: CValueTypeUint, vState: cValueStateZero } } - return CValue{ vType: CValueTypeUint, intVal: int64(value) } + if value == 0 { return CValue{ vType: cValueTypeUint, vState: cValueStateZero } } + return CValue{ vType: cValueTypeUint, intVal: int64(value) } } func CreateCValueUint8 (value uint8 ) CValue { - if value == 0 { return CValue{ vType: CValueTypeUint8, vState: cValueStateZero } } - return CValue{ vType: CValueTypeUint8, intVal: int64(value) } + if value == 0 { return CValue{ vType: cValueTypeUint8, vState: cValueStateZero } } + return CValue{ vType: cValueTypeUint8, intVal: int64(value) } } func CreateCValueUint16 (value uint16 ) CValue { - if value == 0 { return CValue{ vType: CValueTypeUint16, vState: cValueStateZero } } - return CValue{ vType: CValueTypeUint16, intVal: int64(value) } + if value == 0 { return CValue{ vType: cValueTypeUint16, vState: cValueStateZero } } + return CValue{ vType: cValueTypeUint16, intVal: int64(value) } } func CreateCValueUint32 (value uint32 ) CValue { - if value == 0 { return CValue{ vType: CValueTypeUint32, vState: cValueStateZero } } - return CValue{ vType: CValueTypeUint32, intVal: int64(value) } + if value == 0 { return CValue{ vType: cValueTypeUint32, vState: cValueStateZero } } + return CValue{ vType: cValueTypeUint32, intVal: int64(value) } } func CreateCValueUint64 (value uint64 ) CValue { - if value == 0 { return CValue{ vType: CValueTypeUint64, vState: cValueStateZero } } - return CValue{ vType: CValueTypeUint64, intVal: int64(value) } + if value == 0 { return CValue{ vType: cValueTypeUint64, vState: cValueStateZero } } + return CValue{ vType: cValueTypeUint64, intVal: int64(value) } } func CreateCValueUintptr (value uintptr ) CValue { - if value == 0 { return CValue{ vType: CValueTypeUintptr, vState: cValueStateZero } } - return CValue{ vType: CValueTypeUintptr, intVal: int64(value) } + if value == 0 { return CValue{ vType: cValueTypeUintptr, vState: cValueStateZero } } + return CValue{ vType: cValueTypeUintptr, intVal: int64(value) } } @@ -133,67 +132,67 @@ func CreateCValueUintptr (value uintptr ) CValue { func CreateCValueFloat32 (value float32 ) CValue { if value == 0.0 { // Comprobación directa para el valor cero - return CValue{vType: CValueTypeFloat32, vState: cValueStateZero} + return CValue{vType: cValueTypeFloat32, vState: cValueStateZero} } - return CValue{vType: CValueTypeFloat32, intVal: int64(math.Float32bits(value))} + return CValue{vType: cValueTypeFloat32, intVal: int64(math.Float32bits(value))} } func CreateCValueFloat64 (value float64 ) CValue { if value == 0.0 { // Comprobación directa para el valor cero - return CValue{vType: CValueTypeFloat64, vState: cValueStateZero} + return CValue{vType: cValueTypeFloat64, vState: cValueStateZero} } - return CValue{vType: CValueTypeFloat64, intVal: int64(math.Float64bits(value))} + return CValue{vType: cValueTypeFloat64, intVal: int64(math.Float64bits(value))} } func CreateCValueComplex64 (value complex64 ) CValue { if value == 0 { // Comprobación directa para el valor cero - return CValue{vType: CValueTypeComplex64, vState: cValueStateZero } + return CValue{vType: cValueTypeComplex64, vState: cValueStateZero } } - return CValue{vType: CValueTypeComplex64, anyVal: value} + return CValue{vType: cValueTypeComplex64, anyVal: value} } func CreateCValueComplex128 (value complex128) CValue { if value == 0 { // Comprobación directa para el valor cero - return CValue{vType: CValueTypeComplex128, vState: cValueStateZero } + return CValue{vType: cValueTypeComplex128, vState: cValueStateZero } } - return CValue{vType: CValueTypeComplex128, anyVal: value} + return CValue{vType: cValueTypeComplex128, anyVal: value} } func CreateCValueDuration (value Duration ) CValue { if value == 0 { - return CValue{vType: CValueTypeDuration, vState: cValueStateZero} + return CValue{vType: cValueTypeDuration, vState: cValueStateZero} } - return CValue{vType: CValueTypeDuration, intVal: int64(value)} + return CValue{vType: cValueTypeDuration, intVal: int64(value)} } func CreateCValueDate (value Date ) CValue { if value.IsZero() { // Comprobación directa para el valor cero - return CValue{vType: CValueTypeDate, vState: cValueStateZero} + return CValue{vType: cValueTypeDate, vState: cValueStateZero} } - if value.After(G.TypeInfos.minTime) && value.Before(G.TypeInfos.maxTime) { - return CValue{vType: CValueTypeDate, vState: cValueStateShort,intVal: value.UnixNano(), anyVal: value.Location()} + if value.After(g.minTime) && value.Before(g.maxTime) { + return CValue{vType: cValueTypeDate, vState: cValueStateShort,intVal: value.UnixNano(), anyVal: value.Location()} } - return CValue{vType: CValueTypeDate, anyVal: value } + return CValue{vType: cValueTypeDate, anyVal: value } } func CreateCValueString (value string ) CValue { if value == "" { // Comprobación directa para el valor cero - return CValue{vType: CValueTypeString, vState: cValueStateZero} + return CValue{vType: cValueTypeString, vState: cValueStateZero} } - return CValue{vType: CValueTypeString, strVal: value} + return CValue{vType: cValueTypeString, strVal: value} } func CreateCValueBytes (value []uint8 ) CValue { l := len(value) if l == 0 { if value == nil { - return CValue{vType: CValueTypeBytes, vState: cValueStateNil} + return CValue{vType: cValueTypeBytes, vState: cValueStateNil} } else { - return CValue{vType: CValueTypeBytes, vState: cValueStateZero,anyVal: value} + return CValue{vType: cValueTypeBytes, vState: cValueStateZero,anyVal: value} } } - return CValue{vType: CValueTypeBytes, anyVal: value, intVal: int64(l)} + return CValue{vType: cValueTypeBytes, anyVal: value, intVal: int64(l)} } @@ -201,59 +200,59 @@ func CreateCValueStack (value Stack ) CValue { l := len(value) if l == 0 { if value == nil { - return CValue{vType: CValueTypeStack, vState: cValueStateNil} + return CValue{vType: cValueTypeStack, vState: cValueStateNil} } else { - return CValue{vType: CValueTypeStack, vState: cValueStateZero,anyVal: value} + return CValue{vType: cValueTypeStack, vState: cValueStateZero,anyVal: value} } } - return CValue{vType: CValueTypeStack, anyVal: value, intVal: int64(l)} + return CValue{vType: cValueTypeStack, anyVal: value, intVal: int64(l)} } -func CreateCValueBaleable (value Baleable ) CValue { +func CreateCValuePackable (value Packable) CValue { if value == nil { - return CValue{vType: CValueTypeBaleable, vState: cValueStateNil} + return CValue{vType: cValueTypePackable, vState: cValueStateNil} } - return CValue{ vType: CValueTypeBaleable, anyVal: value } + return CValue{ vType: cValueTypePackable, anyVal: value } } func CreateCValueError (value error ) CValue { if value == nil { - return CValue{vType: CValueTypeError, vState: cValueStateNil} + return CValue{vType: cValueTypeError, vState: cValueStateNil} } - return CValue{ vType: CValueTypeError, anyVal: value } + return CValue{ vType: cValueTypeError, anyVal: value } } -func CreateCValueNil (_ any ) CValue { return CValue{ vType: CValueTypeNil, vState: cValueStateNil } } +func CreateCValueNil (_ any ) CValue { return CValue{ vType: cValueTypeNil, vState: cValueStateNil } } -func createCValueCValue (value CValue ) CValue { return CValue{vType: CValueTypeCValue, anyVal: value } } +func createCValueCValue (value CValue ) CValue { return CValue{vType: cValueTypeCValue, anyVal: value } } -func createCValueCField (value CField ) CValue { return CValue{vType: CValueTypeCField, anyVal: value} } +func createCValueCField (value CField ) CValue { return CValue{vType: cValueTypeCField, anyVal: value} } func createCValueObject (value any ) CValue { - return createCValueReflected(value,reflect.ValueOf(value),CValueTypeObject, true) } + return createCValueReflected(value,reflect.ValueOf(value), cValueTypeObject, true) } func CreateCValueList (value any) CValue { - return createCValueReflected (value,reflect.ValueOf(value),CValueTypeList , true) + return createCValueReflected (value,reflect.ValueOf(value), cValueTypeList, true) } func CreateCValueDefer (value any) CValue { - return createCValueReflected (value,reflect.ValueOf(value),CValueTypeDefer ,true) + return createCValueReflected (value,reflect.ValueOf(value), cValueTypeDefer,true) } func CreateCValueMap (value any) CValue { - return createCValueReflected (value,reflect.ValueOf(value),CValueTypeMap , true) + return createCValueReflected (value,reflect.ValueOf(value), cValueTypeMap, true) } func createCValueInvalid (value any) CValue { - return CValue{ vType: CValueTypeInvalid, anyVal: value} + return CValue{ vType: cValueTypeInvalid, anyVal: value} } func createCValueWithInvalidError (value any, vtype CValueType, vstate CValueState, er string) CValue { return CValue{ - vType : CValueTypeInvalid, + vType : cValueTypeInvalid, vState: cValueStateInvalid|cValueStateError|vstate, intVal: int64(vtype), anyVal: value, @@ -264,15 +263,22 @@ func createCValueWithInvalidError (value any, vtype CValueType, vstate CValueSta -func (v CValue) Type () CValueType { return v.vType } +func (v CValue) Type () CValueType { return v.vType } func (v CValue) State() CValueState { return v.vState } +func (v CValue) Value() any { + // devolvemos en funcion del tipo de value + // todo + return v.anyVal +} + + func (v CValue) AsBool () (bool,bool){ - if v.vType != CValueTypeBool { + if v.vType != cValueTypeBool { return false,false } if v.vState.HasNilOrZero() { @@ -287,7 +293,7 @@ func (v CValue) AsBool () (bool,bool){ func (v CValue) AsInt () (int,bool){ - if v.vType != CValueTypeInt { + if v.vType != cValueTypeInt { return 0,false } if v.vState.HasNilOrZero() { @@ -300,10 +306,10 @@ func (v CValue) AsInt () (int,bool){ } func (v CValue) AsInts () ([]int,bool){ - if v.vType != CValueTypeInt|CValueTypeList { + if v.vType != cValueTypeInt|cValueTypeList { return nil,false } - if v.vState.HasValueNil() { + if v.vState.HasNil() { return nil,true } return v.anyVal.([]int),true @@ -311,7 +317,7 @@ func (v CValue) AsInts () ([]int,bool){ func (v CValue) AsInt8 () (int8,bool){ - if v.vType != CValueTypeInt8 { + if v.vType != cValueTypeInt8 { return 0,false } if v.vState.HasNilOrZero() { @@ -324,7 +330,7 @@ func (v CValue) AsInt8 () (int8,bool){ } func (v CValue) AsInt16 () (int16,bool){ - if v.vType != CValueTypeInt16 { + if v.vType != cValueTypeInt16 { return 0,false } if v.vState.HasNilOrZero() { @@ -337,7 +343,7 @@ func (v CValue) AsInt16 () (int16,bool){ } func (v CValue) AsInt32 () (int32,bool){ - if v.vType != CValueTypeInt32 { + if v.vType != cValueTypeInt32 { return 0,false } if v.vState.HasNilOrZero() { @@ -350,7 +356,7 @@ func (v CValue) AsInt32 () (int32,bool){ } func (v CValue) AsInt64 () (int64,bool){ - if v.vType != CValueTypeInt64 { + if v.vType != cValueTypeInt64 { return 0,false } if v.vState.HasNilOrZero() { @@ -364,7 +370,7 @@ func (v CValue) AsInt64 () (int64,bool){ func (v CValue) AsUint () (uint,bool){ - if v.vType != CValueTypeUint { + if v.vType != cValueTypeUint { return 0,false } if v.vState.HasNilOrZero() { @@ -377,7 +383,7 @@ func (v CValue) AsUint () (uint,bool){ } func (v CValue) AsUint8 () (uint8,bool){ - if v.vType != CValueTypeUint8 { + if v.vType != cValueTypeUint8 { return 0,false } if v.vState.HasNilOrZero() { @@ -390,7 +396,7 @@ func (v CValue) AsUint8 () (uint8,bool){ } func (v CValue) AsUint16 () (uint16,bool){ - if v.vType != CValueTypeUint16 { + if v.vType != cValueTypeUint16 { return 0,false } if v.vState.HasNilOrZero() { @@ -403,7 +409,7 @@ func (v CValue) AsUint16 () (uint16,bool){ } func (v CValue) AsUint32 () (uint32,bool){ - if v.vType != CValueTypeUint32 { + if v.vType != cValueTypeUint32 { return 0,false } if v.vState.HasNilOrZero() { @@ -416,7 +422,7 @@ func (v CValue) AsUint32 () (uint32,bool){ } func (v CValue) AsUint64 () (uint64,bool){ - if v.vType != CValueTypeUint64 { + if v.vType != cValueTypeUint64 { return 0,false } if v.vState.HasNilOrZero() { @@ -430,7 +436,7 @@ func (v CValue) AsUint64 () (uint64,bool){ func (v CValue) AsUintptr() (uintptr,bool){ - if v.vType != CValueTypeUintptr { + if v.vType != cValueTypeUintptr { return 0,false } if v.vState.HasNilOrZero() { @@ -444,7 +450,7 @@ func (v CValue) AsUintptr() (uintptr,bool){ func (v CValue) AsFloat32() (float32,bool){ - if v.vType != CValueTypeFloat32 { + if v.vType != cValueTypeFloat32 { return 0,false } if v.vState.HasNilOrZero() { @@ -457,7 +463,7 @@ func (v CValue) AsFloat32() (float32,bool){ } func (v CValue) AsFloat64() (float64,bool){ - if v.vType != CValueTypeFloat64 { + if v.vType != cValueTypeFloat64 { return 0,false } if v.vState.HasNilOrZero() { @@ -470,7 +476,7 @@ func (v CValue) AsFloat64() (float64,bool){ } func (v CValue) AsComplex64 () (complex64,bool){ - if v.vType != CValueTypeComplex64 { + if v.vType != cValueTypeComplex64 { return 0,false } if v.vState.HasNilOrZero() { @@ -483,7 +489,7 @@ func (v CValue) AsComplex64 () (complex64,bool){ } func (v CValue) AsComplex128() (complex128,bool){ - if v.vType != CValueTypeComplex128 { + if v.vType != cValueTypeComplex128 { return 0,false } if v.vState.HasNilOrZero() { @@ -498,7 +504,7 @@ func (v CValue) AsComplex128() (complex128,bool){ func (v CValue) AsDuration() (Duration,bool){ - if v.vType != CValueTypeDuration { + if v.vType != cValueTypeDuration { return 0,false } if v.vState.HasNilOrZero() { @@ -511,7 +517,7 @@ func (v CValue) AsDuration() (Duration,bool){ } func (v CValue) AsDate () (Date,bool){ - if v.vType != CValueTypeDate { + if v.vType != cValueTypeDate { return time.Time{},false } if v.vState.HasNilOrZero() { @@ -520,7 +526,7 @@ func (v CValue) AsDate () (Date,bool){ if v.vType.IsDefer() { return (v.anyVal.(func()Date))(),true } - if v.vState.HasValueShort() { + if v.vState.HasShort() { // version corta del date return time.Unix(0, v.intVal).In(v.anyVal.(*time.Location)), true } @@ -529,7 +535,7 @@ func (v CValue) AsDate () (Date,bool){ func (v CValue) AsString () (string,bool){ - if v.vType != CValueTypeString { + if v.vType != cValueTypeString { return "", false } if v.vState.HasNilOrZero() { @@ -542,10 +548,10 @@ func (v CValue) AsString () (string,bool){ } func (v CValue) AsStrings () ([]string,bool){ - if v.vType != CValueTypeList|CValueTypeString { + if v.vType != cValueTypeList|cValueTypeString { return nil,false } - if v.vState.HasValueNil() { + if v.vState.HasNil() { return nil,true } return v.anyVal.([]string),true @@ -553,10 +559,10 @@ func (v CValue) AsStrings () ([]string,bool){ func (v CValue) AsBytes () ([]byte,bool){ - if v.vType != CValueTypeBytes { + if v.vType != cValueTypeBytes { return nil, false } - if v.vState.HasValueNil() { + if v.vState.HasNil() { return []byte(nil),true } if v.vType.IsDefer() { @@ -567,10 +573,10 @@ func (v CValue) AsBytes () ([]byte,bool){ func (v CValue) AsStack () (Stack,bool){ - if v.vType != CValueTypeStack { + if v.vType != cValueTypeStack { return nil, false } - if v.vState.HasValueNil() { + if v.vState.HasNil() { return Stack(nil),true } if v.vType.IsDefer() { @@ -580,25 +586,25 @@ func (v CValue) AsStack () (Stack,bool){ } -func (v CValue) AsBaleable() (blrs.Baleable,bool){ - if v.vType != CValueTypeBaleable { +func (v CValue) AsPackable() (Packable,bool){ + if v.vType != cValueTypePackable { return nil, false } - if v.vState.HasValueNil() { - return blrs.Baleable(nil),true + if v.vState.HasNil() { + return Packable(nil),true } if v.vType.IsDefer() { - return v.anyVal.(blrs.Baleable),true + return v.anyVal.(Packable),true } - return v.anyVal.(blrs.Baleable),true + return v.anyVal.(Packable),true } func (v CValue) AsError () (error,bool){ - if v.vType != CValueTypeError { + if v.vType != cValueTypeError { return nil, false } - if v.vState.HasValueNil() { + if v.vState.HasNil() { return error(nil),true } if v.vType.IsDefer() { @@ -609,7 +615,7 @@ func (v CValue) AsError () (error,bool){ func (v CValue) AsCValue () (CValue,bool) { - if v.vType != CValueTypeCValue { + if v.vType != cValueTypeCValue { return CValue{}, false } if v.vType.IsDefer() { @@ -619,7 +625,7 @@ func (v CValue) AsCValue () (CValue,bool) { } func (v CValue) AsCField () (CField,bool) { - if v.vType != CValueTypeCField { + if v.vType != cValueTypeCField { return CField{}, false } if v.vType.IsDefer() { @@ -629,10 +635,10 @@ func (v CValue) AsCField () (CField,bool) { } func (v CValue) AsCFields() ([]CField,bool) { - if v.vType != CValueTypeCField|CValueTypeList { + if v.vType != cValueTypeCField|cValueTypeList { return nil, false } - if v.vState.HasValueNil() { + if v.vState.HasNil() { return nil, false } if v.vType.IsDefer() { @@ -644,7 +650,7 @@ func (v CValue) AsCFields() ([]CField,bool) { func (v CValue) AsObject () (any,bool) { - if v.vType != CValueTypeObject { + if v.vType != cValueTypeObject { return nil, false } if v.vType.IsDefer() { @@ -654,7 +660,7 @@ func (v CValue) AsObject () (any,bool) { } func (v CValue) AsList () (any,bool) { - if v.vType != CValueTypeList { + if v.vType != cValueTypeList { return nil, false } if v.vType.IsDefer() { @@ -664,7 +670,7 @@ func (v CValue) AsList () (any,bool) { } func (v CValue) AsMap () (any,bool) { - if v.vType != CValueTypeMap { + if v.vType != cValueTypeMap { return nil, false } if v.vType.IsDefer() { @@ -672,3 +678,9 @@ func (v CValue) AsMap () (any,bool) { } return v.anyVal,true } + + + +func (v CValue) Pack (packer Packer) { + +} \ No newline at end of file diff --git a/src/core/vals/cvalue_state.go b/src/core/vals/cvalue_state.go index 8e90a4d..97a3bcf 100644 --- a/src/core/vals/cvalue_state.go +++ b/src/core/vals/cvalue_state.go @@ -51,16 +51,16 @@ const ( type CValueState uint8 -func (s CValueState) HasValueInvalid () bool { return s&cValueStateInvalid != 0 } -func (s CValueState) HasValueNil () bool { return s&cValueStateNil != 0 } -func (s CValueState) HasValueZero () bool { return s&cValueStateZero != 0 } -func (s CValueState) HasValueReflected() bool { return s&cValueStateReflected != 0 } -func (s CValueState) HasValueShort () bool { return s&cValueStateShort != 0 } -func (s CValueState) HasValueSensitive() bool { return s&cValueStateSensitive != 0 } -func (s CValueState) HasValueEncoded () bool { return s&cValueStateEncoded != 0 } -func (s CValueState) HasValueError () bool { return s&cValueStateError != 0 } +func (s CValueState) HasInvalid () bool { return s&cValueStateInvalid != 0 } +func (s CValueState) HasNil () bool { return s&cValueStateNil != 0 } +func (s CValueState) HasZero () bool { return s&cValueStateZero != 0 } +func (s CValueState) HasReflected() bool { return s&cValueStateReflected != 0 } +func (s CValueState) HasShort () bool { return s&cValueStateShort != 0 } +func (s CValueState) HasSensitive() bool { return s&cValueStateSensitive != 0 } +func (s CValueState) HasEncoded () bool { return s&cValueStateEncoded != 0 } +func (s CValueState) HasError () bool { return s&cValueStateError != 0 } -func (s CValueState) HasNilOrZero () bool { return s&(cValueStateZero|cValueStateNil) != 0 } +func (s CValueState) HasNilOrZero() bool { return s&(cValueStateZero|cValueStateNil) != 0 } func (s CValueState) setOption (options CValueState) CValueState { return s|(options&cValueStateOps) } diff --git a/src/core/vals/cvalue_type.go b/src/core/vals/cvalue_type.go index e86f180..f5f4cbd 100644 --- a/src/core/vals/cvalue_type.go +++ b/src/core/vals/cvalue_type.go @@ -38,55 +38,55 @@ const ( maxCValueTypes int = 32 // CValueType's definidos - CValueTypeInvalid CValueType = 0 + cValueTypeInvalid CValueType = 0 - CValueTypeAny CValueType = 1 << 0 - CValueTypeBool CValueType = 1 << 1 + cValueTypeAny CValueType = 1 << 0 + cValueTypeBool CValueType = 1 << 1 - CValueTypeInt CValueType = 1 << 2 - CValueTypeInt8 CValueType = 1 << 3 - CValueTypeInt16 CValueType = 1 << 4 - CValueTypeInt32 CValueType = 1 << 5 - CValueTypeInt64 CValueType = 1 << 6 + cValueTypeInt CValueType = 1 << 2 + cValueTypeInt8 CValueType = 1 << 3 + cValueTypeInt16 CValueType = 1 << 4 + cValueTypeInt32 CValueType = 1 << 5 + cValueTypeInt64 CValueType = 1 << 6 - CValueTypeUint CValueType = 1 << 7 - CValueTypeUint8 CValueType = 1 << 8 - CValueTypeUint16 CValueType = 1 << 9 - CValueTypeUint32 CValueType = 1 << 10 - CValueTypeUint64 CValueType = 1 << 11 + cValueTypeUint CValueType = 1 << 7 + cValueTypeUint8 CValueType = 1 << 8 + cValueTypeUint16 CValueType = 1 << 9 + cValueTypeUint32 CValueType = 1 << 10 + cValueTypeUint64 CValueType = 1 << 11 - CValueTypeUintptr CValueType = 1 << 12 + cValueTypeUintptr CValueType = 1 << 12 - CValueTypeFloat32 CValueType = 1 << 13 - CValueTypeFloat64 CValueType = 1 << 14 + cValueTypeFloat32 CValueType = 1 << 13 + cValueTypeFloat64 CValueType = 1 << 14 - CValueTypeComplex64 CValueType = 1 << 15 - CValueTypeComplex128 CValueType = 1 << 16 + cValueTypeComplex64 CValueType = 1 << 15 + cValueTypeComplex128 CValueType = 1 << 16 - CValueTypeDuration CValueType = 1 << 17 - CValueTypeDate CValueType = 1 << 18 + cValueTypeDuration CValueType = 1 << 17 + cValueTypeDate CValueType = 1 << 18 - CValueTypeString CValueType = 1 << 19 - CValueTypeBytes CValueType = 1 << 20 - CValueTypeStack CValueType = 1 << 21 + cValueTypeString CValueType = 1 << 19 + cValueTypeBytes CValueType = 1 << 20 + cValueTypeStack CValueType = 1 << 21 - CValueTypeBaleable CValueType = 1 << 22 - CValueTypeError CValueType = 1 << 23 + cValueTypePackable CValueType = 1 << 22 + cValueTypeError CValueType = 1 << 23 - CValueTypeNil CValueType = 1 << 24 + cValueTypeNil CValueType = 1 << 24 - CValueTypeCValue CValueType = 1 << 25 - CValueTypeCField CValueType = 1 << 26 - CValueTypeObject CValueType = 1 << 27 + cValueTypeCValue CValueType = 1 << 25 + cValueTypeCField CValueType = 1 << 26 + cValueTypeObject CValueType = 1 << 27 - CValueTypeDefer CValueType = 1 << 28 - CValueTypeList CValueType = 1 << 29 - CValueTypeMap CValueType = 1 << 30 - CValueTypeMapKey CValueType = 1 << 31 + cValueTypeDefer CValueType = 1 << 28 + cValueTypeList CValueType = 1 << 29 + cValueTypeMap CValueType = 1 << 30 + cValueTypeMapKey CValueType = 1 << 31 - maskCValueTypeComposite= CValueTypeDefer|CValueTypeList|CValueTypeMap - maskCValueTypeBase = ^(maskCValueTypeComposite | CValueTypeMapKey) + maskCValueTypeComposite= cValueTypeDefer | cValueTypeList | cValueTypeMap + maskCValueTypeBase = ^(maskCValueTypeComposite | cValueTypeMapKey) ) @@ -99,64 +99,64 @@ type ( func (t CValueType) IsComposite() bool { return t&maskCValueTypeComposite != 0 } func (t CValueType) BaseType () CValueType { - if t&CValueTypeMap == 0 { + if t&cValueTypeMap == 0 { return t &maskCValueTypeBase } _,vt := t.MapType() return vt } -func (t CValueType) MapType () (CValueType,CValueType) { - if t&CValueTypeMap == 0 { - return CValueTypeInvalid, CValueTypeInvalid +func (t CValueType) MapType () (CValueType, CValueType) { + if t&cValueTypeMap == 0 { + return cValueTypeInvalid, cValueTypeInvalid } bs := t &maskCValueTypeBase switch bits.OnesCount32(uint32(bs)) { case 1: return bs,bs case 2: - if t&CValueTypeMapKey == 0 { + if t&cValueTypeMapKey == 0 { return bs&-bs,bs&^(bs&-bs) } return bs&^(bs&-bs),bs&-bs default: - return CValueTypeInvalid,CValueTypeInvalid + return cValueTypeInvalid, cValueTypeInvalid } } -func (t CValueType) IsTypeInvalid () bool { return t&maskCValueTypeBase == CValueTypeInvalid } -func (t CValueType) IsTypeAny () bool { return t&maskCValueTypeBase == CValueTypeAny } -func (t CValueType) IsTypeBool () bool { return t&maskCValueTypeBase == CValueTypeBool } -func (t CValueType) IsTypeInt () bool { return t&maskCValueTypeBase == CValueTypeInt } -func (t CValueType) IsTypeInt8 () bool { return t&maskCValueTypeBase == CValueTypeInt8 } -func (t CValueType) IsTypeInt16 () bool { return t&maskCValueTypeBase == CValueTypeInt16 } -func (t CValueType) IsTypeInt32 () bool { return t&maskCValueTypeBase == CValueTypeInt32 } -func (t CValueType) IsTypeInt64 () bool { return t&maskCValueTypeBase == CValueTypeInt64 } -func (t CValueType) IsTypeUint () bool { return t&maskCValueTypeBase == CValueTypeUint } -func (t CValueType) IsTypeUint8 () bool { return t&maskCValueTypeBase == CValueTypeUint8 } -func (t CValueType) IsTypeUint16 () bool { return t&maskCValueTypeBase == CValueTypeUint16 } -func (t CValueType) IsTypeUint32 () bool { return t&maskCValueTypeBase == CValueTypeUint32 } -func (t CValueType) IsTypeUint64 () bool { return t&maskCValueTypeBase == CValueTypeUint64 } -func (t CValueType) IsTypeUintptr () bool { return t&maskCValueTypeBase == CValueTypeUintptr } -func (t CValueType) IsTypeFloat32 () bool { return t&maskCValueTypeBase == CValueTypeFloat32 } -func (t CValueType) IsTypeFloat64 () bool { return t&maskCValueTypeBase == CValueTypeFloat64 } -func (t CValueType) IsTypeComplex64 () bool { return t&maskCValueTypeBase == CValueTypeComplex64} -func (t CValueType) IsTypeComplex128 () bool { return t&maskCValueTypeBase == CValueTypeComplex128} -func (t CValueType) IsTypeDuration () bool { return t&maskCValueTypeBase == CValueTypeDuration } -func (t CValueType) IsTypeDate () bool { return t&maskCValueTypeBase == CValueTypeDate } -func (t CValueType) IsTypeString () bool { return t&maskCValueTypeBase == CValueTypeString } -func (t CValueType) IsTypeBytes () bool { return t&maskCValueTypeBase == CValueTypeBytes } -func (t CValueType) IsTypeStack () bool { return t&maskCValueTypeBase == CValueTypeStack } -func (t CValueType) IsTypeBaleable () bool { return t&maskCValueTypeBase == CValueTypeBaleable } -func (t CValueType) IsTypeError () bool { return t&maskCValueTypeBase == CValueTypeError } -func (t CValueType) IsTypeNil () bool { return t&maskCValueTypeBase == CValueTypeNil } -func (t CValueType) IsTypeCVal () bool { return t&maskCValueTypeBase == CValueTypeCValue } -func (t CValueType) IsTypeCField () bool { return t&maskCValueTypeBase == CValueTypeCField } -func (t CValueType) IsTypeObject () bool { return t&maskCValueTypeBase == CValueTypeObject } - -func (t CValueType) IsDefer () bool { return t&CValueTypeDefer != 0 } -func (t CValueType) IsList () bool { return t&CValueTypeList != 0 } -func (t CValueType) IsMap () bool { return t&CValueTypeMap != 0 } +func (t CValueType) IsInvalid() bool { return t&maskCValueTypeBase == cValueTypeInvalid } +func (t CValueType) IsAny() bool { return t&maskCValueTypeBase == cValueTypeAny } +func (t CValueType) IsBool() bool { return t&maskCValueTypeBase == cValueTypeBool } +func (t CValueType) IsInt() bool { return t&maskCValueTypeBase == cValueTypeInt } +func (t CValueType) IsInt8() bool { return t&maskCValueTypeBase == cValueTypeInt8 } +func (t CValueType) IsInt16() bool { return t&maskCValueTypeBase == cValueTypeInt16 } +func (t CValueType) IsInt32() bool { return t&maskCValueTypeBase == cValueTypeInt32 } +func (t CValueType) IsInt64() bool { return t&maskCValueTypeBase == cValueTypeInt64 } +func (t CValueType) IsUint() bool { return t&maskCValueTypeBase == cValueTypeUint } +func (t CValueType) IsUint8() bool { return t&maskCValueTypeBase == cValueTypeUint8 } +func (t CValueType) IsUint16() bool { return t&maskCValueTypeBase == cValueTypeUint16 } +func (t CValueType) IsUint32() bool { return t&maskCValueTypeBase == cValueTypeUint32 } +func (t CValueType) IsUint64() bool { return t&maskCValueTypeBase == cValueTypeUint64 } +func (t CValueType) IsUintptr() bool { return t&maskCValueTypeBase == cValueTypeUintptr } +func (t CValueType) IsFloat32() bool { return t&maskCValueTypeBase == cValueTypeFloat32 } +func (t CValueType) IsFloat64() bool { return t&maskCValueTypeBase == cValueTypeFloat64 } +func (t CValueType) IsComplex64 () bool { return t&maskCValueTypeBase == cValueTypeComplex64 } +func (t CValueType) IsComplex128() bool { return t&maskCValueTypeBase == cValueTypeComplex128 } +func (t CValueType) IsDuration()bool { return t&maskCValueTypeBase == cValueTypeDuration } +func (t CValueType) IsDate() bool { return t&maskCValueTypeBase == cValueTypeDate } +func (t CValueType) IsString() bool { return t&maskCValueTypeBase == cValueTypeString } +func (t CValueType) IsBytes() bool { return t&maskCValueTypeBase == cValueTypeBytes } +func (t CValueType) IsStack() bool { return t&maskCValueTypeBase == cValueTypeStack } +func (t CValueType) IsBaleable()bool { return t&maskCValueTypeBase == cValueTypePackable } +func (t CValueType) IsError() bool { return t&maskCValueTypeBase == cValueTypeError } +func (t CValueType) IsNil() bool { return t&maskCValueTypeBase == cValueTypeNil } +func (t CValueType) IsCValue() bool { return t&maskCValueTypeBase == cValueTypeCValue } +func (t CValueType) IsCField() bool { return t&maskCValueTypeBase == cValueTypeCField } +func (t CValueType) IsObject() bool { return t&maskCValueTypeBase == cValueTypeObject } + +func (t CValueType) IsDefer () bool { return t&cValueTypeDefer != 0 } +func (t CValueType) IsList () bool { return t&cValueTypeList != 0 } +func (t CValueType) IsMap () bool { return t&cValueTypeMap != 0 } func (t CValueType) String () string { @@ -165,16 +165,16 @@ func (t CValueType) String () string { func buildMapType(keyType, valType CValueType) CValueType { - if keyType == CValueTypeInvalid || valType == CValueTypeInvalid { - return CValueTypeInvalid + if keyType == cValueTypeInvalid || valType == cValueTypeInvalid { + return cValueTypeInvalid } if keyType == valType { - return CValueTypeMap|keyType + return cValueTypeMap |keyType } if keyType < valType { - return CValueTypeMap|keyType|valType + return cValueTypeMap |keyType|valType } - return CValueTypeMap|valType|keyType|CValueTypeMapKey + return cValueTypeMap |valType|keyType| cValueTypeMapKey } diff --git a/src/core/vals/cvalue_type_infos.go b/src/core/vals/cvalue_type_infos.go index 8c51d71..b7a3f0b 100644 --- a/src/core/vals/cvalue_type_infos.go +++ b/src/core/vals/cvalue_type_infos.go @@ -29,11 +29,9 @@ package vals import ( - "math" "math/bits" "reflect" "sync" - "time" ) const( @@ -52,8 +50,6 @@ type ( mux sync.RWMutex names [maxCValueTypes+1]string creators [maxCValueTypes+1][cValueNumCreators]func(any)CValue - minTime, - maxTime time.Time cache map[reflect.Type]func(value any)CValue } ) @@ -61,8 +57,7 @@ type ( func newCValueTypeInfos () *CValueTypeInfos { is := CValueTypeInfos{ - minTime : time.Unix(0, math.MinInt64), - maxTime : time.Unix(0, math.MaxInt64), + cache : make(map[reflect.Type]func(value any)CValue), names : [maxCValueTypes+1]string{ /* 0: */ "invalid", @@ -100,51 +95,51 @@ func newCValueTypeInfos () *CValueTypeInfos { /* 32: */ "flag", }, creators: [maxCValueTypes+1][cValueNumCreators]func(any)CValue{ - /* 0: */ createGValCreators[any ](CValueTypeInvalid,createCValueInvalid), - /* 1: */ createGValCreators[any ](CValueTypeAny, createCValueAny), - /* 2: */ createGValCreators[bool ](CValueTypeBool, CreateCValueBool), - /* 3: */ createGValCreators[int ](CValueTypeInt, CreateCValueInt), - /* 4: */ createGValCreators[int8 ](CValueTypeInt8, CreateCValueInt8), - /* 5: */ createGValCreators[int16 ](CValueTypeInt16, CreateCValueInt16), - /* 6: */ createGValCreators[int32 ](CValueTypeInt32, CreateCValueInt32), - /* 7: */ createGValCreators[int64 ](CValueTypeInt64, CreateCValueInt64), - /* 8: */ createGValCreators[uint ](CValueTypeUint, CreateCValueUint), + /* 0: */ createGValCreators[any ](cValueTypeInvalid,createCValueInvalid), + /* 1: */ createGValCreators[any ](cValueTypeAny, createCValueAny), + /* 2: */ createGValCreators[bool ](cValueTypeBool, CreateCValueBool), + /* 3: */ createGValCreators[int ](cValueTypeInt, CreateCValueInt), + /* 4: */ createGValCreators[int8 ](cValueTypeInt8, CreateCValueInt8), + /* 5: */ createGValCreators[int16 ](cValueTypeInt16, CreateCValueInt16), + /* 6: */ createGValCreators[int32 ](cValueTypeInt32, CreateCValueInt32), + /* 7: */ createGValCreators[int64 ](cValueTypeInt64, CreateCValueInt64), + /* 8: */ createGValCreators[uint ](cValueTypeUint, CreateCValueUint), /* caso en el que []uint debe de establecerse como bytes procedemos a construirlo manualmente */ /* 9 :*/ { func(v any) CValue { return CreateCValueUint8 (v.(uint8)) }, - func(v any) CValue { return createGValTypePointer(CValueTypeUint8, CreateCValueUint8, v.(*uint8)) }, - func(v any) CValue { return createGValTypeList (CValueTypeBytes, v.([]uint8)) }, - func(v any) CValue { return createGValTypeDefer (CValueTypeDefer|CValueTypeUint8, v.(func() uint8))}, + func(v any) CValue { return createGValTypePointer(cValueTypeUint8, CreateCValueUint8, v.(*uint8)) }, + func(v any) CValue { return createGValTypeList (cValueTypeBytes, v.([]uint8)) }, + func(v any) CValue { return createGValTypeDefer (cValueTypeDefer|cValueTypeUint8, v.(func() uint8))}, }, - /* 10:*/ createGValCreators[uint16 ](CValueTypeUint16, CreateCValueUint16), - /* 11:*/ createGValCreators[uint32 ](CValueTypeUint32, CreateCValueUint32), - /* 12:*/ createGValCreators[uint64 ](CValueTypeUint64, CreateCValueUint64), - /* 13:*/ createGValCreators[uintptr ](CValueTypeUintptr, CreateCValueUintptr), - - /* 14:*/ createGValCreators[float32 ](CValueTypeFloat32, CreateCValueFloat32), - /* 15:*/ createGValCreators[float64 ](CValueTypeFloat64, CreateCValueFloat64), - /* 16:*/ createGValCreators[complex64 ](CValueTypeComplex64, CreateCValueComplex64), - /* 17:*/ createGValCreators[complex128 ](CValueTypeComplex128, CreateCValueComplex128), - - /* 18:*/ createGValCreators[Duration ](CValueTypeDuration, CreateCValueDuration), - /* 19:*/ createGValCreators[Date ](CValueTypeDate, CreateCValueDate), - - /* 20:*/ createGValCreators[string ](CValueTypeString, CreateCValueString), - /* 21:*/ createGValCreators[Bytes ](CValueTypeBytes, CreateCValueBytes), - /* 22:*/ createGValCreators[Stack ](CValueTypeStack, CreateCValueStack), - /* 23:*/ createGValCreators[Baleable ](CValueTypeBaleable, CreateCValueBaleable), - /* 24:*/ createGValCreators[error ](CValueTypeError, CreateCValueError), - /* 25:*/ createGValCreators[any ](CValueTypeNil, CreateCValueNil), - /* 26:*/ createGValCreators[CValue ](CValueTypeCValue, createCValueCValue), - /* 27:*/ createGValCreators[CField ](CValueTypeCField, createCValueCField), - /* 28:*/ createGValCreators[any ](CValueTypeObject, createCValueObject), - /* 29:*/ createGValCreators[any ](CValueTypeDefer, CreateCValueDefer), - /* 30:*/ createGValCreators[any ](CValueTypeList, CreateCValueList), - /* 31:*/ createGValCreators[any ](CValueTypeMap, CreateCValueMap), - /* 32:*/ createGValCreators[any ](CValueTypeObject, createCValueInvalid), + /* 10:*/ createGValCreators[uint16 ](cValueTypeUint16, CreateCValueUint16), + /* 11:*/ createGValCreators[uint32 ](cValueTypeUint32, CreateCValueUint32), + /* 12:*/ createGValCreators[uint64 ](cValueTypeUint64, CreateCValueUint64), + /* 13:*/ createGValCreators[uintptr ](cValueTypeUintptr, CreateCValueUintptr), + + /* 14:*/ createGValCreators[float32 ](cValueTypeFloat32, CreateCValueFloat32), + /* 15:*/ createGValCreators[float64 ](cValueTypeFloat64, CreateCValueFloat64), + /* 16:*/ createGValCreators[complex64 ](cValueTypeComplex64, CreateCValueComplex64), + /* 17:*/ createGValCreators[complex128 ](cValueTypeComplex128, CreateCValueComplex128), + + /* 18:*/ createGValCreators[Duration ](cValueTypeDuration, CreateCValueDuration), + /* 19:*/ createGValCreators[Date ](cValueTypeDate, CreateCValueDate), + + /* 20:*/ createGValCreators[string ](cValueTypeString, CreateCValueString), + /* 21:*/ createGValCreators[Bytes ](cValueTypeBytes, CreateCValueBytes), + /* 22:*/ createGValCreators[Stack ](cValueTypeStack, CreateCValueStack), + /* 23:*/ createGValCreators[Packable](cValueTypePackable, CreateCValueBaleable), + /* 24:*/ createGValCreators[error ](cValueTypeError, CreateCValueError), + /* 25:*/ createGValCreators[any ](cValueTypeNil, CreateCValueNil), + /* 26:*/ createGValCreators[CValue ](cValueTypeCValue, createCValueCValue), + /* 27:*/ createGValCreators[CField ](cValueTypeCField, createCValueCField), + /* 28:*/ createGValCreators[any ](cValueTypeObject, createCValueObject), + /* 29:*/ createGValCreators[any ](cValueTypeDefer, CreateCValueDefer), + /* 30:*/ createGValCreators[any ](cValueTypeList, CreateCValueList), + /* 31:*/ createGValCreators[any ](cValueTypeMap, CreateCValueMap), + /* 32:*/ createGValCreators[any ](cValueTypeObject, createCValueInvalid), }, } return &is @@ -201,7 +196,7 @@ func (i *CValueTypeInfos) CreateCValue(value any) CValue { case string : f = i.creators[20/* String */][cValueByVal] case Bytes : f = i.creators[21/* Bytes */][cValueByVal] case Stack : f = i.creators[22/* Stack */][cValueByVal] - case Baleable : f = i.creators[23/* Baleable */][cValueByVal] + case Packable: f = i.creators[23 /* Packable */][cValueByVal] case error : f = i.creators[24/* Error */][cValueByVal] case CValue : f = i.creators[26/* CVal */][cValueByVal] case CField : f = i.creators[27/* CCField */][cValueByVal] @@ -216,7 +211,7 @@ func (i *CValueTypeInfos) CreateCValue(value any) CValue { case []int64 : f = i.creators[ 7/* Int64 */][cValueByLst] case []uint : f = i.creators[ 8/* Uint */][cValueByLst] // ya establecido como tipo base Bytes - //case []uint8 : f = i.creators[ 9/* CValueTypeUint8 */].listCreator + //case []uint8 : f = i.creators[ 9/* cValueTypeUint8 */].listCreator // case []uint16 : f = i.creators[10/* Uint16 */][cValueByLst] case []uint32 : f = i.creators[11/* Uint32 */][cValueByLst] @@ -231,7 +226,7 @@ func (i *CValueTypeInfos) CreateCValue(value any) CValue { case []string : f = i.creators[20/* String */][cValueByLst] case []Bytes : f = i.creators[21/* String */][cValueByLst] case []Stack : f = i.creators[22/* Stack */][cValueByLst] - case []Baleable : f = i.creators[23/* Baleable */][cValueByLst] + case []Packable: f = i.creators[23 /* Packable */][cValueByLst] case []error : f = i.creators[24/* Error */][cValueByLst] case []CValue : f = i.creators[26/* CValue */][cValueByLst] case []CField : f = i.creators[27/* CField */][cValueByLst] @@ -259,7 +254,7 @@ func (i *CValueTypeInfos) CreateCValue(value any) CValue { case *string : f = i.creators[20/* String */][cValueByPtr] case *Bytes : f = i.creators[21/* Bytes */][cValueByPtr] case *Stack : f = i.creators[22/* Stack */][cValueByPtr] - case *Baleable : f = i.creators[23/* Baleable */][cValueByPtr] + case *Packable: f = i.creators[23 /* Packable */][cValueByPtr] case *error : f = i.creators[24/* Error */][cValueByPtr] case *CValue : f = i.creators[26/* CValue */][cValueByPtr] case *CField : f = i.creators[27/* CField */][cValueByPtr] @@ -287,7 +282,7 @@ func (i *CValueTypeInfos) CreateCValue(value any) CValue { case func()string : f = i.creators[20/* String */][cValueByDfr] case func()Bytes : f = i.creators[21/* Bytes */][cValueByDfr] case func()Stack : f = i.creators[22/* Stack */][cValueByDfr] - case func()Baleable : f = i.creators[23/* Baleable */][cValueByDfr] + case func() Packable: f = i.creators[23 /* Packable */][cValueByDfr] case func()error : f = i.creators[24/* Error */][cValueByDfr] case func()CValue : f = i.creators[26/* CVal */][cValueByDfr] case func()CField : f = i.creators[27/* CField */][cValueByDfr] @@ -305,7 +300,7 @@ func (i *CValueTypeInfos) CreateCValue(value any) CValue { func (i *CValueTypeInfos) createByReflection(value any) CValue { rv := reflect.ValueOf(value) if !rv.IsValid() { - return createCValueWithInvalidError(value,CValueTypeAny,0,E.InvalidCValueReflected) + return createCValueWithInvalidError(value, cValueTypeAny,0,E.InvalidCValueReflected) } rt := rv.Type() @@ -317,23 +312,23 @@ func (i *CValueTypeInfos) createByReflection(value any) CValue { } i.mux.RUnlock() - vt := CValueTypeAny + vt := cValueTypeAny switch rt.Kind() { // Los tipos soportados deben de haber sido capturados // por el switch de tipos case reflect.Struct : // createCValueAny - vt = CValueTypeObject + vt = cValueTypeObject case reflect.Func : if rt.NumIn() == 0 && rt.NumOut() == 1 { - vt = CValueTypeDefer|CValueTypeAny + vt = cValueTypeDefer | cValueTypeAny } case reflect.Map : var kt,et CValueType - if kt = reflectKindToCValueType(rt.Key().Kind(),true); kt != CValueTypeInvalid { - if et = reflectKindToCValueType(rt.Elem().Kind(),true); et != CValueTypeInvalid { + if kt = reflectKindToCValueType(rt.Key().Kind(),true); kt != cValueTypeInvalid { + if et = reflectKindToCValueType(rt.Elem().Kind(),true); et != cValueTypeInvalid { vt = buildMapType(kt,et) } } @@ -341,12 +336,12 @@ func (i *CValueTypeInfos) createByReflection(value any) CValue { case reflect.Slice, reflect.Array : ke := reflectKindToCValueType(rt.Elem().Kind(),true) - if ke != CValueTypeInvalid { - vt = ke|CValueTypeList + if ke != cValueTypeInvalid { + vt = ke| cValueTypeList } case reflect.Interface: - vt = CValueTypeAny + vt = cValueTypeAny } f = func(v any) CValue { @@ -383,7 +378,7 @@ func createCValueReflected (value any, rv reflect.Value, vtype CValueType, check return createCValueWithInvalidError(value,vtype,vs,E.InvalidCValueForType) } ke := reflectKindToCValueType(rt.Elem().Kind(), true) - if ke == CValueTypeInvalid { + if ke == cValueTypeInvalid { return createCValueWithInvalidError(value,vtype,vs,E.InvalidCValueForType) } vtype |= ke @@ -405,11 +400,11 @@ func createCValueReflected (value any, rv reflect.Value, vtype CValueType, check return createCValueWithInvalidError(value,vtype,vs|cValueStateInvalid,E.InvalidCValueForType) } kt := reflectKindToCValueType(rt.Key().Kind(), true) - if kt == CValueTypeInvalid { + if kt == cValueTypeInvalid { return createCValueWithInvalidError(value,vtype,vs|cValueStateInvalid,E.InvalidCValueForType) } et := reflectKindToCValueType(rt.Elem().Kind(), true) - if et == CValueTypeInvalid { + if et == cValueTypeInvalid { return createCValueWithInvalidError(value,vtype,vs|cValueStateInvalid,E.InvalidCValueForType) } vtype = buildMapType(kt, et) @@ -433,7 +428,7 @@ func createCValueReflected (value any, rv reflect.Value, vtype CValueType, check if rt.NumIn() != 0 || rt.NumOut() != 1 { return createCValueWithInvalidError(value,vtype,vs,E.InvalidCValueForType) } - vtype = CValueTypeDefer|CValueTypeAny + vtype = cValueTypeDefer | cValueTypeAny } if rv.IsNil() { vs|=cValueStateNil @@ -446,7 +441,7 @@ func createCValueReflected (value any, rv reflect.Value, vtype CValueType, check case reflect.Struct : if check { - if !vtype.IsTypeObject() { + if !vtype.IsObject() { return createCValueWithInvalidError(value,vtype,vs,E.InvalidCValueForType) } } @@ -473,8 +468,8 @@ func createGValCreators [T any] (valType CValueType, createFnc func(value T) CVa return [cValueNumCreators]func(any)CValue { func(v any) CValue { return createFnc(v.(T)) }, func(v any) CValue { return createGValTypePointer(valType,createFnc,v.(*T))}, - func(v any) CValue { return createGValTypeList (CValueTypeList |valType,v.([]T)) }, - func(v any) CValue { return createGValTypeDefer (CValueTypeDefer|valType,v.(func() T)) }, + func(v any) CValue { return createGValTypeList (cValueTypeList|valType,v.([]T)) }, + func(v any) CValue { return createGValTypeDefer (cValueTypeDefer|valType,v.(func() T)) }, } } @@ -506,7 +501,7 @@ func createGValTypeDefer[T any](vType CValueType,value func()T) CValue { func buildCValueInvalidWithError (err string) func(v any) CValue { return func(v any) CValue { - return CValue{vType: CValueTypeInvalid, vState: cValueStateInvalid|cValueStateError, anyVal: v, strVal: err } + return CValue{vType: cValueTypeInvalid, vState: cValueStateInvalid|cValueStateError, anyVal: v, strVal: err } } } @@ -515,40 +510,40 @@ func buildCValueInvalidWithError (err string) func(v any) CValue { func reflectKindToCValueType (kind reflect.Kind, base bool) CValueType { switch kind { - case reflect.Invalid: return CValueTypeInvalid - case reflect.Bool: return CValueTypeBool - case reflect.Int: return CValueTypeInt - case reflect.Int8: return CValueTypeInt8 - case reflect.Int16: return CValueTypeInt16 - case reflect.Int32: return CValueTypeInt32 - case reflect.Int64: return CValueTypeInt64 - case reflect.Uint: return CValueTypeUint - case reflect.Uint8: return CValueTypeUint8 - case reflect.Uint16: return CValueTypeUint16 - case reflect.Uint32: return CValueTypeUint32 - case reflect.Uint64: return CValueTypeUint64 - case reflect.Uintptr: return CValueTypeUintptr - case reflect.Float32: return CValueTypeFloat32 - case reflect.Float64: return CValueTypeFloat64 - case reflect.Complex64: return CValueTypeComplex64 - case reflect.Complex128:return CValueTypeComplex128 - case reflect.String: return CValueTypeString - case reflect.Struct: return CValueTypeObject + case reflect.Invalid: return cValueTypeInvalid + case reflect.Bool: return cValueTypeBool + case reflect.Int: return cValueTypeInt + case reflect.Int8: return cValueTypeInt8 + case reflect.Int16: return cValueTypeInt16 + case reflect.Int32: return cValueTypeInt32 + case reflect.Int64: return cValueTypeInt64 + case reflect.Uint: return cValueTypeUint + case reflect.Uint8: return cValueTypeUint8 + case reflect.Uint16: return cValueTypeUint16 + case reflect.Uint32: return cValueTypeUint32 + case reflect.Uint64: return cValueTypeUint64 + case reflect.Uintptr: return cValueTypeUintptr + case reflect.Float32: return cValueTypeFloat32 + case reflect.Float64: return cValueTypeFloat64 + case reflect.Complex64: return cValueTypeComplex64 + case reflect.Complex128:return cValueTypeComplex128 + case reflect.String: return cValueTypeString + case reflect.Struct: return cValueTypeObject case reflect.Array, reflect.Slice: if base { - return CValueTypeList + return cValueTypeList } - return CValueTypeAny + return cValueTypeAny case reflect.Map: if base { - return CValueTypeMap + return cValueTypeMap } - return CValueTypeAny + return cValueTypeAny default: - return CValueTypeAny + return cValueTypeAny } } diff --git a/src/core/vals/types.go b/src/core/vals/types.go index 8515979..286bc0e 100644 --- a/src/core/vals/types.go +++ b/src/core/vals/types.go @@ -29,8 +29,8 @@ package vals import ( - "core/blrs" "core/excs" + "core/pkrs" "time" ) @@ -41,7 +41,8 @@ type ( Date = time.Time Duration = time.Duration Stack = excs.Stack - Baleable = blrs.Baleable + Packer = pkrs.Packer + Packable = pkrs.Packable )