Corregido el packer y cambiado el nombre del interface de Builder a PackBuilder.

master
DEV 2 years ago
parent 5333ba61bf
commit d8e04e77b1

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package hecate
package alogs
import (
"atypes/astrings"

@ -24,8 +24,8 @@
package ejson
import (
"hecate"
"proteus/pjson"
"alogs"
"apacks/pjson"
"results"
)
@ -38,5 +38,5 @@ type (
func EncodeEntry (entry *hecate.Entry) results.Bytes {
func EncodeEntry (entry *alogs.Entry) results.Bytes {
return pjson.Pack(entry) }

@ -21,11 +21,10 @@
// limitations under the License.
// ------------------------------------------------------------------------
package hecate
package alogs
import (
"atypes/slices"
"proteus"
"time"
)
@ -118,8 +117,8 @@ func (e *Entry) Clone() *Entry {
}
func (e *Entry) BuildPack(packer proteus.ValuePacker) error {
packer.PackObject(func (b proteus.ObjectPackBuilder, _ proteus.Flags){
func (e *Entry) BuildPack(packer apacks.ValuePacker) error {
packer.PackObject(func (b apacks.ObjectPackBuilder, _ apacks.Flags){
b.FieldUInt64("id",e.Id,0)
b.FieldDate("date",e.Date,0)
},0)

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package hecate
package alogs
type (

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package hecate
package alogs
type (

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package hecate
package alogs
type (

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package hecate
package alogs
type (

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package hecate
package alogs
import (
"bins/tokens"

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package hecate
package alogs
type (

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package hecate
package alogs
type (

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

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package hecate
package alogs
import (
"math/bits"

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package hecate
package alogs
type (

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package hecate
package alogs
type (

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package hecate
package alogs
import (
"errs"
@ -33,9 +33,10 @@ type (
LoggerCore struct {
sync.RWMutex
EntryFilters
EntryExtenders
EntryAppender
filters EntryFilters
extenders EntryExtenders
appender EntryAppender
name string
level Level
@ -57,6 +58,8 @@ type (
LoggerCoreFnc func(l *LoggerCore)
LoggerCoreEventFnc func (l *LoggerCore) error
LoggerCoreEntryFnc func (l *LoggerCore, entry *Entry)
LoggerCoreErrorFnc func (l *LoggerCore, entry *Entry, err error)
@ -67,8 +70,8 @@ type (
func NewLoggerCore (name string, level Level, options ...LoggerCoreFnc) *LoggerCore {
l := &LoggerCore {
EntryFilters : *NewEntryFilters(),
EntryAppender: AppendEntryFnc(nopEntryAppender),
filters : *NewEntryFilters(),
appender : AppendEntryFnc(nopEntryAppender),
name : name,
level : level,
state : StateCreated,
@ -80,7 +83,7 @@ func NewLoggerCore (name string, level Level, options ...LoggerCoreFnc) *LoggerC
}
//
if l.onFlushFn == nil {
if fl,is := l.EntryAppender.(iosys.Flusher); is {
if fl,is := l.appender.(iosys.Flusher); is {
l.onFlushFn = func(c *LoggerCore) error {
return fl.Flush() }
} else {
@ -187,8 +190,8 @@ func (l *LoggerCore) log(level Level, msg string, err error, options ...EntryFnc
return
}
en := l.ExtendEntry(AcquireEntry(l,level,msg,err,options...))
if er := l.AppendEntry(en); er != nil {
en := l.extenders.ExtendEntry(AcquireEntry(l,level,msg,err,options...))
if er := l.appender.AppendEntry(en); er != nil {
l.handleError(er,en)
}
l.Unlock()
@ -201,32 +204,22 @@ func (l *LoggerCore) log(level Level, msg string, err error, options ...EntryFnc
}
func (l *LoggerCore) Append (entry *Entry) error {
func (l *LoggerCore) Log(entry *Entry) error {
l.Lock()
if l.state != StateStarted {
l.Unlock()
return G.ErrLoggerNotStarted
}
if !l.level.Has(entry.Level) || entry.Excludes.Has(l.name) || !l.Filter(entry) {
if !l.level.Has(entry.Level) || entry.Excludes.Has(l.name) || !l.filters.Filter(entry) {
l.Unlock()
return nil
}
er := l.AppendEntry(entry)
er := l.appender.AppendEntry(entry)
l.Unlock()
return er
}
func (l *LoggerCore) append (entry *Entry) error {
er := l.AppendEntry(entry)
if er != nil {
l.handleError(er,entry)
return er
}
l.count++
return nil
}
func (l *LoggerCore) Flush () error {
l.Lock()
@ -251,8 +244,6 @@ func (l *LoggerCore) handleError (err error, entry *Entry) {
return
}
l.errors = l.errors.Append(err)
if l.onErrorFn != nil {
l.onErrorFn(l, entry, err)
}
@ -286,17 +277,17 @@ func LoggerCoreWithOnError (onError LoggerCoreErrorFnc) LoggerCoreFnc {
func LoggerCoreWithExtender (extender ...EntryExtender) LoggerCoreFnc {
return func(a *LoggerCore) {
a.EntryExtenders = append(a.EntryExtenders,extender...) } }
a.extenders = append(a.extenders,extender...) } }
func LoggerCoreWithFilters (configFilters EntryFiltersFnc) LoggerCoreFnc {
return func(a *LoggerCore) {
configFilters(&a.EntryFilters) } }
configFilters(&a.filters) } }
func LoggerCoreWithAppender(appender EntryAppender) LoggerCoreFnc {
return func(a *LoggerCore) {
a.EntryAppender = appender } }
a.appender = appender } }

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package hecate
package alogs
import (
"errs"
@ -35,8 +35,9 @@ type (
LoggerManager struct {
sync.RWMutex
EntryFilters
EntryExtenders
filters EntryFilters
extenders EntryExtenders
queue queue.GQueue[*Entry]
@ -65,7 +66,7 @@ type (
func NewLoggerManager(name string, level Level, options ...LoggerManagerFnc) *LoggerManager {
l := &LoggerManager{
EntryFilters: *NewEntryFilters(),
filters : *NewEntryFilters(),
level : level,
state : StateCreated,
logErrors: true,
@ -267,17 +268,17 @@ func (l *LoggerManager) Log (entry *Entry) error {
l.Unlock()
return G.ErrLoggerNotStarted
}
if !l.level.Has(entry.Level) || !l.Filter(entry) {
if !l.level.Has(entry.Level) || !l.filters.Filter(entry) {
l.Unlock()
return nil
}
if entry.Logger == nil {
//viene de un scope
entry.Logger = l
l.ExtendEntry(entry)
l.extenders.ExtendEntry(entry)
}
return l.doCores(entry,func(c *LoggerCore, e *Entry) error { return c.Append(e) },G.FmtMsgLogLogErr,false)
return l.doCores(entry,func(c *LoggerCore, e *Entry) error { return c.Log(e) },G.FmtMsgLogLogErr,false)
}
@ -290,7 +291,7 @@ func (l *LoggerManager) log (level Level, msg string, err error,options []EntryF
l.count++
en := AcquireEntry(l,level,msg,err,options...)
_ = l.doCores(en,func(c *LoggerCore, e *Entry) error { return c.Append(e) },G.FmtMsgLogLogErr,true)
_ = l.doCores(en,func(c *LoggerCore, e *Entry) error { return c.Log(e) },G.FmtMsgLogLogErr,true)
if level == LevelFatal && l.onFatalFn != nil {
l.onFatalFn(l,en)
@ -306,7 +307,10 @@ func (l *LoggerManager) handleError (err error, entry *Entry) {
l.Lock()
l.errors = l.errors.Append(err)
if l.logErrors {
//todo construir entry desde err
if entry == nil {
entry = AcquireEntry(l,LevelError,err.Error(),err)
}
l.queue.Push(entry)
}
l.Unlock()
@ -318,7 +322,7 @@ func (l *LoggerManager) handleError (err error, entry *Entry) {
func (l *LoggerManager) enqueue() {
for en := l.queue.Pop(); en != nil; {
_ = l.doCores(en,func(c *LoggerCore, e *Entry) error { return c.Append(e) },G.FmtMsgLogLogErr,true)
_ = l.doCores(en,func(c *LoggerCore, e *Entry) error { return c.Log(e) },G.FmtMsgLogLogErr,true)
ReleaseEntry(en)
}
}
@ -326,28 +330,28 @@ func (l *LoggerManager) enqueue() {
func (l *LoggerManager) doCores (entry *Entry, doFn func(c *LoggerCore, e *Entry) error, msg string, unlock bool) error {
var el errs.ErrorList
for _,co := range l.cores {
if er := doFn(co,entry); er != nil {
el = el.Append(er)
var en *Entry
ms := fmt.Sprintf(msg,co.name)
ne := errs.NewErrMessage(er,msg)
if l.logErrors {
l.queue.Push(AcquireEntry(l,LevelError,fmt.Sprintf(msg,co.name),er,
EntryWithExtender(l.EntryExtenders),
en = AcquireEntry(l,LevelError,ms,ne,
EntryWithExtender(l.extenders),
EntryWithExclude (co.name),
EntryWithField (entryFieldCoreName,co.name,true)))
EntryWithField (entryFieldCoreName,co.name,true))
}
l.handleError(er,en)
}
}
if unlock {
l.Unlock()
}
if er := errs.NewErrMultiIf(el); er != nil {
l.handleError (er,entry )
return er
}
return nil
return errs.NewErrMultiIf(el)
}
func (l *LoggerManager) findCore(name string) int {
for i :=0; i < len(l.cores); i++ {
if l.cores[i].name == name {
@ -360,7 +364,7 @@ func (l *LoggerManager) findCore(name string) int {
func LoggerManagerWithFilters (configFilters EntryFiltersFnc) LoggerManagerFnc {
return func(a *LoggerManager) {
configFilters(&a.EntryFilters) } }
configFilters(&a.filters) } }
func LoggerManagerWithOnFatal (onFatal LoggerManagerEntryFnc) LoggerManagerFnc {
@ -375,6 +379,6 @@ func LoggerManagerWithOnError (onError LoggerManagerErrorFnc) LoggerManagerFnc {
func LoggerManagerWithExtender (extender ...EntryExtender) LoggerManagerFnc {
return func(a *LoggerManager) {
a.EntryExtenders = append(a.EntryExtenders,extender...) } }
a.extenders = append(a.extenders,extender...) } }

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package hecate
package alogs
import (
"fmt"

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package hecate
package alogs

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package hecate
package alogs
const (

@ -21,7 +21,7 @@
// limitations under the License.
// ------------------------------------------------------------------------
package hecate
package alogs
const (

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

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

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

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

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

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

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

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

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

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

@ -28,7 +28,7 @@ import (
"crypts"
"encoding/json"
"errs"
"proteus"
"apacks"
"reflect"
"time"
)
@ -38,7 +38,7 @@ type (
JSONPacker struct {
state *proteus.State
state *apacks.State
dirty bool
}
@ -49,7 +49,7 @@ type (
func NewJSONPacker(options ...JSONPackerFnc) *JSONPacker {
pk := &JSONPacker{
state : proteus.NewState(),
state : apacks.NewState(),
}
for _,o := range options {
o(pk)
@ -59,12 +59,12 @@ func NewJSONPacker(options ...JSONPackerFnc) *JSONPacker {
func (p *JSONPacker) Pack (value any, flags proteus.Flags) {
func (p *JSONPacker) Pack (value any, flags apacks.Flags) {
if p.state.Error != nil {
panic(proteus.G.ErrInvalidState.WrapWithCause(p.state.Error))
panic(apacks.G.ErrInvalidState.WrapWithCause(p.state.Error))
}
if p.dirty {
panic(proteus.G.ErrInvalidState)
panic(apacks.G.ErrInvalidState)
}
p.dirty = true
p.PackAny(value,flags)
@ -86,14 +86,14 @@ func (p *JSONPacker) Reset () {
func (p *JSONPacker) Release () {
p.dirty = false
proteus.ReleaseState(p.state)
apacks.ReleaseState(p.state)
}
func (p *JSONPacker) PackAny (value any, flags proteus.Flags) {
func (p *JSONPacker) PackAny (value any, flags apacks.Flags) {
if p.state.Error != nil {
panic(proteus.G.ErrInvalidState.WrapWithCause(p.state.Error))
panic(apacks.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 proteus.Flags) {
}
switch v := value.(type) {
case proteus.PackBuilder:
case apacks.PackBuilder:
p.state.SetError(v.BuildPack(p))
case json.Marshaler:
@ -166,45 +166,45 @@ func (p *JSONPacker) PackAny (value any, flags proteus.Flags) {
func (p *JSONPacker) PackRaw (value []byte, flags proteus.Flags) { packRaw(p.state,value,flags) }
func (p *JSONPacker) PackRaw (value []byte, flags apacks.Flags) { packRaw(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) PackBinary (value []byte, flags apacks.Flags) { packBinary(p.state,value,flags) }
func (p *JSONPacker) PackString (value string, flags apacks.Flags) { packString (p.state,value,flags) }
func (p *JSONPacker) PackBool (value bool, flags proteus.Flags) { packBool(p.state,value,flags) }
func (p *JSONPacker) PackBool (value bool, flags apacks.Flags) { packBool(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) PackInt8 (value int8 , flags apacks.Flags) { packInt(p.state,int64(value),flags) }
func (p *JSONPacker) PackInt16 (value int16, flags apacks.Flags) { packInt(p.state,int64(value),flags) }
func (p *JSONPacker) PackInt32 (value int32, flags apacks.Flags) { packInt(p.state,int64(value),flags) }
func (p *JSONPacker) PackInt64 (value int64, flags apacks.Flags) { packInt(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) PackUInt8 (value uint8 , flags apacks.Flags) { packUInt(p.state,uint64(value),flags) }
func (p *JSONPacker) PackUInt16 (value uint16, flags apacks.Flags) { packUInt(p.state,uint64(value),flags) }
func (p *JSONPacker) PackUInt32 (value uint32, flags apacks.Flags) { packUInt(p.state,uint64(value),flags) }
func (p *JSONPacker) PackUInt64 (value uint64, flags apacks.Flags) { packUInt(p.state, value,flags) }
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) PackFloat32 (value float32, flags apacks.Flags) { packFloatString(p.state, float64(value), flags, 32) }
func (p *JSONPacker) PackFloat64 (value float64, flags apacks.Flags) { packFloatString(p.state, value, flags, 64) }
func (p *JSONPacker) PackDate (value time.Time, flags proteus.Flags) { packDate(p.state,value,flags) }
func (p *JSONPacker) PackDate (value time.Time, flags apacks.Flags) { packDate(p.state,value,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) PackList (builder func(apacks.ListPackBuilder, apacks.Flags), flags apacks.Flags) {
p.packCompound('[',']',builder==nil,func(pk *JSONPacker, fl apacks.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) PackMap (builder func(apacks.MapPackBuilder, apacks.Flags), flags apacks.Flags) {
p.packCompound('{','}',builder==nil,func(pk *JSONPacker, fl apacks.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) PackObject(builder func(apacks.ObjectPackBuilder, apacks.Flags), flags apacks.Flags) {
p.packCompound('{','}',builder==nil,func(pk *JSONPacker, fl apacks.Flags){ builder(pk,fl) },flags)
}
func (p *JSONPacker) packCompound (opener, closer byte, isnil bool, buildFn func(*JSONPacker, proteus.Flags), flags proteus.Flags) {
func (p *JSONPacker) packCompound (opener, closer byte, isnil bool, buildFn func(*JSONPacker, apacks.Flags), flags apacks.Flags) {
if p.state.Error != nil {
panic(proteus.G.ErrInvalidState.WrapWithCause(p.state.Error))
panic(apacks.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 *proteus.State, value []byte, flags proteus.Flags) {
func packRaw (state *apacks.State, value []byte, flags apacks.Flags) {
if state.Error != nil {
panic(proteus.G.ErrInvalidState.WrapWithCause(state.Error))
panic(apacks.G.ErrInvalidState.WrapWithCause(state.Error))
}
if value == nil {
state.W(cjson.G.NullValue)
@ -244,9 +244,9 @@ func packRaw (state *proteus.State, value []byte, flags proteus.Flags) {
state.WOQ(flags.Quote(),'"',value)
}
func packString (state *proteus.State, value string , flags proteus.Flags) {
func packString (state *apacks.State, value string , flags apacks.Flags) {
if state.Error != nil {
panic(proteus.G.ErrInvalidState.WrapWithCause(state.Error))
panic(apacks.G.ErrInvalidState.WrapWithCause(state.Error))
}
if len(value) == 0 {
@ -255,7 +255,7 @@ func packString (state *proteus.State, value string , flags proteus.Flags) {
}
if flags.Encrypted() {
packEncrypted(state, []byte(value), flags|proteus.FlagBinary64)
packEncrypted(state, []byte(value), flags|apacks.FlagBinary64)
return
}
@ -268,7 +268,7 @@ func packString (state *proteus.State, value string , flags proteus.Flags) {
}
func packEncrypted (state *proteus.State, value []byte, flags proteus.Flags) {
func packEncrypted (state *apacks.State, value []byte, flags apacks.Flags) {
r := state.Encrypter.Encrypt(value)
if !r.Ok() {
state.SetError(r.Fail())
@ -276,16 +276,16 @@ func packEncrypted (state *proteus.State, value []byte, flags proteus.Flags) {
}
if !flags.Binary() {
flags|= proteus.FlagBinary64
flags|= apacks.FlagBinary64
}
packBinary(state,value,flags)
}
func packBinary (state *proteus.State, value []byte , flags proteus.Flags) {
func packBinary (state *apacks.State, value []byte , flags apacks.Flags) {
if state.Error != nil {
panic(proteus.G.ErrInvalidState.WrapWithCause(state.Error))
panic(apacks.G.ErrInvalidState.WrapWithCause(state.Error))
}
if flags.Bin64() {
@ -296,48 +296,48 @@ func packBinary (state *proteus.State, value []byte , flags proteus.Flags) {
state.SetError(cjson.WriteBase32(state.ABuffer,value))
return
}
state.SetError(proteus.G.ErrUnsupportedType)
state.SetError(apacks.G.ErrUnsupportedType)
}
func packBool (state *proteus.State, value bool , flags proteus.Flags) {
func packBool (state *apacks.State, value bool , flags apacks.Flags) {
if state.Error != nil {
panic(proteus.G.ErrInvalidState.WrapWithCause(state.Error))
panic(apacks.G.ErrInvalidState.WrapWithCause(state.Error))
}
cjson.WriteBool(state.ABuffer,value,flags.Quote())
}
func packInt (state *proteus.State, value int64 , flags proteus.Flags) {
func packInt (state *apacks.State, value int64 , flags apacks.Flags) {
if state.Error != nil {
panic(proteus.G.ErrInvalidState.WrapWithCause(state.Error))
panic(apacks.G.ErrInvalidState.WrapWithCause(state.Error))
}
cjson.WriteInt(state.ABuffer,value,flags.Quote())
}
func packUInt (state *proteus.State, value uint64 , flags proteus.Flags) {
func packUInt (state *apacks.State, value uint64 , flags apacks.Flags) {
if state.Error != nil {
panic(proteus.G.ErrInvalidState.WrapWithCause(state.Error))
panic(apacks.G.ErrInvalidState.WrapWithCause(state.Error))
}
cjson.WriteUint(state.ABuffer,value,flags.Quote())
}
func packFloat (state *proteus.State, value float64, flags proteus.Flags) {
func packFloat (state *apacks.State, value float64, flags apacks.Flags) {
packFloatString(state, value, flags, 64) }
func packFloatString (state *proteus.State, f float64, flags proteus.Flags, bits int) {
func packFloatString (state *apacks.State, f float64, flags apacks.Flags, bits int) {
if state.Error != nil {
panic(proteus.G.ErrInvalidState.WrapWithCause(state.Error))
panic(apacks.G.ErrInvalidState.WrapWithCause(state.Error))
}
cjson.WriteFloat(state.ABuffer,f,bits,flags.Quote())
}
func packDate(state *proteus.State, value time.Time, flags proteus.Flags) {
func packDate(state *apacks.State, value time.Time, flags apacks.Flags) {
if state.Error != nil {
panic(proteus.G.ErrInvalidState.WrapWithCause(state.Error))
panic(apacks.G.ErrInvalidState.WrapWithCause(state.Error))
}
cjson.WriteDate(state.ABuffer,value,flags.DateFormat(),true)
}
@ -347,7 +347,7 @@ func packDate(state *proteus.State, value time.Time, flags proteus.Flags) {
func packListString (state *proteus.State, list []string, flags proteus.Flags) {
func packListString (state *apacks.State, list []string, flags apacks.Flags) {
if !checkList(state,list == nil, len(list) ==0) {
return
}
@ -365,7 +365,7 @@ func packListString (state *proteus.State, list []string, flags proteus.Flags) {
}
func packListBool (state *proteus.State, list []bool, flags proteus.Flags) {
func packListBool (state *apacks.State, list []bool, flags apacks.Flags) {
if !checkList(state,list == nil, len(list) ==0) {
return
}
@ -383,7 +383,7 @@ func packListBool (state *proteus.State, list []bool, flags proteus.Flags) {
}
func packListInt [T int | int8 | int16 | int32 | int64](state *proteus.State, list []T, flags proteus.Flags) {
func packListInt [T int | int8 | int16 | int32 | int64](state *apacks.State, list []T, flags apacks.Flags) {
if !checkList(state,list == nil, len(list) ==0) {
return
}
@ -401,7 +401,7 @@ func packListInt [T int | int8 | int16 | int32 | int64](state *proteus.State, l
}
func packListUInt [T uint | uint8 | uint16 | uint32 | uint64](state *proteus.State, list []T, flags proteus.Flags) {
func packListUInt [T uint | uint8 | uint16 | uint32 | uint64](state *apacks.State, list []T, flags apacks.Flags) {
if !checkList(state,list == nil, len(list) ==0) {
return
}
@ -419,7 +419,7 @@ func packListUInt [T uint | uint8 | uint16 | uint32 | uint64](state *proteus.Sta
}
func packListFloat[T float32 | float64](state *proteus.State, list []T, flags proteus.Flags, bits int) {
func packListFloat[T float32 | float64](state *apacks.State, list []T, flags apacks.Flags, bits int) {
if !checkList(state,list == nil, len(list) ==0) {
return
}
@ -436,7 +436,7 @@ func packListFloat[T float32 | float64](state *proteus.State, list []T, flags pr
state.WriteByte(']')
}
func packListDate (state *proteus.State, list []time.Time, flags proteus.Flags) {
func packListDate (state *apacks.State, list []time.Time, flags apacks.Flags) {
if !checkList(state,list == nil, len(list) ==0) {
return
}
@ -454,7 +454,7 @@ func packListDate (state *proteus.State, list []time.Time, flags proteus.Flags)
}
func checkList (state *proteus.State, isNull, isEmpty bool) bool {
func checkList (state *apacks.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 (
"apacks"
"time"
)
func (p *JSONPacker) ItemAny (value any, flags apacks.Flags) { p.addItem(func(){ p.PackAny(value,flags) }) }
func (p *JSONPacker) ItemRaw (value []byte, flags apacks.Flags) { p.addItem(func() { p.PackRaw(value,flags) }) }
func (p *JSONPacker) ItemBinary (value []byte, flags apacks.Flags) { p.addItem(func (){ p.PackBinary(value,flags) }) }
func (p *JSONPacker) ItemString (value string, flags apacks.Flags) { p.addItem(func (){ p.PackString(value,flags) }) }
func (p *JSONPacker) ItemBool (value bool, flags apacks.Flags) { p.addItem(func (){ p.PackBool(value,flags) }) }
func (p *JSONPacker) ItemInt8 (value int8 , flags apacks.Flags) { p.addItem(func (){ packInt(p.state,int64(value),flags) }) }
func (p *JSONPacker) ItemInt16 (value int16, flags apacks.Flags) { p.addItem(func (){ packInt(p.state,int64(value),flags) }) }
func (p *JSONPacker) ItemInt32 (value int32, flags apacks.Flags) { p.addItem(func (){ packInt(p.state,int64(value),flags) }) }
func (p *JSONPacker) ItemInt64 (value int64, flags apacks.Flags) { p.addItem(func (){ packInt(p.state,value,flags) }) }
func (p *JSONPacker) ItemUInt8 (value uint8 , flags apacks.Flags){ p.addItem(func (){ packUInt(p.state,uint64(value),flags) }) }
func (p *JSONPacker) ItemUInt16 (value uint16, flags apacks.Flags){ p.addItem(func (){ packUInt(p.state,uint64(value),flags) }) }
func (p *JSONPacker) ItemUInt32 (value uint32, flags apacks.Flags){ p.addItem(func (){ packUInt(p.state,uint64(value),flags) }) }
func (p *JSONPacker) ItemUInt64 (value uint64, flags apacks.Flags){ p.addItem(func (){ packUInt(p.state,uint64(value),flags) }) }
func (p *JSONPacker) ItemFloat32 (value float32, flags apacks.Flags){ p.addItem(func (){ packFloatString(p.state,float64(value),flags,32)})}
func (p *JSONPacker) ItemFloat64 (value float64, flags apacks.Flags){ p.addItem(func (){ packFloatString(p.state,value,flags,64) })}
func (p *JSONPacker) ItemDate (value time.Time, flags apacks.Flags) { p.addItem(func(){ packDate(p.state,value,flags); p.state.Inc() })}
func (p *JSONPacker) ItemList (builder func(apacks.ListPackBuilder, apacks.Flags), flags apacks.Flags) {
p.addItem(func(){ p.PackList(builder,flags) }) }
func (p *JSONPacker) ItemMap (builder func(apacks.MapPackBuilder, apacks.Flags), flags apacks.Flags) {
p.addItem(func(){ p.PackMap(builder,flags) }) }
func (p *JSONPacker) ItemObject(builder func(apacks.ObjectPackBuilder, apacks.Flags), flags apacks.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()
}
}

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

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

@ -24,7 +24,7 @@
package pjson
import (
"proteus"
apacks "packs"
"reflect"
"sync"
)
@ -33,7 +33,7 @@ type (
rPackerFnc func (state *proteus.State, rvalue reflect.Value, flags proteus.Flags)
rPackerFnc func (state *apacks.State, rvalue reflect.Value, flags apacks.Flags)
)
@ -49,7 +49,7 @@ func rTypePacker (rtype reflect.Type) rPackerFnc {
wg.Add(1)
fi,ld := g.packersCache.LoadOrStore(rtype, rPackerFnc(func (e *proteus.State, v reflect.Value, f proteus.Flags) {
fi,ld := g.packersCache.LoadOrStore(rtype, rPackerFnc(func (e *apacks.State, v reflect.Value, f apacks.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 *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.Bool : return func(s *apacks.State, v reflect.Value, f apacks.Flags) { packBool (s,v.Bool (),f )}
case reflect.String : return func(s *apacks.State, v reflect.Value, f apacks.Flags) { packString(s,v.String(),f )}
case reflect.Int,
reflect.Int8,
reflect.Int16,
reflect.Int32,
reflect.Int64 : return func(s *proteus.State, v reflect.Value, f proteus.Flags) { packInt (s,v.Int (),f )}
reflect.Int64 : return func(s *apacks.State, v reflect.Value, f apacks.Flags) { packInt (s,v.Int (),f )}
case reflect.Uint,
reflect.Uint8,
reflect.Uint16,
reflect.Uint32,
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) }
reflect.Uint64 : return func(s *apacks.State, v reflect.Value, f apacks.Flags) { packUInt (s,v.Uint (),f )}
case reflect.Float32: return func(s *apacks.State, v reflect.Value, f apacks.Flags) { packFloatString(s,v.Float(),f,32) }
case reflect.Float64: return func(s *apacks.State, v reflect.Value, f apacks.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 *proteus.State, _ reflect.Value, _ proteus.Flags) {
state.SetError(proteus.G.ErrUnsupportedType)
func unsupportedTypePacker(state *apacks.State, _ reflect.Value, _ apacks.Flags) {
state.SetError(apacks.G.ErrUnsupportedType)
}

@ -25,11 +25,11 @@ package pjson
import (
"codecs/cjson"
"proteus"
"apacks"
"reflect"
)
func rInterfacePacker (s *proteus.State, v reflect.Value, f proteus.Flags) {
func rInterfacePacker (s *apacks.State, v reflect.Value, f apacks.Flags) {
if v.IsNil() {
s.W(cjson.G.NullValue)
return

@ -26,7 +26,7 @@ package pjson
import (
"encoding"
"math"
"proteus"
"apacks"
"reflect"
"strconv"
)
@ -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 = proteus.FlagScapeHTML
e.f = apacks.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 = proteus.FlagScapeHTML
e.f = apacks.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 = proteus.FlagScapeHTML
e.f = apacks.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 = proteus.FlagScapeHTML
e.f = apacks.FlagScapeHTML
}
return er
}
@ -128,7 +128,7 @@ func _stringifyRKey(rt reflect.Type) rMapEntryFnc {
return nil
default:
return proteus.G.ErrInvalidKey
return apacks.G.ErrInvalidKey
}
}

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

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

@ -24,7 +24,7 @@
package pjson
import (
"proteus"
"apacks"
"reflect"
)
@ -32,7 +32,7 @@ type (
rMapEntry struct {
f proteus.Flags // flags
f apacks.Flags // flags
v reflect.Value // value
k string // Key
}

@ -25,7 +25,7 @@ package pjson
import (
"mems"
"proteus"
"apacks"
"reflect"
"sort"
)
@ -46,7 +46,7 @@ func rObjectPacker (rtype reflect.Type) rPackerFnc {
if !ok {
op,_ = g.fieldsCache.LoadOrStore(rtype,*newRObject(rtype))
}
return func(s *proteus.State, value reflect.Value, flags proteus.Flags) {
return func(s *apacks.State, value reflect.Value, flags apacks.Flags) {
op.(rObject).pack(s,value,flags)
}
//return (op.(rObject)).pack
@ -87,7 +87,7 @@ func newRObject(rtype reflect.Type) *rObject {
continue
}
nm, fg, has := proteus.FlagsFromPackTag(sf.Tag)
nm, fg, has := apacks.FlagsFromPackTag(sf.Tag)
if !has {
nm, fg, has = jsonTags(sf.Tag)
}
@ -95,7 +95,7 @@ func newRObject(rtype reflect.Type) *rObject {
if nm == "-" || fg.Omit() {
continue
}
if !proteus.CheckTag(nm) {
if !apacks.CheckTag(nm) {
nm = ""
}
}
@ -116,7 +116,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| proteus.FlagQuote
fg = fg| apacks.FlagQuote
}
}
@ -133,7 +133,7 @@ func newRObject(rtype reflect.Type) *rObject {
flags : fg,
}
of.nameB = []byte(of.name)
of.foldFn= proteus.GetFoldFunc(of.nameB)
of.foldFn= apacks.GetFoldFunc(of.nameB)
// BuildPack nameEscHTML and nameNonEsc ahead of time.
nms.Reset()
@ -213,7 +213,7 @@ func newRObject(rtype reflect.Type) *rObject {
func (o rObject) pack (s *proteus.State, v reflect.Value, f proteus.Flags) {
func (o rObject) pack (s *apacks.State, v reflect.Value, f apacks.Flags) {
nx := byte('{')
FieldLoop:
for i:= range o.fields {
@ -250,11 +250,11 @@ FieldLoop:
}
func jsonTags (tag reflect.StructTag) (string, proteus.Flags,bool) {
return proteus.FlagsFromTag(tag,jsonTag,func(n string) proteus.Flags {
func jsonTags (tag reflect.StructTag) (string, apacks.Flags,bool) {
return apacks.FlagsFromTag(tag,jsonTag,func(n string) apacks.Flags {
switch n {
case "omitempty" : return proteus.FlagOmitEmpty
case "quote" : return proteus.FlagQuote
case "omitempty" : return apacks.FlagOmitEmpty
case "quote" : return apacks.FlagQuote
default : return 0
}
})

@ -24,7 +24,7 @@
package pjson
import (
"proteus"
"apacks"
"reflect"
)
@ -39,9 +39,9 @@ type (
isTagged bool
index []int
rtype reflect.Type
flags proteus.Flags
flags apacks.Flags
foldFn proteus.FoldFnc
foldFn apacks.FoldFnc
packerFn rPackerFnc
}

@ -25,7 +25,7 @@ package pjson
import (
"codecs/cjson"
"proteus"
"apacks"
"reflect"
)
@ -47,7 +47,7 @@ func newRPointer (rtype reflect.Type) *rPointer {
}
func (p rPointer) pack (s *proteus.State, v reflect.Value, f proteus.Flags) {
func (p rPointer) pack (s *apacks.State, v reflect.Value, f apacks.Flags) {
if v.IsNil() {
s.W(cjson.G.NullValue)
return

@ -24,7 +24,7 @@
package pjson
import (
"proteus"
"apacks"
"reflect"
)
@ -36,6 +36,6 @@ func rValuePacker (rvalue reflect.Value) rPackerFnc {
}
func invalidValuePacker(state *proteus.State, _ reflect.Value, _ proteus.Flags) {
state.SetError(proteus.G.ErrInvalidValue)
func invalidValuePacker(state *apacks.State, _ reflect.Value, _ apacks.Flags) {
state.SetError(apacks.G.ErrInvalidValue)
}

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

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

@ -1,10 +1,9 @@
package main
import (
"alogs/ejson"
"errs"
"fmt"
"hecate"
"hecate/ejson"
"os"
)
@ -16,7 +15,7 @@ func Print (err error) {
}
func Append (entry *hecate.Entry) error {
func Append (entry *alogs.Entry) error {
rs := ejson.EncodeEntry(entry)
if !rs.Ok() {
@ -30,9 +29,9 @@ func Append (entry *hecate.Entry) error {
func main() {
l := hecate.NewLoggerManager("Main",hecate.LevelAll)
l := alogs.NewLoggerManager("Main",alogs.LevelAll)
l.AddCore(hecate.NewLoggerCore("MiLogger",hecate.LevelAll,hecate.LoggerCoreWithAppender(hecate.AppendEntryFnc(Append))))
l.AddCore(alogs.NewLoggerCore("MiLogger",alogs.LevelAll,alogs.LoggerCoreWithAppender(alogs.AppendEntryFnc(Append))))
l.Start(true)
l.Warn("Esto es un mensage")

@ -0,0 +1,63 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name err_message.go
// Created by DEV
// Modified 27/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 errs
type (
ErrMessage struct {
error
message string
}
)
func NewErrMessage (err error, message string) *ErrMessage {
if err == nil{
return nil
}
return &ErrMessage{
error: err,
message: message } }
func (e ErrMessage) Message () string {
return e.message }
func (e ErrMessage) WrapWithInfo (options ...ErrInfoFnc) error {
return WrapWithInfo(e,options...) }
func (e ErrMessage) WrapWithCause(cause error) error {
return WrapWithCause(e,cause) }
func (e ErrMessage) WrapWithTrace(offset int) error {
return WrapWithTrace(e,offset) }

@ -18,8 +18,8 @@ use (
./core/ctxs
./core/atypes
./core/mems
./proteus
./hecate
./apacks
./alogs
./app
)

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

@ -1,7 +0,0 @@
module proteus
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 (
"proteus"
"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()
}
}
Loading…
Cancel
Save

Powered by TurnKey Linux.