Empezado la adaptacion del modulos de logs

master
DEV 2 years ago
parent 20060c28fd
commit b714acbc5b

@ -1,135 +1,28 @@
package main
import (
"errs"
"errs/collects"
"errs/fjson"
"errs/ftext"
"errs/stack"
"fmt"
"time"
)
func printTrace (s stack.Trace) {
lf := s.Frames()
for i,f := range lf {
fmt.Printf("%d file %s line %d %s\n",i,f.File,f.LineNumber,f.FuncName)
}
}
func GenerateBinaryString() string {
binaryString := ""
for c := 0; c < 255; c++ {
if ('a' <= byte(c) && byte(c) <= 'z') || ('A' <= byte(c) && byte(c) <= 'Z') || byte(c) == '@' {
binaryString += "1"
} else {
binaryString += "0"
}
}
return binaryString
}
type (
MiCustomErr struct {
error
ms string
}
)
func (c MiCustomErr) Message() string {
return "esto es un custom werro"
}
func (c MiCustomErr) Code() string {
return "custom-code"
}
func (c MiCustomErr) Int () int {
return 33423
}
func (c MiCustomErr) Error () string {
return "ERRRROPROO"
}
func (c MiCustomErr) Unwrap () error {
return c.error
}
func (c MiCustomErr) Collect (collector collects.Collector) {
collector.AddFieldInt("UnInt",c.Int())
collector.AddFieldFloat("UnFloat",34.33)
collector.AddFieldAny("UnoCualquiera",struct {
A string
B int
T time.Time
F float64
}{
A : "UUnA",
B : 3,
T : time.Now(),
F : 2.343,
})
}
func printCollection (ec collects.ErrorCollection) {
if ec.Invalid != nil {
fmt.Printf("INvalid %s\n", ec.Invalid.Error())
}
ec.Fields.Sort()
fmt.Printf("Error: %s\n",ec.ErrStr)
fmt.Printf("Types: %d\n",len(ec.Types))
for _,t := range ec.Types {
fmt.Printf("\tWrap Type : %s\n",t.String())
}
fmt.Printf("Fields: \n")
for _,h := range ec.Fields.GetHeads() {
fmt.Printf("\t%s : %v\n",h.Name)
}
fmt.Printf("Causes: \n")
for _,c := range ec.Causes {
printCollection(c)
}
}
func main() {
me := errs.WrapWithCause(errs.WrapWithInfo(MiCustomErr{},
errs.ErrInfoWithInfo("Mi mensaje")),errs.ErrCode("UnERRORito"))
mu := errs.NewErrMulti(
errs.ErrCode("UnError"),
errs.ErrCode("UnOtro"),
me,
)
filters := logs.NewFilters()
filters.AddFilterAllowed(logs.NewFilter("1",func(e *logs.Entry) bool {
fmt.Println("UNO FILTER")
return e.Level.Has(logs.LevelWarn)
}))
//printCollection(*collr.NewErrorCollection(me).Collect(true,true,true))
filters.AddFilterAllowed(logs.NewFilter("2",func(e *logs.Entry) bool {
fmt.Println("DS FILTER")
return e.Level.Has(logs.LevelDebug)
}))
f := ftext.DefaultFormatter()
j := fjson.DefaultFormatter()
fmt.Print(string(f.FormatError(errs.WrapWithTrace(mu,1))))
fmt.Print(string(j.FormatError(errs.WrapWithTrace(mu,1))))
fmt.Printf("Pasado %v\n",filters.Filter(logs.NewEntry(nil,logs.LevelWarn.Add(logs.LevelDebug),"",nil)))
}

@ -64,12 +64,11 @@ type (
)
// NewTokenizerCore
// NewATokenizer
// Function constructor -> ATokenizer
//
//
func NewTokenizerCore(options ...ATokenizerFnc) *ATokenizer {
func NewATokenizer(options ...ATokenizerFnc) *ATokenizer {
tk := &ATokenizer{
aTokenizerChars : *newATokenizerChars(),
MinLenToken : tokenMinLen,

@ -23,8 +23,6 @@
package crypts
import "rsts"
type (
Decrypter interface {

@ -23,11 +23,6 @@
package crypts
import (
"rsts"
)
type (

@ -27,7 +27,7 @@ import (
"sort"
"sync"
"sync/atomic"
"syncs"
"syncs/pools"
)
@ -35,7 +35,7 @@ import (
type (
Pool struct {
syncs.PoolStatsInfo
pools.PoolStatsInfo
inner sync.Pool
@ -54,7 +54,14 @@ type (
)
func NewPool(options ...PoolFnc) *Pool {
return applyBufferPoolOptions(&Pool{percentile: poolPercentile}, options...) }
p :=&Pool {
percentile: poolPercentile,
}
for _,o := range options {
o(p)
}
return p
}
func (p *Pool) MaxSize() uint64 {
@ -104,12 +111,12 @@ func (p *Pool) calibrate() {
if atomic.CompareAndSwapUint64(&p.calibra, 0, 1) {
return
}
ar := make(syncs.PoolCallSizes, 0, poolSteps)
ar := make(pools.PoolCallSizes, 0, poolSteps)
cs := uint64(0)
for i := uint64(0); i < poolSteps; i++ {
cl := atomic.SwapUint64(&p.calls[i], 0)
cs += cl
ar = append(ar, syncs.PoolCallSize{
ar = append(ar, pools.PoolCallSize{
Calls: cl,
Size: minSize << i})
}
@ -155,19 +162,13 @@ func index(n int) int {
func applyBufferPoolOptions (b *Pool, options ...PoolFnc) *Pool {
for _,o := range options {
o(b)
}
return b
}
func WithMaxPercentile(percentile float32) PoolFnc {
return func(b *Pool) {
b.percentile = percentile } }
return func(p *Pool) {
p.percentile = percentile } }
func CallsThreshold(threshold uint64) PoolFnc {
return func(b *Pool) {
atomic.StoreUint64(&b.threshold, threshold) } }
return func(p *Pool) {
atomic.StoreUint64(&p.threshold, threshold) } }

@ -0,0 +1,3 @@
module results
go 1.22

@ -1,3 +0,0 @@
module rsts
go 1.22

@ -0,0 +1,109 @@
//
// Feb21
//
// GO Active Thing
// Framework
//
// http://activething.com/dev/goat
//
// Dev : Juan V.Navarro
// Email: juanvnl@activething.com
// Date : 16/02/2021
//
// Copyright 2021 the GOAT Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package syncs
import (
"sync/atomic"
)
type (
// ABool
// Type: Struct
// Desc: Atomic Bool, estructura para realizar operaciones atomicas
// sobre un valor de tipo Bool
//
ABool struct {
// value: valor sobre el que se realizaran las operaciones
// atomicas.
//
value uint32
}
)
// NewABool
// Desc: Función constructor para ABool
//
// Prms: val, valor inicial
// Rets: Puntero al nuevo objeto creado.
//
func NewABool(val bool) *ABool { return &ABool{value: boolAsUint32(val)} }
// ABool.Get
// Desc:
// Rets:
//
func (b *ABool) Get() bool { return atomic.LoadUint32(&b.value) == 1 }
// ABool.Set
// Desc:
// Prms:
//
func (b *ABool) Set(val bool) { atomic.StoreUint32(&b.value, boolAsUint32(val)) }
// ABool.Swap
// Desc:
// Prms:
//
func (b *ABool) Swap(new bool) bool { return atomic.SwapUint32(&b.value, boolAsUint32(new)) == 1 }
// ABool.CAS
// Desc:
// Prms:
// Rets:
//
func (b *ABool) CAS(old, new bool) bool {
return atomic.CompareAndSwapUint32(&b.value, boolAsUint32(old), boolAsUint32(new))
}
// boolAsUint32
// Desc: Convierte un valor de tipo bool a uint32
// Prms: val, valor a convertir
// Rets: uint32, El valor segun sea true = 1 o
// false = *
//
func boolAsUint32(val bool) uint32 {
if val {
return 1
}
return 0
}
/*
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA.
"LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS.
SIDDHARTA
- HERMANN HESSE -
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/

@ -0,0 +1,117 @@
//
// Feb21
//
// GO Active Thing
// Framework
//
// http://activething.com/dev/goat
//
// Dev : Juan V.Navarro
// Email: juanvnl@activething.com
// Date : 16/02/2021
//
// Copyright 2021 the GOAT Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package syncs
import (
"sync/atomic"
"time"
)
type (
// ADuration
// Type: Struct
//
// Desc:
//
//
ADuration struct {
value int64
}
)
// NewADuration
// Desc: Función constructor para ADuration
//
// Prms: val, valor inicial
// Rets: Puntero al nuevo objeto creado.
//
func NewADuration(val time.Duration) *ADuration { return &ADuration{value: int64(val)} }
// ADuration.Get
// Desc:
// Prms:
// Rets:
//
func (i *ADuration) Get() time.Duration { return time.Duration(atomic.LoadInt64(&i.value)) }
// ADuration.Set
// Desc:
// Prms:
// Rets:
//
func (i *ADuration) Set(val time.Duration) { atomic.StoreInt64(&i.value, int64(val)) }
// ADuration.Swap
// Desc:
// Prms:
// Rets:
//
func (i *ADuration) Swap(new time.Duration) time.Duration {
return time.Duration(atomic.SwapInt64(&i.value, int64(new)))
}
// ADuration.Add
// Desc:
// Prms:
// Rets:
//
func (i *ADuration) Add(dlt time.Duration) time.Duration {
return time.Duration(atomic.AddInt64(&i.value, int64(dlt)))
}
// ADuration.Sub
// Desc:
// Prms:
// Rets:
//
func (i *ADuration) Sub(dlt time.Duration) time.Duration {
return time.Duration(atomic.AddInt64(&i.value, int64(-dlt)))
}
// ADuration.CAS
// Desc:
// Prms:
// Rets:
//
func (i *ADuration) CAS(old, new time.Duration) bool {
return atomic.CompareAndSwapInt64(&i.value, int64(old), int64(new))
}
/*
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA.
"LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS.
SIDDHARTA
- HERMANN HESSE -
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/

@ -0,0 +1,90 @@
//
// Feb21
//
// GO Active Thing
// Framework
//
// http://activething.com/dev/goat
//
// Dev : Juan V.Navarro
// Email: juanvnl@activething.com
// Date : 16/02/2021
//
// Copyright 2021 the GOAT Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package syncs
import (
"sync/atomic"
)
type (
// AError
// Type: Struct
// Desc:
//
//
AError struct {
value atomic.Value
}
)
// NewAError
// Desc: Función constructor para AError
//
// Prms: val, valor inicial
// Rets: Puntero al nuevo objeto creado.
//
func NewAError(err error) *AError {
ae := &AError{}
if err != nil {
ae.value.Store(err)
}
return ae
}
// AError.Set
// Desc:
// Prms:
// Rets:
//
func (a *AError) Set(err error) { a.value.Store(err) }
// AError.Get
// Desc:
// Prms:
// Rets:
//
func (a *AError) Get() error {
if vl := a.value.Load(); vl != nil {
return vl.(error)
}
return nil
}
/*
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA.
"LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS.
SIDDHARTA
- HERMANN HESSE -
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/

@ -0,0 +1,121 @@
//
// Feb21
//
// GO Active Thing
// Framework
//
// http://activething.com/dev/goat
//
// Dev : Juan V.Navarro
// Email: juanvnl@activething.com
// Date : 16/02/2021
//
// Copyright 2021 the GOAT Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package syncs
import (
"sync/atomic"
)
type (
// AInt32
// Type: Struct
// Desc:
//
//
AInt32 struct {
value int32
}
)
// NewAInt32
// Desc: Función constructor para AInt32
//
// Prms: val, valor inicial
// Rets: Puntero al nuevo objeto creado.
//
func NewAInt32(val int32) *AInt32 { return &AInt32{value: val} }
// AInt32.Get
// Desc:
// Prms:
// Rets:
//
func (i *AInt32) Get() int32 { return atomic.LoadInt32(&i.value) }
// AInt32.Set
// Desc:
// Prms:
// Rets:
//
func (i *AInt32) Set(val int32) { atomic.StoreInt32(&i.value, val) }
// AInt32.Swap
// Desc:
// Prms:
// Rets:
//
func (i *AInt32) Swap(new int32) int32 { return atomic.SwapInt32(&i.value, new) }
// AInt32.Add
// Desc:
// Prms:
// Rets:
//
func (i *AInt32) Add(dlt int32) int32 { return atomic.AddInt32(&i.value, dlt) }
// AInt32.Sub
// Desc:
// Prms:
// Rets:
//
func (i *AInt32) Sub(dlt int32) int32 { return atomic.AddInt32(&i.value, -dlt) }
// AInt32.Inc
// Desc:
// Prms:
// Rets:
//
func (i *AInt32) Inc() int32 { return i.Add(1) }
// AInt32.Dec
// Desc:
// Prms:
// Rets:
//
func (i *AInt32) Dec() int32 { return i.Add(-1) }
// AInt32.CAS
// Desc:
// Prms:
// Rets:
//
func (i *AInt32) CAS(old, new int32) bool { return atomic.CompareAndSwapInt32(&i.value, old, new) }
/*
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA.
"LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS.
SIDDHARTA
- HERMANN HESSE -
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/

@ -0,0 +1,121 @@
//
// Feb21
//
// GO Active Thing
// Framework
//
// http://activething.com/dev/goat
//
// Dev : Juan V.Navarro
// Email: juanvnl@activething.com
// Date : 16/02/2021
//
// Copyright 2021 the GOAT Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package syncs
import (
"sync/atomic"
)
type (
// AInt64
// Type: Struct
// Desc:
//
//
AInt64 struct {
value int64
}
)
// NewAInt64
// Desc: Función constructor para AInt64
//
// Prms: val, valor inicial
// Rets: Puntero al nuevo objeto creado.
//
func NewAInt64(val int64) *AInt64 { return &AInt64{value: val} }
// AInt64.Get
// Desc:
// Prms:
// Rets:
//
func (i *AInt64) Get() int64 { return atomic.LoadInt64(&i.value) }
// AInt64.Set
// Desc:
// Prms:
// Rets:
//
func (i *AInt64) Set(val int64) { atomic.StoreInt64(&i.value, val) }
// AInt64.Swap
// Desc:
// Prms:
// Rets:
//
func (i *AInt64) Swap(new int64) int64 { return atomic.SwapInt64(&i.value, new) }
// AInt64.Add
// Desc:
// Prms:
// Rets:
//
func (i *AInt64) Add(dlt int64) int64 { return atomic.AddInt64(&i.value, dlt) }
// AInt64.Sub
// Desc:
// Prms:
// Rets:
//
func (i *AInt64) Sub(dlt int64) int64 { return atomic.AddInt64(&i.value, -dlt) }
// AInt64.Inc
// Desc:
// Prms:
// Rets:
//
func (i *AInt64) Inc() int64 { return i.Add(1) }
// AInt64.Dec
// Desc:
// Prms:
// Rets:
//
func (i *AInt64) Dec() int64 { return i.Add(-1) }
// AInt64.CAS
// Desc:
// Prms:
// Rets:
//
func (i *AInt64) CAS(old, new int64) bool { return atomic.CompareAndSwapInt64(&i.value, old, new) }
/*
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA.
"LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS.
SIDDHARTA
- HERMANN HESSE -
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/

@ -0,0 +1,155 @@
//
// Feb21
//
// GO Active Thing
// Framework
//
// http://activething.com/dev/goat
//
// Dev : Juan V.Navarro
// Email: juanvnl@activething.com
// Date : 16/02/2021
//
// Copyright 2021 the GOAT Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package syncs
import (
"sync/atomic"
"time"
)
type (
// ANanos
// Type: Struct
// Desc:
//
//
ANanos struct {
value int64
}
)
// NewANanos
// Desc: Función constructor para ANanos
//
// Prms: val, valor inicial
// Rets: Puntero al nuevo objeto creado.
//
func NewANanos(val time.Duration) *ANanos { return &ANanos{value: int64(val)} }
// ANanos.Get
// Desc:
// Prms:
// Rets:
//
func (i *ANanos) Get() time.Duration { return time.Duration(atomic.LoadInt64(&i.value)) }
// ANanos.Set
// Desc:
// Prms:
// Rets:
//
func (i *ANanos) Set(val time.Duration) { atomic.StoreInt64(&i.value, int64(val)) }
// ANanos.Swap
// Desc:
// Prms:
// Rets:
//
func (i *ANanos) Swap(new time.Duration) time.Duration {
return time.Duration(atomic.SwapInt64(&i.value, int64(new)))
}
// ANanos.Add
// Desc:
// Prms:
// Rets:
//
func (i *ANanos) Add(dlt time.Duration) time.Duration {
return time.Duration(atomic.AddInt64(&i.value, int64(dlt)))
}
// ANanos.Sub
// Desc:
// Prms:
// Rets:
//
func (i *ANanos) Sub(dlt time.Duration) time.Duration {
return time.Duration(atomic.AddInt64(&i.value, int64(-dlt)))
}
// ANanos.CAS
// Desc:
// Prms:
// Rets:
//
func (i *ANanos) CAS(old, new time.Duration) bool {
return atomic.CompareAndSwapInt64(&i.value, int64(old), int64(new))
}
// ANanos.GetTime
// Desc:
// Prms:
// Rets:
//
func (i *ANanos) GetTime() time.Time { return time.Unix(0, atomic.LoadInt64(&i.value)) }
// ANanos.SetTime
// Desc:
// Prms:
// Rets:
//
func (i *ANanos) SetTime(val time.Time) { atomic.StoreInt64(&i.value, val.UnixNano()) }
// ANanos.GetNanos
// Desc:
// Prms:
// Rets:
//
func (i *ANanos) GetNanos() int64 { return atomic.LoadInt64(&i.value) }
// ANanos.SetNanos
// Desc:
// Prms:
// Rets:
//
func (i *ANanos) SetNanos(val int64) { atomic.StoreInt64(&i.value, val) }
// ANanos.SetNow
// Desc:
// Prms:
// Rets:
//
func (i *ANanos) SetNow() time.Time {
nw := time.Now()
i.SetTime(nw)
return nw
}
/*
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA.
"LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS.
SIDDHARTA
- HERMANN HESSE -
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/

@ -0,0 +1,121 @@
//
// Feb21
//
// GO Active Thing
// Framework
//
// http://activething.com/dev/goat
//
// Dev : Juan V.Navarro
// Email: juanvnl@activething.com
// Date : 16/02/2021
//
// Copyright 2021 the GOAT Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package syncs
import (
"sync/atomic"
)
type (
// AUInt32
// Type: Struct
// Desc:
//
//
AUInt32 struct {
value uint32
}
)
// NewAUInt32
// Desc: Función constructor para AUInt32
//
// Prms: val, valor inicial
// Rets: Puntero al nuevo objeto creado.
//
func NewAUInt32(val uint32) *AUInt32 { return &AUInt32{value: val} }
// AUInt32.Get
// Desc:
// Prms:
// Rets:
//
func (u *AUInt32) Get() uint32 { return atomic.LoadUint32(&u.value) }
// AUInt32.Set
// Desc:
// Prms:
// Rets:
//
func (u *AUInt32) Set(val uint32) { atomic.StoreUint32(&u.value, val) }
// AUInt32.Swap
// Desc:
// Prms:
// Rets:
//
func (u *AUInt32) Swap(new uint32) uint32 { return atomic.SwapUint32(&u.value, new) }
// AUInt32.Add
// Desc:
// Prms:
// Rets:
//
func (u *AUInt32) Add(dlt uint32) uint32 { return atomic.AddUint32(&u.value, dlt) }
// AUInt32.Sub
// Desc:
// Prms:
// Rets:
//
func (u *AUInt32) Sub(dlt uint32) uint32 { return atomic.AddUint32(&u.value, ^uint32(dlt-1)) }
// AUInt32.Inc
// Desc:
// Prms:
// Rets:
//
func (u *AUInt32) Inc() uint32 { return u.Add(1) }
// AUInt32.Dec
// Desc:
// Prms:
// Rets:
//
func (u *AUInt32) Dec() uint32 { return u.Add(^uint32(0)) }
// AUInt32.CAS
// Desc:
// Prms:
// Rets:
//
func (u *AUInt32) CAS(old, new uint32) bool { return atomic.CompareAndSwapUint32(&u.value, old, new) }
/*
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA.
"LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS.
SIDDHARTA
- HERMANN HESSE -
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/

@ -0,0 +1,121 @@
//
// Feb21
//
// GO Active Thing
// Framework
//
// http://activething.com/dev/goat
//
// Dev : Juan V.Navarro
// Email: juanvnl@activething.com
// Date : 16/02/2021
//
// Copyright 2021 the GOAT Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package syncs
import (
"sync/atomic"
)
type (
// AUInt64
// Type: Struct
// Desc:
//
//
AUInt64 struct {
value uint64
}
)
// NewAUInt64
// Desc: Función constructor para AUInt64
//
// Prms: val, valor inicial
// Rets: Puntero al nuevo objeto creado.
//
func NewAUInt64(val uint64) *AUInt64 { return &AUInt64{value: val} }
// AUInt64.Get
// Desc:
// Prms:
// Rets:
//
func (u *AUInt64) Get() uint64 { return atomic.LoadUint64(&u.value) }
// AUInt64.Set
// Desc:
// Prms:
// Rets:
//
func (u *AUInt64) Set(val uint64) { atomic.StoreUint64(&u.value, val) }
// AUInt64.Swap
// Desc:
// Prms:
// Rets:
//
func (u *AUInt64) Swap(new uint64) uint64 { return atomic.SwapUint64(&u.value, new) }
// AUInt64.Add
// Desc:
// Prms:
// Rets:
//
func (u *AUInt64) Add(dlt uint64) uint64 { return atomic.AddUint64(&u.value, dlt) }
// AUInt64.Sub
// Desc:
// Prms:
// Rets:
//
func (u *AUInt64) Sub(dlt uint64) uint64 { return atomic.AddUint64(&u.value, ^uint64(dlt-1)) }
// AUInt64.Inc
// Desc:
// Prms:
// Rets:
//
func (u *AUInt64) Inc() uint64 { return u.Add(1) }
// AUInt64.Dec
// Desc:
// Prms:
// Rets:
//
func (u *AUInt64) Dec() uint64 { return u.Add(^uint64(0)) }
// AUInt64.CAS
// Desc:
// Prms:
// Rets:
//
func (u *AUInt64) CAS(old, new uint64) bool { return atomic.CompareAndSwapUint64(&u.value, old, new) }
/*
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA.
"LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS.
SIDDHARTA
- HERMANN HESSE -
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/

@ -0,0 +1,64 @@
//
// Feb21
//
// GO Active Thing
// Framework
//
// http://activething.com/dev/goat
//
// Dev : Juan V.Navarro
// Email: juanvnl@activething.com
// Date : 16/02/2021
//
// Copyright 2021 the GOAT Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// +build 386 arm mips mipsle
package syncs
import (
"sync/atomic"
)
type AInt struct{ value int32 }
func NewAInt(v int) *AInt { return &AInt{value: int32(v)} }
func (u *AInt) Get() int { return int(atomic.LoadInt32(&u.value)) }
func (u *AInt) Set(v int) { atomic.StoreInt32(&u.value, int32(v)) }
func (u *AInt) Swap(new int) int { return int(atomic.SwapInt32(&u.value, int32(new))) }
func (u *AInt) Add(dlt int) int { return int(atomic.AddInt32(&u.value, int32(dlt))) }
func (u *AInt) Sub(dlt int) int { return int(atomic.AddInt32(&u.value, -dlt)) }
func (u *AInt) Inc() int { return u.Add(1) }
func (u *AInt) Dec() int { return u.Add(-1) }
func (u *AInt) CAS(old, new int) bool {
return atomic.CompareAndSwapInt32(&u.value, int32(old), int32(new))
}
/*
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA.
"LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS.
SIDDHARTA
- HERMANN HESSE -
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/

@ -0,0 +1,64 @@
//
// Feb21
//
// GO Active Thing
// Framework
//
// http://activething.com/dev/goat
//
// Dev : Juan V.Navarro
// Email: juanvnl@activething.com
// Date : 16/02/2021
//
// Copyright 2021 the GOAT Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// +build 386 arm mips mipsle
package syncs
import (
"sync/atomic"
)
type AUInt struct{ value uint32 }
func NewAUint(v uint) *AUInt { return &AUInt{value: uint32(v)} }
func (u *AUInt) Get() uint { return uint(atomic.LoadUint32(&u.value)) }
func (u *AUInt) Set(v uint) { atomic.StoreUint32(&u.value, uint32(v)) }
func (u *AUInt) Swap(new uint) uint { return uint(atomic.SwapUint32(&u.value, uint32(new))) }
func (u *AUInt) Add(dlt uint) uint { return uint(atomic.AddUint32(&u.value, uint32(dlt))) }
func (u *AUInt) Sub(dlt uint) uint { return uint(atomic.AddUint32(&u.value, ^uint32(uint32(dlt)-1))) }
func (u *AUInt) Inc() uint { return u.Add(1) }
func (u *AUInt) Dec() uint { return u.Add(uint(^uint32(0))) }
func (u *AUInt) CAS(old, new uint) bool {
return atomic.CompareAndSwapUint32(&u.value, uint32(old), uint32(new))
}
/*
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA.
"LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS.
SIDDHARTA
- HERMANN HESSE -
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/

@ -0,0 +1,124 @@
//
// Feb21
//
// GO Active Thing
// Framework
//
// http://activething.com/dev/goat
//
// Dev : Juan V.Navarro
// Email: juanvnl@activething.com
// Date : 16/02/2021
//
// Copyright 2021 the GOAT Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// +build amd64 arm64 ppc64 ppc64le mips64 mips64le s390x
package syncs
import (
"sync/atomic"
)
type (
// AInt
// Type: Struct
// Desc:
//
AInt struct {
value int64
}
)
// NewAInt
// Desc: Función constructor para AInt
//
// Prms: val, valor inicial
// Rets: Puntero al nuevo objeto creado.
//
func NewAInt(val int) *AInt { return &AInt{value: int64(val)} }
// AInt.Get
// Desc:
// Prms:
// Rets:
//
func (u *AInt) Get() int { return int(atomic.LoadInt64(&u.value)) }
// AInt.Set
// Desc:
// Prms:
// Rets:
//
func (u *AInt) Set(v int) { atomic.StoreInt64(&u.value, int64(v)) }
// AInt.Swap
// Desc:
// Prms:
// Rets:
//
func (u *AInt) Swap(new int) int { return int(atomic.SwapInt64(&u.value, int64(new))) }
// AInt.Add
// Desc:
// Prms:
// Rets:
//
func (u *AInt) Add(dlt int) int { return int(atomic.AddInt64(&u.value, int64(dlt))) }
// AInt.Sub
// Desc:
// Prms:
// Rets:
//
func (u *AInt) Sub(dlt int) int { return int(atomic.AddInt64(&u.value, int64(-dlt))) }
// AInt.Inc
// Desc:
// Prms:
// Rets:
//
func (u *AInt) Inc() int { return u.Add(1) }
// AInt.Dec
// Desc:
// Prms:
// Rets:
//
func (u *AInt) Dec() int { return u.Add(-1) }
// AInt.CAS
// Desc:
// Prms:
// Rets:
//
func (u *AInt) CAS(old, new int) bool {
return atomic.CompareAndSwapInt64(&u.value, int64(old), int64(new))
}
/*
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA.
"LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS.
SIDDHARTA
- HERMANN HESSE -
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/

@ -0,0 +1,124 @@
//
// Feb21
//
// GO Active Thing
// Framework
//
// http://activething.com/dev/goat
//
// Dev : Juan V.Navarro
// Email: juanvnl@activething.com
// Date : 16/02/2021
//
// Copyright 2021 the GOAT Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// +build amd64 arm64 ppc64 ppc64le mips64 mips64le s390x
package syncs
import (
"sync/atomic"
)
type (
// AUInt
// Type: Struct
// Desc:
//
AUInt struct {
value uint64
}
)
// NewAInt
// Desc: Función constructor para AUInt
//
// Prms: val, valor inicial
// Rets: Puntero al nuevo objeto creado.
//
func NewAUint(val int64) *AUInt { return &AUInt{value: uint64(val)} }
// AUInt.Get
// Desc:
// Prms:
// Rets:
//
func (u *AUInt) Get() uint { return uint(atomic.LoadUint64(&u.value)) }
// AUInt.Set
// Desc:
// Prms:
// Rets:
//
func (u *AUInt) Set(val uint) { atomic.StoreUint64(&u.value, uint64(val)) }
// AUInt.Swap
// Desc:
// Prms:
// Rets:
//
func (u *AUInt) Swap(new uint) uint { return uint(atomic.SwapUint64(&u.value, uint64(new))) }
// AUInt.Add
// Desc:
// Prms:
// Rets:
//
func (u *AUInt) Add(dlt uint) uint { return uint(atomic.AddUint64(&u.value, uint64(dlt))) }
// AUInt.Sub
// Desc:
// Prms:
// Rets:
//
func (u *AUInt) Sub(dlt uint) uint { return uint(atomic.AddUint64(&u.value, ^uint64(dlt-1))) }
// AUInt.Inc
// Desc:
// Prms:
// Rets:
//
func (u *AUInt) Inc() uint { return u.Add(1) }
// AUInt.Dec
// Desc:
// Prms:
// Rets:
//
func (u *AUInt) Dec() uint { return uint(^uint64(0)) }
// AUInt.CAS
// Desc:
// Prms:
// Rets:
//
func (u *AUInt) CAS(old, new uint) bool {
return atomic.CompareAndSwapUint64(&u.value, uint64(old), uint64(new))
}
/*
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA.
"LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS.
SIDDHARTA
- HERMANN HESSE -
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/

@ -26,20 +26,20 @@ package syncs
type (
LockerNop struct{}
NopLocker struct{}
)
func (_ LockerNop) Lock() {}
func (_ NopLocker) Lock() {}
func (_ LockerNop) Unlock() {}
func (_ NopLocker) Unlock() {}
func (_ LockerNop) RLock() {}
func (_ NopLocker) RLock() {}
func (_ LockerNop) RUnlock() {}
func (_ NopLocker) RUnlock() {}

@ -1,69 +0,0 @@
// ------------------------------------------------------------------------
// Project atila
// Active Thing (activething.com) git.activething.com/go
//
// File name pool_ops.go
// Created by DEV
// Modified 17/01/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package syncs
import (
"opts"
"sync/atomic"
)
func PoolWithNew[T any](nfn func() *T) opts.GOptionFnc[Pool[T]] {
return func(p *Pool[T]) {
p.createFn = nfn
}
}
func PoolWithCap[T any](cap int32) opts.GOptionFnc[Pool[T]] {
return func(p *Pool[T]) {
atomic.StoreInt32(&p.cap, cap)
}
}
func PoolWithLen[T any](len int32) opts.GOptionFnc[Pool[T]] {
return func(p *Pool[T]) {
if p.createFn == nil {
return
}
c := p.Cap()
if c != -1 && len > c {
len = c
}
for i := int32(0); i < len; i++ {
p.Put(p.createFn())
}
}
}
func PoolWithSet[T any](els ...*T) opts.GOptionFnc[Pool[T]] {
return func(p *Pool[T]) {
for _, e := range els {
if e != nil {
p.Put(e)
}
}
}
}

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package syncs
package pools
import (
"opts"
@ -31,7 +31,7 @@ import (
type (
Pool[T any] struct {
GPool[T any] struct {
PoolStatsInfo
inner sync.Pool
@ -43,19 +43,19 @@ type (
}
)
func NewPool[T any](ops ...opts.GOptionFnc[Pool[T]]) *Pool[T] {
return opts.GApply(&Pool[T]{}, ops...) }
func NewGPool[T any](ops ...opts.GOptionFnc[GPool[T]]) *GPool[T] {
return opts.GApply(&GPool[T]{}, ops...) }
func (p *Pool[T]) Len() int32 {
func (p *GPool[T]) Len() int32 {
return atomic.LoadInt32(&p.len) }
func (p *Pool[T]) Cap() int32 {
func (p *GPool[T]) Cap() int32 {
return atomic.LoadInt32(&p.cap) }
func (p *Pool[T]) Get() *T {
func (p *GPool[T]) Get() *T {
o := p.inner.Get()
if o != nil {
p.AddAcquired()
@ -71,7 +71,7 @@ func (p *Pool[T]) Get() *T {
}
func (p *Pool[T]) Put(obj *T) {
func (p *GPool[T]) Put(obj *T) {
if obj == nil {
return
}
@ -84,8 +84,51 @@ func (p *Pool[T]) Put(obj *T) {
}
func (p *Pool[T]) Empty() {
func (p *GPool[T]) Empty() {
for p.Len() > 0 {
_ = p.Get()
}
}
func WithNew[T any](nfn func() *T) opts.GOptionFnc[GPool[T]] {
return func(p *GPool[T]) {
p.createFn = nfn
}
}
func WithCap[T any](cap int32) opts.GOptionFnc[GPool[T]] {
return func(p *GPool[T]) {
atomic.StoreInt32(&p.cap, cap)
}
}
func WithLen[T any](len int32) opts.GOptionFnc[GPool[T]] {
return func(p *GPool[T]) {
if p.createFn == nil {
return
}
c := p.Cap()
if c != -1 && len > c {
len = c
}
for i := int32(0); i < len; i++ {
p.Put(p.createFn())
}
}
}
func WithSet[T any](els ...*T) opts.GOptionFnc[GPool[T]] {
return func(p *GPool[T]) {
for _, e := range els {
if e != nil {
p.Put(e)
}
}
}
}

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package syncs
package pools
type (
PoolCallSize struct {

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package syncs
package pools

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package syncs
package pools
import "sync/atomic"

@ -0,0 +1,85 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name g_queue.go
// Created by DEV
// Modified 24/04/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package queue
import (
"sync"
"syncs"
)
type (
GQueue [T any]struct {
locker syncs.LockerRW
elems []T
}
)
func NewGQueue [T any](safe bool) *GQueue[T] {
var lc syncs.LockerRW
if safe {
lc = &sync.RWMutex{}
}
return &GQueue[T]{ locker : lc }
}
func (q *GQueue[T]) Len () (l int) {
q.locker.RLock()
l = len(q.elems)
q.locker.RUnlock()
return
}
func (q *GQueue[T]) Push(ele T) {
q.locker.Lock()
q.elems = append(q.elems,ele)
q.locker.Unlock()
}
func (q *GQueue[T]) Pop() (e T) {
q.locker.Lock()
if q.Len() > 0 {
e = q.elems[0]
q.elems = q.elems[1:]
}
q.locker.Unlock()
return
}
func (q *GQueue[T]) Clear (onClearFnc func(ele T)) {
q.locker.Lock()
if onClearFnc != nil {
for _,e := range q.elems {
onClearFnc(e)
}
}
q.elems = q.elems[:0]
q.locker.Unlock()
}

@ -28,7 +28,7 @@ import (
"runtime"
"sync"
"sync/atomic"
"syncs"
"syncs/pools"
"time"
)
@ -36,7 +36,7 @@ import (
type (
Pool struct {
stats *syncs.PoolStatsInfo
stats *pools.PoolStatsInfo
pool sync.Pool
mux sync.Mutex
@ -62,7 +62,7 @@ func NewPool(options ...PoolFnc) *Pool {
c = 0
}
wp := &Pool{
stats : syncs.NewPoolStatsInfo(),
stats : pools.NewPoolStatsInfo(),
maxIdle: int64(maxIdle),
cap : c,
max : maxWorkers,
@ -82,7 +82,7 @@ func (p *Pool) newWorker () any {
jobCh: make(chan func(), atomic.LoadInt32(&p.cap)) }}
func (p *Pool) Stats () syncs.PoolStats {
func (p *Pool) Stats () pools.PoolStats {
return p.stats }

@ -3,7 +3,7 @@ go 1.22
use (
./core/errs
./core/rsts
./core/results
./core/codecs
./core/crypts
./core/vals
@ -17,8 +17,8 @@ use (
./core/ctxs
./core/atypes
./core/mems
./packs
./logs
./proteus
./hecate
./app
)

@ -23,6 +23,13 @@
package logs
import (
"bins/tokens"
"mems"
"syncs"
"syncs/pools"
"time"
)
const (
@ -34,21 +41,60 @@ const (
LevelNameFatal string = "FATAL"
levelNameSep string = "|"
filterLevelName string = "level"
filterScopeName string = "scope"
)
const (
msgLogLogErr = "Error logging core logger"
msgLogStartErr = "Error starting core logger"
msgLogStopErr = "Error stopping core logger"
msgLogFlushErr = "Error flushing core logger"
)
var (
G = struct {
ErrInvalidLevel ErrLogs
ErrDuplicatedScope ErrLogs
ErrDuplicatedLogger ErrLogs
ErrInvalidScope ErrLogs
ErrInvalidScopeMode ErrLogs
ErrNotExistsLogger ErrLogs
ScopeSep byte
}{
ErrInvalidLevel : ErrLogs{ "invalid-level"},
ErrDuplicatedScope : ErrLogs{"duplicated-scope" },
ErrDuplicatedLogger : ErrLogs{"duplicated-logger"},
ErrInvalidScope : ErrLogs{"invalid-scope"},
ErrInvalidScopeMode : ErrLogs{ "invalid-scope-mode"},
ErrNotExistsLogger : ErrLogs{"not-exists-logger"},
ScopeSep : '.',
}
g = struct {
idGen syncs.AUInt64
entryPool pools.GPool[Entry]
bufferPool mems.Pool
tokenizer tokens.ATokenizer
scopeSepStr string
}{
idGen : *syncs.NewAUInt64(uint64(time.Now().Unix())),
bufferPool: *mems.NewPool(),
tokenizer : *tokens.NewATokenizer(),
entryPool : *pools.NewGPool[Entry](pools.WithNew(newEntry)),
scopeSepStr : ".",
}
)

@ -0,0 +1,53 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name aggregator.go
// Created by DEV
// Modified 25/04/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package logs
type (
Aggregators []EntryFnc
)
func (a Aggregators) Apply (entry *Entry) *Entry{
for _,f := range a {
f(entry)
}
return entry
}
func (a Aggregators) Append (entryFn ... EntryFnc) Aggregators {
return append(a,entryFn...) }

@ -0,0 +1,90 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name hecate.go
// Created by DEV
// Modified 25/04/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package logs
import (
"errs"
"syncs/queue"
)
type (
ALogger struct {
loggerLevel
Aggregators
Filters
scopes Scopes
queue queue.GQueue[*Entry]
state State
count int
logErrors bool
errors errs.ErrorList
}
ManagerFnc func(manager *ALogger)
)
func NewALogger(name string, level Level, options ...ManagerFnc) *ALogger {
m := &ALogger{
loggerLevel : *newLoggerLevel(name,level),
Filters : *NewFilters(),
state : StateCreated,
logErrors : true,
}
m.logFn = m.log
for o := range options {
o(m)
}
return m
}
func (l *ALogger) Start (all bool) error {
l.mux.Lock()
if l.state == StateStarted {
l.mux.Unlock()
return nil
}
l.errors = l.errors[:0]
l.state = StateStarted
if !all {
l.mux.Unlock()
return nil
}
for _,cl := range l.cores {
}
}

@ -0,0 +1,40 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name appender.go
// Created by DEV
// Modified 24/04/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package logs
type (
Appender interface {
Append (entry *Entry) error
}
AppendFnc func (entry *Entry) error
)
func (f AppendFnc) Append (entry *Entry) error {
return f(entry) }

@ -0,0 +1,136 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name entry.go
// Created by DEV
// Modified 23/04/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package logs
import (
"atypes/slices"
"time"
)
type (
Entry struct {
Logger Logger
Id uint64
Scope string
Scopes [][]byte
Level Level
Message string
Date time.Time
Error error
Data any
excludes slices.Strings
}
EntryFnc func (entry *Entry)
)
func AcquireEntry (logger Logger, level Level, message string, err error, options ...EntryFnc) *Entry {
return g.entryPool.Get().init(logger,level,message,err,options...) }
func ReleaseEntry (entry *Entry) {
g.entryPool.Put(entry.reset()) }
func NewEntry (logger Logger, level Level, message string, err error, options ...EntryFnc) *Entry {
return newEntry().init(logger,level,message,err,options...) }
func newEntry () *Entry {
return &Entry{} }
func (e *Entry) init (logger Logger, level Level, message string, err error, options ...EntryFnc) *Entry {
e.Id = g.idGen.Inc()
e.Logger = logger
e.Level = level
e.Error = err
e.Message= message
e.Date = time.Now()
for _,o := range options {
o(e)
}
return e
}
func (e *Entry) reset () *Entry {
if e == nil {
return nil
}
e.Logger = nil
e.excludes = e.excludes.Reset()
for _,s := range e.Scopes {
s = s[:0]
}
e.Scopes = e.Scopes[:0]
e.Error = nil
e.Data = nil
e.Message= ""
return e
}
func (e *Entry) IsExcluded (value string) bool {
return e.excludes.Has(value) }
func (e *Entry) Clone() *Entry {
n := *e
/*
l:=len(e.Fields)
if l > 0 {
n.Fields = make(vals.Fields,len(e.Fields))
for i:=0; i<l; i++ {
n.Fields[i]=e.Fields[i]
}
}
*/
return &n
}
func EntryWithExclude (exclude ... string) EntryFnc {
return func(e *Entry) {
for _, ex := range exclude {
if len(ex) > 0 {
e.excludes = e.excludes.Append(ex)
}
}
}
}

@ -0,0 +1,41 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name entry_logger.go
// Created by DEV
// Modified 24/04/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package logs
type (
EntryLogger interface {
Log (entry *Entry) error
}
LogEntryFnc func(entry *Entry) error
)
func (f LogEntryFnc) Log(entry *Entry) error {
return f(entry) }

@ -0,0 +1,105 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name entry_filter.go
// Created by DEV
// Modified 24/04/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package logs
import (
"bins/tokens"
"strings"
)
type (
Filter struct {
name string
active bool
filterFnc FilterFnc
}
FilterFnc func (entry *Entry) bool
)
func NewFilter(name string, fnc FilterFnc) *Filter {
if fnc == nil {
fnc = NopFilterTrue
}
return &Filter{
name : name,
active : true,
filterFnc : fnc,
}
}
func NewFilterLevel (name string, level Level) *Filter {
if len(name) == 0 {
name = filterLevelName
}
l := level
return &Filter{
name : name,
active : true,
filterFnc: func(e *Entry) bool {
return l.Has(e.Level)
},
}
}
func NewFilterScope (name string, topic string) *Filter {
if len(name) == 0 {
name = filterScopeName
}
tp := *g.tokenizer.NewTopic([]byte(strings.ToLower(topic)),tokens.TokenKindAll)
return &Filter{
name : name,
active : true,
filterFnc: func(e *Entry) bool {
return tp.Match(e.Scopes)
},
}
}
func (f *Filter) Name () string {
return f.name }
func (f *Filter) IsActive () bool {
return f.active }
func (f *Filter) SetActive (enable bool) {
f.active = enable }
func (f *Filter) Filter (entry *Entry) bool {
return f.filterFnc(entry) }
func NopFilterTrue (_ *Entry) bool {
return true }
func NopFilterFalse(_ *Entry) bool {
return false }

@ -0,0 +1,116 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name filters.go
// Created by DEV
// Modified 24/04/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package logs
type (
Filters struct {
allows []*Filter
denies []*Filter
}
FiltersFnc func(f *Filters)
)
func NewFilters (options ...FiltersFnc) *Filters {
f := &Filters {
}
for _,o := range options {
o(f)
}
return f
}
func (f *Filters) AddFilterAllowed(filter *Filter) {
f.add(filter,&f.allows) }
func (f *Filters) AddFilterDenied (filter *Filter) {
f.add(filter,&f.denies) }
func (f *Filters) DelFilterAllowed(name string) {
f.del(name,&f.allows) }
func (f *Filters) DelFilterDenied (name string) {
f.del(name,&f.denies) }
func (f *Filters) Filter (entry *Entry) bool {
if len(f.allows) > 0 {
p := false
for _,fi := range f.allows {
if fi.IsActive() {
if p = fi.Filter(entry); p {
break
}
}
}
if !p {
return false
}
}
for _,fi := range f.denies {
if fi.IsActive() {
if fi.Filter(entry) {
return false
}
}
}
return true
}
func (f *Filters) add (ft *Filter, ls *[]*Filter) {
if p := filterPos(*ls, ft.name); p != -1 {
(*ls)[p]= ft
return
}
*ls = append(*ls, ft)
}
func (f *Filters) del (name string, ls *[]*Filter) {
if p := filterPos(*ls,name); p != -1 {
*ls = append((*ls)[:p],(*ls)[p+1:]...)
}
}
func filterPos (list []*Filter, name string) int {
for i,f := range list {
if f.name == name {
return i
}
}
return -1
}

@ -0,0 +1,3 @@
module hecate
go 1.22

@ -28,11 +28,14 @@ import (
"strings"
)
const(
levelsCount int = 6
)
const(
LevelNone Level = 0
LevelData Level = 1 << iota
LevelDebug
LevelInfo
@ -40,8 +43,11 @@ const(
LevelError
LevelFatal
LevelNone Level = 0
LevelAll Level = LevelData|LevelDebug|LevelInfo|LevelWarn|LevelError|LevelFatal
)
@ -109,7 +115,8 @@ func (lv Level) HasFatal() bool {
return lv&LevelFatal!=0 }
func (lv Level) isValid () bool {
return lv <= LevelAll }

@ -2,9 +2,9 @@
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name entry.go
// File name log.go
// Created by DEV
// Modified 23/04/2024
// Modified 24/04/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
@ -27,15 +27,7 @@ package logs
type (
Entry struct {
Logger Logger
}
EntryFnc func (entry *Entry)
LogFnc func (level Level, message string, err error, options ...EntryFnc)
)

@ -0,0 +1,52 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name logger_core.go
// Created by DEV
// Modified 25/04/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package logs
import "errs"
type (
LoggerCore struct {
loggerLevel
Filters
Aggregators
Appender
state State
count int
errors errs.ErrorList
}
LoggerCoreFnc func(l *LoggerCore)
)
func NewLoggerCore (name string, level Level, options ...LoggerCoreFnc) *LoggerCore {
}

@ -0,0 +1,93 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name logger_level.go
// Created by DEV
// Modified 24/04/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package logs
import "sync"
type (
loggerLevel struct {
mux sync.RWMutex
name string
level Level
logFn LogFnc
}
)
func newLoggerLevel (name string, level Level) *loggerLevel {
return &loggerLevel{
name : name,
level: level } }
func (l *loggerLevel) Name () string {
return l.name }
func (l *loggerLevel) Level() (lv Level) {
l.mux.RLock()
lv = l.level
l.mux.RUnlock()
return
}
func (l *loggerLevel) SetLevel (level Level) {
l.mux.Lock()
l.level = level
l.mux.Unlock()
}
func (l *loggerLevel) Fatal (msg string, err error, ops ...EntryFnc){
l.logFn(LevelFatal,msg,err,ops ...) }
func (l *loggerLevel) Error (msg string, err error, ops ...EntryFnc){
l.logFn(LevelError,msg,err,ops ...) }
func (l *loggerLevel) Warn (msg string, ops ...EntryFnc){
l.logFn(LevelWarn,msg,nil,ops ...) }
func (l *loggerLevel) Info (msg string, ops ...EntryFnc){
l.logFn(LevelInfo,msg,nil,ops...) }
func (l *loggerLevel) Debug (msg string, ops ...EntryFnc){
l.logFn(LevelDebug,msg,nil,ops...) }
func (l *loggerLevel) Data (msg string, data any, ops ...EntryFnc){
l.logFn(LevelData,msg,nil,func (e *Entry) {
e.Data = data
for _,o := range ops {
o(e)
}
}) }

@ -0,0 +1,192 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name scope.go
// Created by DEV
// Modified 24/04/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package logs
import (
"fmt"
"strings"
)
type (
Scope struct {
loggerLevel
Aggregators
path string
nodes [][]byte
mode ScopeMode
parent Loggable
scopes Scopes
}
ScopeFnc func (s *Scope)
)
func newScope(name string, level Level, parent Loggable, path string, nodes [][]byte, options []ScopeFnc) *Scope {
if path != "" {
path = fmt.Sprintf("%s%c%s",path,G.ScopeSep,name)
} else {
path = name
}
sc := &Scope {
loggerLevel: *newLoggerLevel(name,level),
parent: parent,
nodes : append(nodes,[]byte(name)),
path : path,
}
sc.logFn = sc.log
for _,o := range options {
o(sc)
}
return sc
}
func (s *Scope) Nodes() [][]byte {
return s.nodes }
func (s *Scope) Path () string {
return s.path }
func (s *Scope) Mode () (m ScopeMode) {
s.mux.RLock()
m = s.mode
s.mux.RUnlock()
return
}
func (s *Scope) SetMode (mode ScopeMode) {
if !mode.isValid() {
panic(G.ErrInvalidScopeMode)
}
s.mux.Lock()
s.mode = mode
s.mux.Unlock()
}
func (s *Scope) GetScope (name string) *Scope {
return s.getScope(strings.Split(strings.ToLower(name),g.scopeSepStr)) }
func (s *Scope) getScope (nodes []string)( sc *Scope) {
s.mux.RLock()
if sc = s.scopes.getScope(nodes[0]); sc != nil {
if len(nodes) > 1 {
sc = sc.getScope(nodes[:1])
}
}
s.mux.RUnlock()
return
}
func (s *Scope) NewScope (path string, options ...ScopeFnc) (*Scope,error) {
return s.newScope(strings.Split(strings.ToLower(path),g.scopeSepStr),options) }
func (s *Scope) newScope (path []string, options []ScopeFnc) (sc *Scope, er error) {
s.mux.Lock()
if sc = s.scopes.getScope(path[0]); sc == nil {
sc = newScope(path[0], s.level, s, s.path, s.nodes,options)
s.scopes = append(s.scopes, sc)
if len(path) == 1 {
s.mux.Unlock()
return
}
} else if len(path) == 1 {
s.mux.Unlock()
return nil,G.ErrDuplicatedScope
}
sc,er = sc.newScope(path[1:],options)
s.mux.Unlock()
return
}
func (s *Scope) Log(ent *Entry) error {
s.mux.Lock()
if s.mode & ScopeFilter != 0 && !s.level.Has(ent.Level) {
s.mux.Unlock()
return nil
}
if s.mode.IsCascade() {
s.Apply(ent)
}
s.mux.Unlock()
return s.parent.Log(ent)
}
func (s *Scope) log(lvl Level, msg string, err error,ops ...EntryFnc){
s.mux.Lock()
if !s.level.Has(lvl) {
s.mux.Unlock()
return
}
en := s.Apply(AcquireEntry(nil,lvl,msg,err,ops...))
en.Scope = s.path
en.Scopes= s.nodes
s.mux.Unlock()
s.parent.Log(en)
ReleaseEntry(en)
}
func ScopeWithMode (mode ScopeMode) ScopeFnc {
return func(s *Scope) {
if !mode.isValid() {
panic(G.ErrInvalidScopeMode)
}
if mode == ScopeDirect {
s.mode = ScopeDirect
return
}
s.mode |= mode
}
}
func ScopeWithLevel (level Level) ScopeFnc {
return func(s *Scope) {
if !level.isValid() {
panic(G.ErrInvalidLevel)
}
s.level = level
}
}
func ScopeWithAggregator (aggregator ...EntryFnc) ScopeFnc {
return func(s *Scope) {
for _,a := range aggregator {
s.Aggregators = s.Aggregators.Append(a)
}
}
}

@ -0,0 +1,56 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name scope.go
// Created by DEV
// Modified 24/04/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package logs
const (
ScopeCascade ScopeMode = 1 << iota
ScopeFilter
ScopeDirect = 0
)
type (
ScopeMode uint8
)
func (m ScopeMode) isValid () bool {
return m <= ScopeFilter }
func (m ScopeMode) IsDirect() bool {
return m == ScopeDirect }
func (m ScopeMode) IsCascade() bool {
return m & ScopeCascade != 0 }
func (m ScopeMode) IsFilter () bool {
return m & ScopeFilter != 0 }

@ -0,0 +1,63 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name scopes.go
// Created by DEV
// Modified 25/04/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package logs
type (
Scopes []*Scope
)
func (s Scopes) getScope (name string) *Scope {
if ps := s.find(name); ps != -1 {
return s[ps]
}
return nil
}
func (s Scopes) find (name string) int {
for i,e := range s {
if e.name == name {
return i
}
}
return -1
}
func (s Scopes) walk(walkfn func(sc *Scope) bool) bool {
ex := true
for i:=0; i<len(s) && ex; i++ {
e := s[i]
e.mux.Lock()
if ex = walkfn(e); ex {
ex = e.scopes.walk(walkfn)
}
e.mux.Unlock()
}
return ex
}

@ -1,3 +0,0 @@
module logs
go 1.22

@ -1,7 +0,0 @@
module packs
go 1.22

@ -1,80 +0,0 @@
// ------------------------------------------------------------------------
// Project atila
// Active Thing (activething.com) git.activething.com/go
//
// File name builder_list.go
// Created by DEV
// Modified 06/02/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package pjson
import (
"packs"
"time"
)
func (p *JSONPacker) ItemAny (value any, flags packs.Flags) { p.addItem(func(){ p.PackAny(value,flags) }) }
func (p *JSONPacker) ItemRaw (value []byte, flags packs.Flags) { p.addItem(func() { p.PackRaw(value,flags) }) }
func (p *JSONPacker) ItemBinary (value []byte, flags packs.Flags) { p.addItem(func (){ p.PackBinary(value,flags) }) }
func (p *JSONPacker) ItemString (value string, flags packs.Flags) { p.addItem(func (){ p.PackString(value,flags) }) }
func (p *JSONPacker) ItemBool (value bool, flags packs.Flags) { p.addItem(func (){ p.PackBool(value,flags) }) }
func (p *JSONPacker) ItemInt8 (value int8 , flags packs.Flags) { p.addItem(func (){ packInt(p.state,int64(value),flags) }) }
func (p *JSONPacker) ItemInt16 (value int16, flags packs.Flags) { p.addItem(func (){ packInt(p.state,int64(value),flags) }) }
func (p *JSONPacker) ItemInt32 (value int32, flags packs.Flags) { p.addItem(func (){ packInt(p.state,int64(value),flags) }) }
func (p *JSONPacker) ItemInt64 (value int64, flags packs.Flags) { p.addItem(func (){ packInt(p.state,value,flags) }) }
func (p *JSONPacker) ItemUInt8 (value uint8 , flags packs.Flags){ p.addItem(func (){ packUInt(p.state,uint64(value),flags) }) }
func (p *JSONPacker) ItemUInt16 (value uint16, flags packs.Flags){ p.addItem(func (){ packUInt(p.state,uint64(value),flags) }) }
func (p *JSONPacker) ItemUInt32 (value uint32, flags packs.Flags){ p.addItem(func (){ packUInt(p.state,uint64(value),flags) }) }
func (p *JSONPacker) ItemUInt64 (value uint64, flags packs.Flags){ p.addItem(func (){ packUInt(p.state,uint64(value),flags) }) }
func (p *JSONPacker) ItemFloat32 (value float32, flags packs.Flags){ p.addItem(func (){ packFloatString(p.state,float64(value),flags,32)})}
func (p *JSONPacker) ItemFloat64 (value float64, flags packs.Flags){ p.addItem(func (){ packFloatString(p.state,value,flags,64) })}
func (p *JSONPacker) ItemDate (value time.Time, flags packs.Flags) { p.addItem(func(){ packDate(p.state,value,flags); p.state.Inc() })}
func (p *JSONPacker) ItemList (builder func(packs.ListPackBuilder, packs.Flags), flags packs.Flags) {
p.addItem(func(){ p.PackList(builder,flags) }) }
func (p *JSONPacker) ItemMap (builder func(packs.MapPackBuilder, packs.Flags), flags packs.Flags) {
p.addItem(func(){ p.PackMap(builder,flags) }) }
func (p *JSONPacker) ItemObject(builder func(packs.ObjectPackBuilder, packs.Flags), flags packs.Flags) {
p.addItem(func(){ p.PackObject(builder,flags) }) }
func (p *JSONPacker) addItem (caller func()) {
if p.state.Count() > 0 {
p.state.WriteByte(',')
}
caller()
if p.state != nil {
p.state.Inc()
}
}

@ -21,11 +21,11 @@
// limitations under the License.
// ------------------------------------------------------------------------
package packs
package proteus
import (
"errs"
"syncs"
"syncs/pools"
)
const(
@ -69,7 +69,7 @@ var (
g = struct {
poolsSem uint32
statePool *syncs.Pool[State]
statePool *pools.GPool[State]
} {}
)

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package packs
package proteus

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package packs
package proteus
import "errs"

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package packs
package proteus
import (
"bits"

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package packs
package proteus
import (
"bins/chars"

@ -0,0 +1,7 @@
module proteus
go 1.22

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package packs
package proteus
import "time"

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package packs
package proteus
import "time"

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package packs
package proteus
import "time"

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package packs
package proteus
type (

@ -28,7 +28,6 @@ import (
"encoding/json"
"packs"
"reflect"
"rsts"
"sync"
)
@ -39,7 +38,7 @@ const (
maxCyclesAfter = 100
defaultFlags = packs.Flags(0)
defaultFlags = proteus.Flags(0)
)
@ -59,7 +58,7 @@ var (
jsonMarshalerType: reflect.TypeOf((*json.Marshaler)(nil)).Elem(),
textMarshalerType: reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem(),
packMarshalerType: reflect.TypeOf((*packs.Packer)(nil)).Elem(),
packMarshalerType: reflect.TypeOf((*proteus.Packer)(nil)).Elem(),
}
)

@ -38,7 +38,7 @@ type (
JSONPacker struct {
state *packs.State
state *proteus.State
dirty bool
}
@ -49,7 +49,7 @@ type (
func NewJSONPacker(options ...JSONPackerFnc) *JSONPacker {
pk := &JSONPacker{
state : packs.NewState(),
state : proteus.NewState(),
}
for _,o := range options {
o(pk)
@ -59,12 +59,12 @@ func NewJSONPacker(options ...JSONPackerFnc) *JSONPacker {
func (p *JSONPacker) Pack (value any, flags packs.Flags) {
func (p *JSONPacker) Pack (value any, flags proteus.Flags) {
if p.state.Error != nil {
panic(packs.G.ErrInvalidState.WrapWithCause(p.state.Error))
panic(proteus.G.ErrInvalidState.WrapWithCause(p.state.Error))
}
if p.dirty {
panic(packs.G.ErrInvalidState)
panic(proteus.G.ErrInvalidState)
}
p.dirty = true
p.PackAny(value,flags)
@ -86,14 +86,14 @@ func (p *JSONPacker) Reset () {
func (p *JSONPacker) Release () {
p.dirty = false
packs.ReleaseState(p.state)
proteus.ReleaseState(p.state)
}
func (p *JSONPacker) PackAny (value any, flags packs.Flags) {
func (p *JSONPacker) PackAny (value any, flags proteus.Flags) {
if p.state.Error != nil {
panic(packs.G.ErrInvalidState.WrapWithCause(p.state.Error))
panic(proteus.G.ErrInvalidState.WrapWithCause(p.state.Error))
}
if value == nil {
p.state.W(cjson.G.NullValue)
@ -101,7 +101,7 @@ func (p *JSONPacker) PackAny (value any, flags packs.Flags) {
}
switch v := value.(type) {
case packs.Builder:
case proteus.Builder:
p.state.SetError(v.Build(p))
case json.Marshaler:
@ -166,45 +166,45 @@ func (p *JSONPacker) PackAny (value any, flags packs.Flags) {
func (p *JSONPacker) PackRaw (value []byte, flags packs.Flags) { packRaw(p.state,value,flags) }
func (p *JSONPacker) PackRaw (value []byte, flags proteus.Flags) { packRaw(p.state,value,flags) }
func (p *JSONPacker) PackBinary (value []byte, flags packs.Flags) { packBinary(p.state,value,flags) }
func (p *JSONPacker) PackString (value string, flags packs.Flags) { packString (p.state,value,flags) }
func (p *JSONPacker) PackBinary (value []byte, flags proteus.Flags) { packBinary(p.state,value,flags) }
func (p *JSONPacker) PackString (value string, flags proteus.Flags) { packString (p.state,value,flags) }
func (p *JSONPacker) PackBool (value bool, flags packs.Flags) { packBool(p.state,value,flags) }
func (p *JSONPacker) PackBool (value bool, flags proteus.Flags) { packBool(p.state,value,flags) }
func (p *JSONPacker) PackInt8 (value int8 , flags packs.Flags) { packInt(p.state,int64(value),flags) }
func (p *JSONPacker) PackInt16 (value int16, flags packs.Flags) { packInt(p.state,int64(value),flags) }
func (p *JSONPacker) PackInt32 (value int32, flags packs.Flags) { packInt(p.state,int64(value),flags) }
func (p *JSONPacker) PackInt64 (value int64, flags packs.Flags) { packInt(p.state,value,flags)}
func (p *JSONPacker) PackInt8 (value int8 , flags proteus.Flags) { packInt(p.state,int64(value),flags) }
func (p *JSONPacker) PackInt16 (value int16, flags proteus.Flags) { packInt(p.state,int64(value),flags) }
func (p *JSONPacker) PackInt32 (value int32, flags proteus.Flags) { packInt(p.state,int64(value),flags) }
func (p *JSONPacker) PackInt64 (value int64, flags proteus.Flags) { packInt(p.state,value,flags)}
func (p *JSONPacker) PackUInt8 (value uint8 , flags packs.Flags) { packUInt(p.state,uint64(value),flags) }
func (p *JSONPacker) PackUInt16 (value uint16, flags packs.Flags) { packUInt(p.state,uint64(value),flags) }
func (p *JSONPacker) PackUInt32 (value uint32, flags packs.Flags) { packUInt(p.state,uint64(value),flags) }
func (p *JSONPacker) PackUInt64 (value uint64, flags packs.Flags) { packUInt(p.state, value,flags) }
func (p *JSONPacker) PackUInt8 (value uint8 , flags proteus.Flags) { packUInt(p.state,uint64(value),flags) }
func (p *JSONPacker) PackUInt16 (value uint16, flags proteus.Flags) { packUInt(p.state,uint64(value),flags) }
func (p *JSONPacker) PackUInt32 (value uint32, flags proteus.Flags) { packUInt(p.state,uint64(value),flags) }
func (p *JSONPacker) PackUInt64 (value uint64, flags proteus.Flags) { packUInt(p.state, value,flags) }
func (p *JSONPacker) PackFloat32 (value float32, flags packs.Flags) { packFloatString(p.state, float64(value), flags, 32) }
func (p *JSONPacker) PackFloat64 (value float64, flags packs.Flags) { packFloatString(p.state, value, flags, 64) }
func (p *JSONPacker) PackFloat32 (value float32, flags proteus.Flags) { packFloatString(p.state, float64(value), flags, 32) }
func (p *JSONPacker) PackFloat64 (value float64, flags proteus.Flags) { packFloatString(p.state, value, flags, 64) }
func (p *JSONPacker) PackDate (value time.Time, flags packs.Flags) { packDate(p.state,value,flags) }
func (p *JSONPacker) PackDate (value time.Time, flags proteus.Flags) { packDate(p.state,value,flags) }
func (p *JSONPacker) PackList (builder func(packs.ListPackBuilder, packs.Flags), flags packs.Flags) {
p.packCompound('[',']',builder==nil,func(pk *JSONPacker, fl packs.Flags){ builder(pk,fl) },flags)
func (p *JSONPacker) PackList (builder func(proteus.ListPackBuilder, proteus.Flags), flags proteus.Flags) {
p.packCompound('[',']',builder==nil,func(pk *JSONPacker, fl proteus.Flags){ builder(pk,fl) },flags)
}
func (p *JSONPacker) PackMap (builder func(packs.MapPackBuilder, packs.Flags), flags packs.Flags) {
p.packCompound('{','}',builder==nil,func(pk *JSONPacker, fl packs.Flags){ builder(pk,fl) },flags)
func (p *JSONPacker) PackMap (builder func(proteus.MapPackBuilder, proteus.Flags), flags proteus.Flags) {
p.packCompound('{','}',builder==nil,func(pk *JSONPacker, fl proteus.Flags){ builder(pk,fl) },flags)
}
func (p *JSONPacker) PackObject(builder func(packs.ObjectPackBuilder, packs.Flags), flags packs.Flags) {
p.packCompound('{','}',builder==nil,func(pk *JSONPacker, fl packs.Flags){ builder(pk,fl) },flags)
func (p *JSONPacker) PackObject(builder func(proteus.ObjectPackBuilder, proteus.Flags), flags proteus.Flags) {
p.packCompound('{','}',builder==nil,func(pk *JSONPacker, fl proteus.Flags){ builder(pk,fl) },flags)
}
func (p *JSONPacker) packCompound (opener, closer byte, isnil bool, buildFn func(*JSONPacker, packs.Flags), flags packs.Flags) {
func (p *JSONPacker) packCompound (opener, closer byte, isnil bool, buildFn func(*JSONPacker, proteus.Flags), flags proteus.Flags) {
if p.state.Error != nil {
panic(packs.G.ErrInvalidState.WrapWithCause(p.state.Error))
panic(proteus.G.ErrInvalidState.WrapWithCause(p.state.Error))
}
if isnil {
p.state.W(cjson.G.NullValue)
@ -229,9 +229,9 @@ func (p *JSONPacker) packCompound (opener, closer byte, isnil bool, buildFn func
func packRaw (state *packs.State, value []byte, flags packs.Flags) {
func packRaw (state *proteus.State, value []byte, flags proteus.Flags) {
if state.Error != nil {
panic(packs.G.ErrInvalidState.WrapWithCause(state.Error))
panic(proteus.G.ErrInvalidState.WrapWithCause(state.Error))
}
if value == nil {
state.W(cjson.G.NullValue)
@ -244,9 +244,9 @@ func packRaw (state *packs.State, value []byte, flags packs.Flags) {
state.WOQ(flags.Quote(),'"',value)
}
func packString (state *packs.State, value string , flags packs.Flags) {
func packString (state *proteus.State, value string , flags proteus.Flags) {
if state.Error != nil {
panic(packs.G.ErrInvalidState.WrapWithCause(state.Error))
panic(proteus.G.ErrInvalidState.WrapWithCause(state.Error))
}
if len(value) == 0 {
@ -255,7 +255,7 @@ func packString (state *packs.State, value string , flags packs.Flags) {
}
if flags.Encrypted() {
packEncrypted(state, []byte(value), flags|packs.FlagBinary64)
packEncrypted(state, []byte(value), flags|proteus.FlagBinary64)
return
}
@ -268,7 +268,7 @@ func packString (state *packs.State, value string , flags packs.Flags) {
}
func packEncrypted (state *packs.State, value []byte, flags packs.Flags) {
func packEncrypted (state *proteus.State, value []byte, flags proteus.Flags) {
r := state.Encrypter.Encrypt(value)
if !r.Ok() {
state.SetError(r.Fail())
@ -276,16 +276,16 @@ func packEncrypted (state *packs.State, value []byte, flags packs.Flags) {
}
if !flags.Binary() {
flags|= packs.FlagBinary64
flags|= proteus.FlagBinary64
}
packBinary(state,value,flags)
}
func packBinary (state *packs.State, value []byte , flags packs.Flags) {
func packBinary (state *proteus.State, value []byte , flags proteus.Flags) {
if state.Error != nil {
panic(packs.G.ErrInvalidState.WrapWithCause(state.Error))
panic(proteus.G.ErrInvalidState.WrapWithCause(state.Error))
}
if flags.Bin64() {
@ -296,48 +296,48 @@ func packBinary (state *packs.State, value []byte , flags packs.Flags) {
state.SetError(cjson.WriteBase32(state.ABuffer,value))
return
}
state.SetError(packs.G.ErrUnsupportedType)
state.SetError(proteus.G.ErrUnsupportedType)
}
func packBool (state *packs.State, value bool , flags packs.Flags) {
func packBool (state *proteus.State, value bool , flags proteus.Flags) {
if state.Error != nil {
panic(packs.G.ErrInvalidState.WrapWithCause(state.Error))
panic(proteus.G.ErrInvalidState.WrapWithCause(state.Error))
}
cjson.WriteBool(state.ABuffer,value,flags.Quote())
}
func packInt (state *packs.State, value int64 , flags packs.Flags) {
func packInt (state *proteus.State, value int64 , flags proteus.Flags) {
if state.Error != nil {
panic(packs.G.ErrInvalidState.WrapWithCause(state.Error))
panic(proteus.G.ErrInvalidState.WrapWithCause(state.Error))
}
cjson.WriteInt(state.ABuffer,value,flags.Quote())
}
func packUInt (state *packs.State, value uint64 , flags packs.Flags) {
func packUInt (state *proteus.State, value uint64 , flags proteus.Flags) {
if state.Error != nil {
panic(packs.G.ErrInvalidState.WrapWithCause(state.Error))
panic(proteus.G.ErrInvalidState.WrapWithCause(state.Error))
}
cjson.WriteUint(state.ABuffer,value,flags.Quote())
}
func packFloat (state *packs.State, value float64, flags packs.Flags) {
func packFloat (state *proteus.State, value float64, flags proteus.Flags) {
packFloatString(state, value, flags, 64) }
func packFloatString (state *packs.State, f float64, flags packs.Flags, bits int) {
func packFloatString (state *proteus.State, f float64, flags proteus.Flags, bits int) {
if state.Error != nil {
panic(packs.G.ErrInvalidState.WrapWithCause(state.Error))
panic(proteus.G.ErrInvalidState.WrapWithCause(state.Error))
}
cjson.WriteFloat(state.ABuffer,f,bits,flags.Quote())
}
func packDate(state *packs.State, value time.Time, flags packs.Flags) {
func packDate(state *proteus.State, value time.Time, flags proteus.Flags) {
if state.Error != nil {
panic(packs.G.ErrInvalidState.WrapWithCause(state.Error))
panic(proteus.G.ErrInvalidState.WrapWithCause(state.Error))
}
cjson.WriteDate(state.ABuffer,value,flags.DateFormat(),true)
}
@ -347,7 +347,7 @@ func packDate(state *packs.State, value time.Time, flags packs.Flags) {
func packListString (state *packs.State, list []string, flags packs.Flags) {
func packListString (state *proteus.State, list []string, flags proteus.Flags) {
if !checkList(state,list == nil, len(list) ==0) {
return
}
@ -365,7 +365,7 @@ func packListString (state *packs.State, list []string, flags packs.Flags) {
}
func packListBool (state *packs.State, list []bool, flags packs.Flags) {
func packListBool (state *proteus.State, list []bool, flags proteus.Flags) {
if !checkList(state,list == nil, len(list) ==0) {
return
}
@ -383,7 +383,7 @@ func packListBool (state *packs.State, list []bool, flags packs.Flags) {
}
func packListInt [T int | int8 | int16 | int32 | int64](state *packs.State, list []T, flags packs.Flags) {
func packListInt [T int | int8 | int16 | int32 | int64](state *proteus.State, list []T, flags proteus.Flags) {
if !checkList(state,list == nil, len(list) ==0) {
return
}
@ -401,7 +401,7 @@ func packListInt [T int | int8 | int16 | int32 | int64](state *packs.State, lis
}
func packListUInt [T uint | uint8 | uint16 | uint32 | uint64](state *packs.State, list []T, flags packs.Flags) {
func packListUInt [T uint | uint8 | uint16 | uint32 | uint64](state *proteus.State, list []T, flags proteus.Flags) {
if !checkList(state,list == nil, len(list) ==0) {
return
}
@ -419,7 +419,7 @@ func packListUInt [T uint | uint8 | uint16 | uint32 | uint64](state *packs.State
}
func packListFloat[T float32 | float64](state *packs.State, list []T, flags packs.Flags, bits int) {
func packListFloat[T float32 | float64](state *proteus.State, list []T, flags proteus.Flags, bits int) {
if !checkList(state,list == nil, len(list) ==0) {
return
}
@ -436,7 +436,7 @@ func packListFloat[T float32 | float64](state *packs.State, list []T, flags pack
state.WriteByte(']')
}
func packListDate (state *packs.State, list []time.Time, flags packs.Flags) {
func packListDate (state *proteus.State, list []time.Time, flags proteus.Flags) {
if !checkList(state,list == nil, len(list) ==0) {
return
}
@ -454,7 +454,7 @@ func packListDate (state *packs.State, list []time.Time, flags packs.Flags) {
}
func checkList (state *packs.State, isNull, isEmpty bool) bool {
func checkList (state *proteus.State, isNull, isEmpty bool) bool {
if isNull {
state.Write2Byte('"','"')
return false

@ -0,0 +1,80 @@
// ------------------------------------------------------------------------
// Project atila
// Active Thing (activething.com) git.activething.com/go
//
// File name builder_list.go
// Created by DEV
// Modified 06/02/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package pjson
import (
"packs"
"time"
)
func (p *JSONPacker) ItemAny (value any, flags proteus.Flags) { p.addItem(func(){ p.PackAny(value,flags) }) }
func (p *JSONPacker) ItemRaw (value []byte, flags proteus.Flags) { p.addItem(func() { p.PackRaw(value,flags) }) }
func (p *JSONPacker) ItemBinary (value []byte, flags proteus.Flags) { p.addItem(func (){ p.PackBinary(value,flags) }) }
func (p *JSONPacker) ItemString (value string, flags proteus.Flags) { p.addItem(func (){ p.PackString(value,flags) }) }
func (p *JSONPacker) ItemBool (value bool, flags proteus.Flags) { p.addItem(func (){ p.PackBool(value,flags) }) }
func (p *JSONPacker) ItemInt8 (value int8 , flags proteus.Flags) { p.addItem(func (){ packInt(p.state,int64(value),flags) }) }
func (p *JSONPacker) ItemInt16 (value int16, flags proteus.Flags) { p.addItem(func (){ packInt(p.state,int64(value),flags) }) }
func (p *JSONPacker) ItemInt32 (value int32, flags proteus.Flags) { p.addItem(func (){ packInt(p.state,int64(value),flags) }) }
func (p *JSONPacker) ItemInt64 (value int64, flags proteus.Flags) { p.addItem(func (){ packInt(p.state,value,flags) }) }
func (p *JSONPacker) ItemUInt8 (value uint8 , flags proteus.Flags){ p.addItem(func (){ packUInt(p.state,uint64(value),flags) }) }
func (p *JSONPacker) ItemUInt16 (value uint16, flags proteus.Flags){ p.addItem(func (){ packUInt(p.state,uint64(value),flags) }) }
func (p *JSONPacker) ItemUInt32 (value uint32, flags proteus.Flags){ p.addItem(func (){ packUInt(p.state,uint64(value),flags) }) }
func (p *JSONPacker) ItemUInt64 (value uint64, flags proteus.Flags){ p.addItem(func (){ packUInt(p.state,uint64(value),flags) }) }
func (p *JSONPacker) ItemFloat32 (value float32, flags proteus.Flags){ p.addItem(func (){ packFloatString(p.state,float64(value),flags,32)})}
func (p *JSONPacker) ItemFloat64 (value float64, flags proteus.Flags){ p.addItem(func (){ packFloatString(p.state,value,flags,64) })}
func (p *JSONPacker) ItemDate (value time.Time, flags proteus.Flags) { p.addItem(func(){ packDate(p.state,value,flags); p.state.Inc() })}
func (p *JSONPacker) ItemList (builder func(proteus.ListPackBuilder, proteus.Flags), flags proteus.Flags) {
p.addItem(func(){ p.PackList(builder,flags) }) }
func (p *JSONPacker) ItemMap (builder func(proteus.MapPackBuilder, proteus.Flags), flags proteus.Flags) {
p.addItem(func(){ p.PackMap(builder,flags) }) }
func (p *JSONPacker) ItemObject(builder func(proteus.ObjectPackBuilder, proteus.Flags), flags proteus.Flags) {
p.addItem(func(){ p.PackObject(builder,flags) }) }
func (p *JSONPacker) addItem (caller func()) {
if p.state.Count() > 0 {
p.state.WriteByte(',')
}
caller()
if p.state != nil {
p.state.Inc()
}
}

@ -29,51 +29,51 @@ import (
"time"
)
func (p *JSONPacker) KeyValueAny (key any, value any, flags packs.Flags) {
func (p *JSONPacker) KeyValueAny (key any, value any, flags proteus.Flags) {
p.addKeyValue(key, func(){ p.PackAny(value,flags)}) }
func (p *JSONPacker) KeyValueRaw (key any,value []byte, flags packs.Flags) {
func (p *JSONPacker) KeyValueRaw (key any,value []byte, flags proteus.Flags) {
p.addKeyValue(key, func(){ p.PackRaw(value,flags)}) }
func (p *JSONPacker) KeyValueBinary (key any, value []byte, flags packs.Flags) {
func (p *JSONPacker) KeyValueBinary (key any, value []byte, flags proteus.Flags) {
p.addKeyValue(key, func(){ p.PackBinary(value,flags)}) }
func (p *JSONPacker) KeyValueString (key any, value string, flags packs.Flags) {
func (p *JSONPacker) KeyValueString (key any, value string, flags proteus.Flags) {
p.addKeyValue(key, func(){ p.PackString(value,flags)}) }
func (p *JSONPacker) KeyValueBool (key any, value bool, flags packs.Flags) {
func (p *JSONPacker) KeyValueBool (key any, value bool, flags proteus.Flags) {
p.addKeyValue(key, func(){ p.PackBool(value,flags)}) }
func (p *JSONPacker) KeyValueInt8 (key any, value int8 , flags packs.Flags) { p.addKeyValue(key, func(){ p.PackInt64(int64(value),flags)}) }
func (p *JSONPacker) KeyValueInt16 (key any, value int16, flags packs.Flags) { p.addKeyValue(key, func(){ p.PackInt64(int64(value),flags)}) }
func (p *JSONPacker) KeyValueInt32 (key any, value int32, flags packs.Flags) { p.addKeyValue(key, func(){ p.PackInt64(int64(value),flags)}) }
func (p *JSONPacker) KeyValueInt64 (key any, value int64, flags packs.Flags) { p.addKeyValue(key, func(){ p.PackInt64(value,flags)}) }
func (p *JSONPacker) KeyValueInt8 (key any, value int8 , flags proteus.Flags) { p.addKeyValue(key, func(){ p.PackInt64(int64(value),flags)}) }
func (p *JSONPacker) KeyValueInt16 (key any, value int16, flags proteus.Flags) { p.addKeyValue(key, func(){ p.PackInt64(int64(value),flags)}) }
func (p *JSONPacker) KeyValueInt32 (key any, value int32, flags proteus.Flags) { p.addKeyValue(key, func(){ p.PackInt64(int64(value),flags)}) }
func (p *JSONPacker) KeyValueInt64 (key any, value int64, flags proteus.Flags) { p.addKeyValue(key, func(){ p.PackInt64(value,flags)}) }
func (p *JSONPacker) KeyValueUInt8 (key any, value uint8 , flags packs.Flags) { p.addKeyValue(key, func(){ p.PackUInt64(uint64(value),flags)}) }
func (p *JSONPacker) KeyValueUInt16 (key any, value uint16, flags packs.Flags) { p.addKeyValue(key, func(){ p.PackUInt64(uint64(value),flags)}) }
func (p *JSONPacker) KeyValueUInt32 (key any, value uint32, flags packs.Flags) { p.addKeyValue(key, func(){ p.PackUInt64(uint64(value),flags)}) }
func (p *JSONPacker) KeyValueUInt64 (key any, value uint64, flags packs.Flags) { p.addKeyValue(key, func(){ p.PackUInt64(value,flags)}) }
func (p *JSONPacker) KeyValueUInt8 (key any, value uint8 , flags proteus.Flags) { p.addKeyValue(key, func(){ p.PackUInt64(uint64(value),flags)}) }
func (p *JSONPacker) KeyValueUInt16 (key any, value uint16, flags proteus.Flags) { p.addKeyValue(key, func(){ p.PackUInt64(uint64(value),flags)}) }
func (p *JSONPacker) KeyValueUInt32 (key any, value uint32, flags proteus.Flags) { p.addKeyValue(key, func(){ p.PackUInt64(uint64(value),flags)}) }
func (p *JSONPacker) KeyValueUInt64 (key any, value uint64, flags proteus.Flags) { p.addKeyValue(key, func(){ p.PackUInt64(value,flags)}) }
func (p *JSONPacker) KeyValueFloat32(key any, value float32, flags packs.Flags){
func (p *JSONPacker) KeyValueFloat32(key any, value float32, flags proteus.Flags){
p.addKeyValue(key,func(){ p.PackFloat32(value, flags) }) }
func (p *JSONPacker) KeyValueFloat64(key any, value float64, flags packs.Flags){
func (p *JSONPacker) KeyValueFloat64(key any, value float64, flags proteus.Flags){
p.addKeyValue(key,func(){ p.PackFloat64(value, flags) }) }
func (p *JSONPacker) KeyValueDate (key any, value time.Time, flags packs.Flags){
func (p *JSONPacker) KeyValueDate (key any, value time.Time, flags proteus.Flags){
p.addKeyValue(key,func(){ p.PackDate(value, flags) }) }
func (p *JSONPacker) KeyValueList (key any, builder func(packs.ListPackBuilder, packs.Flags), flags packs.Flags) {
func (p *JSONPacker) KeyValueList (key any, builder func(proteus.ListPackBuilder, proteus.Flags), flags proteus.Flags) {
p.addKeyValue(key,func(){ p.PackList(builder, flags) }) }
func (p *JSONPacker) KeyValueMap (key any, builder func(packs.MapPackBuilder, packs.Flags), flags packs.Flags) {
func (p *JSONPacker) KeyValueMap (key any, builder func(proteus.MapPackBuilder, proteus.Flags), flags proteus.Flags) {
p.addKeyValue(key,func(){ p.PackMap(builder, flags) }) }
func (p *JSONPacker) KeyValueObject (key any, builder func(packs.ObjectPackBuilder, packs.Flags), flags packs.Flags) {
func (p *JSONPacker) KeyValueObject (key any, builder func(proteus.ObjectPackBuilder, proteus.Flags), flags proteus.Flags) {
p.addKeyValue(key,func(){ p.PackObject(builder, flags) }) }
@ -94,16 +94,16 @@ func (p *JSONPacker) addKeyValue(key any, caller func()) {
func (p *JSONPacker) packStringifyKey(key any) {
switch v := key.(type) {
case string : p.PackString(v, packs.FlagScapeHTML)
case float32: p.PackFloat32(v, packs.FlagScapeHTML|packs.FlagQuote)
case float64: p.PackFloat64(v, packs.FlagScapeHTML|packs.FlagQuote)
case string : p.PackString(v, proteus.FlagScapeHTML)
case float32: p.PackFloat32(v, proteus.FlagScapeHTML|proteus.FlagQuote)
case float64: p.PackFloat64(v, proteus.FlagScapeHTML|proteus.FlagQuote)
default:
me := &rMapEntry{
v : reflect.ValueOf(key),
}
fn := stringifyRKey(me.v.Type())
if fn == nil {
p.state.SetError(packs.G.ErrInvalidKey)
p.state.SetError(proteus.G.ErrInvalidKey)
return
}
if er := fn(me,me.v); er != nil {

@ -28,71 +28,71 @@ import (
"time"
)
func (p *JSONPacker) FieldAny (name string, value any, flags packs.Flags) {
func (p *JSONPacker) FieldAny (name string, value any, flags proteus.Flags) {
p.addField(name, func() { p.PackAny(value, flags) }) }
func (p *JSONPacker) FieldRaw (name string, value []byte, flags packs.Flags){
func (p *JSONPacker) FieldRaw (name string, value []byte, flags proteus.Flags){
p.addField(name, func() { p.PackRaw(value, flags) }) }
func (p *JSONPacker) FieldBinary (name string, value []byte, flags packs.Flags) {
func (p *JSONPacker) FieldBinary (name string, value []byte, flags proteus.Flags) {
p.addField(name, func() { p.PackBinary(value, flags) }) }
func (p *JSONPacker) FieldString (name string, value string, flags packs.Flags) {
func (p *JSONPacker) FieldString (name string, value string, flags proteus.Flags) {
p.addField(name, func() { p.PackString(value, flags) })
}
func (p *JSONPacker) FieldBool (name string, value bool, flags packs.Flags) {
func (p *JSONPacker) FieldBool (name string, value bool, flags proteus.Flags) {
p.addField(name, func() { p.PackBool(value, flags) })
}
func (p *JSONPacker) FieldInt8 (name string, value int8 , flags packs.Flags) {
func (p *JSONPacker) FieldInt8 (name string, value int8 , flags proteus.Flags) {
p.addField(name, func() { p.PackInt64(int64(value), flags) })}
func (p *JSONPacker) FieldInt16 (name string, value int16, flags packs.Flags) {
func (p *JSONPacker) FieldInt16 (name string, value int16, flags proteus.Flags) {
p.addField(name, func() { p.PackInt64(int64(value), flags) })}
func (p *JSONPacker) FieldInt32 (name string, value int32, flags packs.Flags) {
func (p *JSONPacker) FieldInt32 (name string, value int32, flags proteus.Flags) {
p.addField(name, func() { p.PackInt64(int64(value), flags) }) }
func (p *JSONPacker) FieldInt64 (name string, value int64, flags packs.Flags) {
func (p *JSONPacker) FieldInt64 (name string, value int64, flags proteus.Flags) {
p.addField(name, func() { p.PackInt64(value, flags) }) }
func (p *JSONPacker) FieldUInt8 (name string, value uint8, flags packs.Flags) {
func (p *JSONPacker) FieldUInt8 (name string, value uint8, flags proteus.Flags) {
p.addField(name, func() { p.PackUInt64(uint64(value), flags) }) }
func (p *JSONPacker) FieldUInt16 (name string, value uint16, flags packs.Flags) {
func (p *JSONPacker) FieldUInt16 (name string, value uint16, flags proteus.Flags) {
p.addField(name,func(){ p.PackUInt64(uint64(value), flags) }) }
func (p *JSONPacker) FieldUInt32 (name string, value uint32, flags packs.Flags) {
func (p *JSONPacker) FieldUInt32 (name string, value uint32, flags proteus.Flags) {
p.addField(name,func(){ p.PackUInt64(uint64(value), flags) }) }
func (p *JSONPacker) FieldUInt64 (name string, value uint64, flags packs.Flags) {
func (p *JSONPacker) FieldUInt64 (name string, value uint64, flags proteus.Flags) {
p.addField(name,func(){ p.PackUInt64(value, flags) }) }
func (p *JSONPacker) FieldFloat32(name string, value float32,flags packs.Flags) {
func (p *JSONPacker) FieldFloat32(name string, value float32,flags proteus.Flags) {
p.addField(name,func(){ p.PackFloat32(value, flags) })
}
func (p *JSONPacker) FieldFloat64(name string, value float64,flags packs.Flags) {
func (p *JSONPacker) FieldFloat64(name string, value float64,flags proteus.Flags) {
p.addField(name,func(){ p.PackFloat64(value, flags) })
}
func (p *JSONPacker) FieldDate (name string, value time.Time,flags packs.Flags) {
func (p *JSONPacker) FieldDate (name string, value time.Time,flags proteus.Flags) {
p.addField(name,func(){ p.PackDate(value, flags) })
}
func (p *JSONPacker) FieldList (name string, builder func(packs.ListPackBuilder, packs.Flags), flags packs.Flags) {
func (p *JSONPacker) FieldList (name string, builder func(proteus.ListPackBuilder, proteus.Flags), flags proteus.Flags) {
p.addField(name,func(){ p.PackList(builder, flags) })
}
func (p *JSONPacker) FieldMap (name string, builder func(packs.MapPackBuilder, packs.Flags), flags packs.Flags) {
func (p *JSONPacker) FieldMap (name string, builder func(proteus.MapPackBuilder, proteus.Flags), flags proteus.Flags) {
p.addField(name,func(){ p.PackMap(builder, flags) })
}
func (p *JSONPacker) FieldObject (name string, builder func(packs.ObjectPackBuilder, packs.Flags), flags packs.Flags) {
func (p *JSONPacker) FieldObject (name string, builder func(proteus.ObjectPackBuilder, proteus.Flags), flags proteus.Flags) {
p.addField(name,func(){ p.PackObject(builder, flags) })
}
@ -102,7 +102,7 @@ func (p *JSONPacker) addField(name string, caller func()) {
if p.state.Count() > 0 {
p.state.WriteByte(',')
}
packString(p.state,name, packs.FlagScapeHTML)
packString(p.state,name, proteus.FlagScapeHTML)
if p.state.Error != nil {
return
}

@ -33,7 +33,7 @@ type (
rPackerFnc func (state *packs.State, rvalue reflect.Value, flags packs.Flags)
rPackerFnc func (state *proteus.State, rvalue reflect.Value, flags proteus.Flags)
)
@ -49,7 +49,7 @@ func rTypePacker (rtype reflect.Type) rPackerFnc {
wg.Add(1)
fi,ld := g.packersCache.LoadOrStore(rtype, rPackerFnc(func (e *packs.State, v reflect.Value, f packs.Flags) {
fi,ld := g.packersCache.LoadOrStore(rtype, rPackerFnc(func (e *proteus.State, v reflect.Value, f proteus.Flags) {
wg.Wait()
fn(e,v,f)
}))
@ -68,20 +68,20 @@ func rTypePacker (rtype reflect.Type) rPackerFnc {
func _rTypePacker(rtype reflect.Type) rPackerFnc {
switch rtype.Kind() {
case reflect.Bool : return func(s *packs.State, v reflect.Value, f packs.Flags) { packBool (s,v.Bool (),f )}
case reflect.String : return func(s *packs.State, v reflect.Value, f packs.Flags) { packString(s,v.String(),f )}
case reflect.Bool : return func(s *proteus.State, v reflect.Value, f proteus.Flags) { packBool (s,v.Bool (),f )}
case reflect.String : return func(s *proteus.State, v reflect.Value, f proteus.Flags) { packString(s,v.String(),f )}
case reflect.Int,
reflect.Int8,
reflect.Int16,
reflect.Int32,
reflect.Int64 : return func(s *packs.State, v reflect.Value, f packs.Flags) { packInt (s,v.Int (),f )}
reflect.Int64 : return func(s *proteus.State, v reflect.Value, f proteus.Flags) { packInt (s,v.Int (),f )}
case reflect.Uint,
reflect.Uint8,
reflect.Uint16,
reflect.Uint32,
reflect.Uint64 : return func(s *packs.State, v reflect.Value, f packs.Flags) { packUInt (s,v.Uint (),f )}
case reflect.Float32: return func(s *packs.State, v reflect.Value, f packs.Flags) { packFloatString(s,v.Float(),f,32) }
case reflect.Float64: return func(s *packs.State, v reflect.Value, f packs.Flags) { packFloatString(s,v.Float(),f,64) }
reflect.Uint64 : return func(s *proteus.State, v reflect.Value, f proteus.Flags) { packUInt (s,v.Uint (),f )}
case reflect.Float32: return func(s *proteus.State, v reflect.Value, f proteus.Flags) { packFloatString(s,v.Float(),f,32) }
case reflect.Float64: return func(s *proteus.State, v reflect.Value, f proteus.Flags) { packFloatString(s,v.Float(),f,64) }
case reflect.Pointer:
return rPointerPacker(rtype)
@ -106,8 +106,8 @@ func _rTypePacker(rtype reflect.Type) rPackerFnc {
}
func unsupportedTypePacker(state *packs.State, _ reflect.Value, _ packs.Flags) {
state.SetError(packs.G.ErrUnsupportedType)
func unsupportedTypePacker(state *proteus.State, _ reflect.Value, _ proteus.Flags) {
state.SetError(proteus.G.ErrUnsupportedType)
}

@ -29,7 +29,7 @@ import (
"reflect"
)
func rInterfacePacker (s *packs.State, v reflect.Value, f packs.Flags) {
func rInterfacePacker (s *proteus.State, v reflect.Value, f proteus.Flags) {
if v.IsNil() {
s.W(cjson.G.NullValue)
return

@ -45,7 +45,7 @@ func _stringifyRKey(rt reflect.Type) rMapEntryFnc {
if rt.Kind() == reflect.String {
return func(e *rMapEntry, k reflect.Value) error {
e.k = k.String()
e.f = packs.FlagScapeHTML
e.f = proteus.FlagScapeHTML
return nil
}
}
@ -58,7 +58,7 @@ func _stringifyRKey(rt reflect.Type) rMapEntryFnc {
bf, er := (k.Interface().(encoding.TextMarshaler)).MarshalText()
if er == nil {
e.k = string(bf)
e.f = packs.FlagScapeHTML
e.f = proteus.FlagScapeHTML
}
return er
}
@ -92,7 +92,7 @@ func _stringifyRKey(rt reflect.Type) rMapEntryFnc {
if k.Type().Kind() == reflect.String {
e.k = k.String()
e.f = packs.FlagScapeHTML
e.f = proteus.FlagScapeHTML
return nil
}
@ -103,7 +103,7 @@ func _stringifyRKey(rt reflect.Type) rMapEntryFnc {
bf, er := t.MarshalText()
if er == nil {
e.k = string(bf)
e.f = packs.FlagScapeHTML
e.f = proteus.FlagScapeHTML
}
return er
}
@ -128,7 +128,7 @@ func _stringifyRKey(rt reflect.Type) rMapEntryFnc {
return nil
default:
return packs.G.ErrInvalidKey
return proteus.G.ErrInvalidKey
}
}

@ -58,7 +58,7 @@ func newRList(rtype reflect.Type) *rList {
func (p rList) packBinary (s *packs.State, v reflect.Value, f packs.Flags) {
func (p rList) packBinary (s *proteus.State, v reflect.Value, f proteus.Flags) {
if f.Binary() {
packBinary(s, v.Interface().([]byte), f)
return
@ -67,7 +67,7 @@ func (p rList) packBinary (s *packs.State, v reflect.Value, f packs.Flags) {
}
func (p rList) packBinarySlice (s *packs.State, v reflect.Value, f packs.Flags) {
func (p rList) packBinarySlice (s *proteus.State, v reflect.Value, f proteus.Flags) {
if f.Binary() {
packBinary(s, v.Interface().([]byte), f)
return
@ -78,7 +78,7 @@ func (p rList) packBinarySlice (s *packs.State, v reflect.Value, f packs.Flags)
func (p rList) packSlice(s *packs.State, v reflect.Value, f packs.Flags) {
func (p rList) packSlice(s *proteus.State, v reflect.Value, f proteus.Flags) {
if v.IsNil() {
s.W(cjson.G.NullValue)
return
@ -95,7 +95,7 @@ func (p rList) packSlice(s *packs.State, v reflect.Value, f packs.Flags) {
if fn,ok := s.CheckCycle(cp); ok {
defer fn()
} else {
s.SetError(packs.G.ErrRedundantPack)
s.SetError(proteus.G.ErrRedundantPack)
return
}
}
@ -105,7 +105,7 @@ func (p rList) packSlice(s *packs.State, v reflect.Value, f packs.Flags) {
func (p rList) pack (s *packs.State, v reflect.Value, f packs.Flags) {
func (p rList) pack (s *proteus.State, v reflect.Value, f proteus.Flags) {
if v.IsNil() {
s.W(cjson.G.NullValue)
return

@ -53,9 +53,9 @@ func newRMap(rtype reflect.Type) *rMap {
}
func (p *rMap) pack (s *packs.State, v reflect.Value, f packs.Flags) {
func (p *rMap) pack (s *proteus.State, v reflect.Value, f proteus.Flags) {
if p.keyFn == nil {
s.SetError(packs.G.ErrInvalidKey)
s.SetError(proteus.G.ErrInvalidKey)
return
}
@ -72,7 +72,7 @@ func (p *rMap) pack (s *packs.State, v reflect.Value, f packs.Flags) {
if fn,ok := s.CheckCycle(v.UnsafePointer()); ok {
defer fn()
} else {
s.SetError(packs.G.ErrRedundantPack)
s.SetError(proteus.G.ErrRedundantPack)
return
}
}

@ -32,7 +32,7 @@ type (
rMapEntry struct {
f packs.Flags // flags
f proteus.Flags // flags
v reflect.Value // value
k string // Key
}

@ -46,7 +46,7 @@ func rObjectPacker (rtype reflect.Type) rPackerFnc {
if !ok {
op,_ = g.fieldsCache.LoadOrStore(rtype,*newRObject(rtype))
}
return func(s *packs.State, value reflect.Value, flags packs.Flags) {
return func(s *proteus.State, value reflect.Value, flags proteus.Flags) {
op.(rObject).pack(s,value,flags)
}
//return (op.(rObject)).pack
@ -85,7 +85,7 @@ func newRObject(rtype reflect.Type) *rObject {
continue
}
nm, fg, has := packs.FlagsFromPackTag(sf.Tag)
nm, fg, has := proteus.FlagsFromPackTag(sf.Tag)
if !has {
nm, fg, has = jsonTags(sf.Tag)
}
@ -93,7 +93,7 @@ func newRObject(rtype reflect.Type) *rObject {
if nm == "-" || fg.Omit() {
continue
}
if !packs.CheckTag(nm) {
if !proteus.CheckTag(nm) {
nm = ""
}
}
@ -114,7 +114,7 @@ func newRObject(rtype reflect.Type) *rObject {
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr,
reflect.Float32, reflect.Float64,
reflect.String:
fg = fg| packs.FlagQuote
fg = fg| proteus.FlagQuote
}
}
@ -131,7 +131,7 @@ func newRObject(rtype reflect.Type) *rObject {
flags : fg,
}
of.nameB = []byte(of.name)
of.foldFn= packs.GetFoldFunc(of.nameB)
of.foldFn= proteus.GetFoldFunc(of.nameB)
// Build nameEscHTML and nameNonEsc ahead of time.
nms.Reset()
@ -211,7 +211,7 @@ func newRObject(rtype reflect.Type) *rObject {
func (o rObject) pack (s *packs.State, v reflect.Value, f packs.Flags) {
func (o rObject) pack (s *proteus.State, v reflect.Value, f proteus.Flags) {
nx := byte('{')
FieldLoop:
for i:= range o.fields {
@ -248,11 +248,11 @@ FieldLoop:
}
func jsonTags (tag reflect.StructTag) (string, packs.Flags,bool) {
return packs.FlagsFromTag(tag,jsonTag,func(n string) packs.Flags {
func jsonTags (tag reflect.StructTag) (string, proteus.Flags,bool) {
return proteus.FlagsFromTag(tag,jsonTag,func(n string) proteus.Flags {
switch n {
case "omitempty" : return packs.FlagOmitEmpty
case "quote" : return packs.FlagQuote
case "omitempty" : return proteus.FlagOmitEmpty
case "quote" : return proteus.FlagQuote
default : return 0
}
})

@ -39,9 +39,9 @@ type (
isTagged bool
index []int
rtype reflect.Type
flags packs.Flags
flags proteus.Flags
foldFn packs.FoldFnc
foldFn proteus.FoldFnc
packerFn rPackerFnc
}

@ -47,7 +47,7 @@ func newRPointer (rtype reflect.Type) *rPointer {
}
func (p rPointer) pack (s *packs.State, v reflect.Value, f packs.Flags) {
func (p rPointer) pack (s *proteus.State, v reflect.Value, f proteus.Flags) {
if v.IsNil() {
s.W(cjson.G.NullValue)
return

@ -36,6 +36,6 @@ func rValuePacker (rvalue reflect.Value) rPackerFnc {
}
func invalidValuePacker(state *packs.State, _ reflect.Value, _ packs.Flags) {
state.SetError(packs.G.ErrInvalidValue)
func invalidValuePacker(state *proteus.State, _ reflect.Value, _ proteus.Flags) {
state.SetError(proteus.G.ErrInvalidValue)
}

@ -21,13 +21,13 @@
// limitations under the License.
// ------------------------------------------------------------------------
package packs
package proteus
import (
"bins/mems"
"crypts"
"sync/atomic"
"syncs"
"syncs/pools"
)
@ -53,8 +53,8 @@ type (
func NewState(options ...StateFnc) *State {
if atomic.CompareAndSwapUint32(&g.poolsSem,0,1) {
g.statePool = syncs.NewPool[State](
syncs.PoolWithNew[State](func() *State {
g.statePool = pools.NewGPool[State](
pools.WithNew[State](func() *State {
return &State{
ABuffer: mems.NewABuffer(),
checks : make(map[any]struct{}),

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package packs
package proteus
import "time"
Loading…
Cancel
Save

Powered by TurnKey Linux.