dado por terminado la reorganizcion del codigo de errores

master
DEV 2 years ago
parent e283bc5e1d
commit 078ac86110

@ -2,7 +2,7 @@ package main
import ( import (
"errs" "errs"
"errs/collr" "errs/collects"
"errs/fjson" "errs/fjson"
"errs/ftext" "errs/ftext"
"errs/stack" "errs/stack"
@ -65,7 +65,7 @@ func (c MiCustomErr) Unwrap () error {
return c.error return c.error
} }
func (c MiCustomErr) Collect (collector collr.Collector) { func (c MiCustomErr) Collect (collector collects.Collector) {
collector.AddFieldInt("UnInt",c.Int()) collector.AddFieldInt("UnInt",c.Int())
collector.AddFieldFloat("UnFloat",34.33) collector.AddFieldFloat("UnFloat",34.33)
collector.AddFieldAny("UnoCualquiera",struct { collector.AddFieldAny("UnoCualquiera",struct {
@ -82,7 +82,7 @@ func (c MiCustomErr) Collect (collector collr.Collector) {
} }
func printCollection (ec collr.ErrorCollection) { func printCollection (ec collects.ErrorCollection) {
if ec.Invalid != nil { if ec.Invalid != nil {
fmt.Printf("INvalid %s\n", ec.Invalid.Error()) fmt.Printf("INvalid %s\n", ec.Invalid.Error())
} }

@ -43,7 +43,7 @@ func NewNonEscapeWriter(w io.Writer) *NonEscapeWriter {
/* /*
func (w *NonEscapeWriter) Write(data []byte) (n int, e error) { func (w *NonEscapeWriter) Write(data []byte) (n int, e error) {
var pt bytes.Buffer var pt bytes.ABuffer
var ef bool var ef bool
for _, b := range data { for _, b := range data {

@ -34,10 +34,10 @@ var (
G = struct { G = struct {
ErrUnsupportedFlagType Err ErrUnsupportedFlagType ErrBits
}{ }{
ErrUnsupportedFlagType : Err{errs.ErrCode ("unsupported-bit-flag-type") }, ErrUnsupportedFlagType : ErrBits{errs.ErrCode ("unsupported-bit-flag-type") },
} }
) )

@ -27,7 +27,7 @@ import "errs"
type ( type (
Err struct { errs.ErrCode } ErrBits struct { errs.ErrCode }
) )

@ -33,16 +33,16 @@ const(
var ( var (
G = struct { G = struct {
ErrInvalidName ErrBField ErrInvalidName ErrBFields
ErrDuplicated ErrBField ErrDuplicated ErrBFields
ErrFixed ErrBField ErrFixed ErrBFields
ErrReadOnly ErrBField ErrReadOnly ErrBFields
}{ }{
ErrInvalidName: ErrBField{errs.ErrCode("invalid-name")}, ErrInvalidName: ErrBFields{errs.ErrCode("invalid-name")},
ErrDuplicated : ErrBField{errs.ErrCode("duplicated-field")}, ErrDuplicated : ErrBFields{errs.ErrCode("duplicated-field")},
ErrFixed : ErrBField{errs.ErrCode("bfields-fixed")}, ErrFixed : ErrBFields{errs.ErrCode("bfields-fixed")},
ErrReadOnly : ErrBField{errs.ErrCode("bfields-read-only")}, ErrReadOnly : ErrBFields{errs.ErrCode("bfields-read-only")},
} }
) )

@ -27,6 +27,6 @@ import "errs"
type ( type (
ErrBField struct { errs.ErrCode } ErrBFields struct { errs.ErrCode }
) )

@ -0,0 +1,39 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name active.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 matchs
var (
G = struct {
ErrInvalidMatcher ErrMatchs
ErrMatcherNotFound ErrMatchs
ErrInvalidBuilder ErrMatchs
}{
ErrInvalidMatcher : ErrMatchs{ ErrCode("invalid-matcher")},
ErrMatcherNotFound: ErrMatchs{ ErrCode("matcher-not-found")},
ErrInvalidBuilder : ErrMatchs{ ErrCode("invalid-builder")},
}
)

@ -0,0 +1,33 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name err_matchs.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 matchs
import "errs"
type (
ErrMatchs { errs.ErrCode }
)

@ -0,0 +1,26 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name matcher.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 matchs

@ -0,0 +1,43 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name active.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 tokens
import "errs"
var (
G = struct {
ErrInvalidTopic ErrTokens
ErrInvalidTopicLen ErrTokens
ErrInvalidToken ErrTokens
ErrInvalidTokenLen ErrTokens
} {
ErrInvalidTopic : ErrTokens{errs.ErrCode("invalid-topic")},
ErrInvalidTopicLen : ErrTokens{errs.ErrCode("invalid-topic-len")},
ErrInvalidToken : ErrTokens{errs.ErrCode("invalid-token")},
ErrInvalidTokenLen : ErrTokens{errs.ErrCode("invalid-token-len")},
}
)

@ -0,0 +1,276 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name atokenizer.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 tokens
const (
topicMinLen int = 1
topicMaxLen int = 255
topicMaxTokens int = 32
topicMinTokens int = 1
tokenMinLen int = 1
tokenMaxLen int = 256
//
// Token chars
//
tokenSep byte = '.'
tokenWildcard byte = '*'
tokenRelative byte = '+'
tokenMatchini byte = '{'
tokenMatchend byte = '}'
)
type (
// TokenizerCore
// Struct type
// Implements -> Tokenizer
//
TokenizerCore struct {
TokenSep byte
TokenWildcard byte
TokenRelative byte
TokenMathcIni byte
TokenMatchEnd byte
MinLenToken int
MaxLenToken int
MinLenTopic int
MaxLenTopic int
MinTokens int
MaxTokens int
MatchBuilder mchs.Matchers
}
// TokenizerCoreFnc
// Function type
//
//
TokenizerCoreFnc func (tkz *TokenizerCore)
)
// NewTokenizerCore
// Function constructor -> TokenizerCore
//
//
func NewTokenizerCore(ops ...TokenizerCoreFnc)(*TokenizerCore){
tk := &TokenizerCore{
TokenSep : tokenSep,
TokenWildcard : tokenWildcard,
TokenRelative : tokenRelative,
TokenMathcIni : tokenMatchini,
TokenMatchEnd : tokenMatchend,
MinLenToken : tokenMinLen,
MaxLenToken : tokenMaxLen,
MinLenTopic : topicMinLen,
MaxLenTopic : topicMaxLen,
MinTokens : topicMinTokens,
MaxTokens : topicMaxTokens,
}
for _,o := range ops {
o(tk) }
if tk.MaxTokens > topicMaxTokens {
tk.MaxTokens = topicMaxTokens
}
if tk.MatchBuilder == nil {
tk.MatchBuilder = mchs.MatchersNoop{} }
return tk
}
// NewTopic
// Function member -> TokenizerCore
//
//
func (t TokenizerCore) NewTopic (tpc []byte, alw Kind) *Topic { return NewTopic(t,tpc,alw) }
// Tokenize
// Function member -> TokenizerCore
// Implements -> Tokenizer
//
//
func (t TokenizerCore) Tokenize(tpc []byte, alw Kind) (Tokens, Kind){
ln := len(tpc)
if ln < t.MinLenTopic || ln > t.MaxLenTopic {
return []Token{*(NewInvalidToken(G.ErrInvalidTopicLen,tpc)) }, TokenKindInvalid
}
tl := [topicMaxTokens]Token{}
tt := TokenKindNone
m,c,x := 0,0,0
for i:=0; i<ln; i++ {
switch tpc[i] {
case t.TokenMathcIni : m++
case t.TokenMatchEnd : m--
case t.TokenSep:
if m != 0 {
continue }
if c >= t.MaxTokens {
tl[c] = *(NewInvalidToken(G.ErrInvalidTopicLen,tpc[x:]))
return tl[:c+1], tt | TokenKindInvalid
}
tl[c] = t.NewToken(tpc[x:i])
tk := tl[c].Kind()
if tk == TokenKindRelative {
tl[c]= NewInvalidToken(G.ErrInvalidToken,tpc[x:i])
} else if tk & alw == 0 {
tt |= TokenKindInvalid
}
tt |= tl[c].Kind()
x = i + 1
c++
}
}
if m != 0 {
tl[c] = *(NewInvalidToken(G.ErrInvalidTopic,tpc[x:]))
} else {
tl[c] = t.NewToken(tpc[x:])
}
return tl[:c+1], tt | tl[c].Kind()
}
// Split
// Function member -> TokenizerCore
//
//
func (t TokenizerCore) Split (tpc []byte, alw Kind)([][]byte, Kind){
var ms, ps,x int
var tk, pk Kind
ln := len(tpc)
ar := [topicMaxTokens][]byte{}
for i:=0; i< ln; i++ {
switch tpc[i] {
case t.TokenMathcIni : ms++
case t.TokenMatchEnd : ms--
case t.TokenSep:
if ms == 0 {
ar[ps] = tpc[x:i]
if pk = t.Kind(ar[ps]); pk & alw == 0 {
return nil, TokenKindInvalid
}
tk|= pk
x = i + 1
ps++
}
}
}
ar[ps] = tpc[x:]
if pk = t.Kind(ar[ps]); pk& alw == 0 {
return nil, TokenKindInvalid
}
tk |= pk
return ar[:ps+1],tk
}
// NewToken
// Function member -> TokenizerCore
//
//
func (t TokenizerCore) NewToken(Token []byte)(Token){
ln := len(Token)
if ln < t.MinLenToken || ln > t.MaxLenToken {
return InvalidToken{ error: nil, source: Token } }
if ln == 1 {
switch Token[0] {
case t.TokenWildcard : return WildcardToken{}
case t.TokenRelative : return RelativeToken{}
case t.TokenMathcIni,
t.TokenMatchEnd : return *(NewInvalidToken(G.ErrInvalidTopicLen,Token)) }
}
if Token[0] != t.TokenMathcIni {
return LiteralToken(Token) }
if Token[ln-1] == t.TokenMatchEnd && ln > t.MinLenToken+ 2 {
m,e := t.MatchBuilder.Build(Token)
if e == nil {
return *(NewMatcherToken(m.Match,Token)) }
return *(NewInvalidToken(e,Token))
}
return *(NewInvalidToken(mchs.Errs.ErrInvalidMatcher,Token))
}
// Kind
// Function member -> TokenizerCore
//
func (t TokenizerCore) Kind (Token []byte)(Kind){
ln := len(Token)
if ln < t.MinLenToken || ln > t.MaxLenToken {
return TokenKindInvalid
}
if ln == 1 {
switch Token[0] {
case t.TokenWildcard : return TokenWildcard
case t.TokenRelative : return TokenRelative
case t.TokenMathcIni,
t.TokenMatchEnd : return TokenKindInvalid
}
}
if Token[0] == t.TokenMathcIni {
if Token[ln-1] == t.TokenMatchEnd {
return TokenMatcher }
return TokenKindInvalid
}
return TokenLiteral
}

@ -0,0 +1,34 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name err_token.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 tokens
import "errs"
type (
ErrTokens struct { errs.ErrCode }
)

@ -0,0 +1,77 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name kind.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 tokens
const (
// Kind enum values
//
TokenKindNone Kind = 0
TokenKindLiteral Kind = 1
TokenKindWildcard Kind = 2
TokenKindMatcher Kind = 4
TokenKindRelative Kind = 8
TokenKindInvalid Kind = 128
//
// Kind compund values
//
TokenKindAny = TokenKindRelative | TokenKindWildcard
TokenKindTopic = TokenKindLiteral | TokenKindMatcher | TokenKindAny
TokenKindMatchable= TokenKindLiteral | TokenKindMatcher
TokenKindAll = TokenKindInvalid | TokenKindTopic
)
type (
Kind uint8
)
func (t Kind) HasLiteral () bool {
return t &TokenKindLiteral != 0 }
func (t Kind) HasRelative () bool {
return t &TokenKindRelative != 0 }
func (t Kind) HasWildcard () bool {
return t &TokenKindWildcard != 0 }
func (t Kind) HasMatcher () bool {
return t &TokenKindMatcher != 0 }
func (t Kind) HasInvalid () bool {
return t &TokenKindInvalid != 0 }
func (t Kind) HasAny () bool {
return t &TokenKindAny != 0 }
func (t Kind) HasMatchable() bool {
return t &TokenKindMatchable != 0 }

@ -0,0 +1,36 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name token.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 tokens
type (
Token interface {
Kind () Kind
Source() []byte
Match (val []byte) bool
}
)

@ -0,0 +1,49 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name token_invalid.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 tokens
type (
InvalidToken struct {
error
source []byte
}
)
func NewInvalidToken(err error, src []byte) *InvalidToken {
return &InvalidToken{ error : err, source: src }}
func (_ InvalidToken) Kind () Kind {
return TokenKindInvalid
}
func (_ InvalidToken) Match (_ []byte) bool {
return false }
func (t InvalidToken) Source()[]byte {
return t.source }

@ -0,0 +1,46 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name token_literal.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 tokens
import "bytes"
type (
// LiteralToken
// Implements -> Token
LiteralToken []byte
)
func (_ LiteralToken) Kind () Kind {
return TokenKindLiteral
}
func (t LiteralToken) Match (val []byte) bool {
return bytes.Equal(t, val) }
func (t LiteralToken) Source()[]byte {
return t }

@ -0,0 +1,50 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name token_matcher.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 tokens
type (
MatcherToken struct {
source []byte
matchFn MatchFnc
}
MatchFnc func (target []byte) bool
)
func NewMatcherToken (mfn MatchFnc, src []byte) *MatcherToken {
return &MatcherToken{ matchFn: mfn, source: src } }
func (_ MatcherToken) Kind () Kind {
return TokenKindMatcher
}
func (t MatcherToken) Match(val []byte) bool {
return t.matchFn(val) }
func (t MatcherToken) Source()[]byte {
return t.source }

@ -0,0 +1,43 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name token_relative.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 tokens
type (
RelativeToken struct {}
)
func (_ RelativeToken) Kind () Kind {
return TokenKindRelative
}
func (_ RelativeToken) Match(_ []byte) bool {
return true }
func (_ RelativeToken) Source()[]byte {
return nil }

@ -0,0 +1,41 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name token_wildcard.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 tokens
type (
WildcardToken struct {}
)
func (_ WildcardToken) Kind () Kind {
return TokenKindWildcard
}
func (_ WildcardToken) Match(_ []byte) bool {
return true }
func (_ WildcardToken) Source()[]byte {
return nil }

@ -0,0 +1,41 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name tokenizer.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 tokens
type (
Tokenizer interface {
NewToken (Token []byte) Token
TokenKind (Token []byte) Kind
Split (subject []byte, allow Kind) ([][]byte , Kind)
Tokenize (topic []byte, allow Kind) (Tokens, Kind)
}
)

@ -0,0 +1,32 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name tokens.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 tokens
type (
Tokens []Token
)

@ -0,0 +1,64 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name topic.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 tokens
type (
// Topic
// Struct type
//
//
Topic struct {
kind Kind
source []byte
tokens Tokens
}
// TopicList
// Slice type
// Implements -> sort.Interface
//
//
TopicList []Topic
)
// NewTopic
// Function constructor -> Topic
//
//
func NewTopic (tkz Tokenizer, tpc []byte, alw Kind)(*Topic){
tp := &Topic{
source : tpc }
tp.tokens,
tp.kind = tkz.Tokenize(tpc,alw)
return tp
}

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

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

@ -0,0 +1,70 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name writer.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 base32
import (
"bins/mems"
"encoding/base32"
)
func Write(b *mems.ABuffer, value, null, empty []byte, isQuoted bool, quote byte) (er error) {
if value == nil {
_,_ = b.Write(null)
return nil
}
if len(value) == 0 {
_,_ = b.Write(empty)
return nil
}
p := b.Len()
if isQuoted {
b.WriteByte(quote)
}
var t [64]byte
ln := base32.StdEncoding.EncodedLen(len(value))
if ln <= len(t) {
dst := t[:ln]
base32.StdEncoding.Encode(dst, value)
_,er = b.Write(dst)
} else if ln <= 1024 {
dst := make([]byte, ln)
base32.StdEncoding.Encode(dst, value)
_,er = b.Write(dst)
} else if er == nil {
ec := base32.NewEncoder(base32.StdEncoding, b)
_,_ = ec.Write(value)
return ec.Close()
}
if er == nil {
if isQuoted {
b.WriteByte(quote)
}
} else {
b.Truncate(p)
}
return er
}

@ -2,7 +2,7 @@
// Project active2 // Project active2
// Active Thing (activething.com) git.activething.com/go // Active Thing (activething.com) git.activething.com/go
// //
// File name writer_encoding.go // File name writer.go
// Created by DEV // Created by DEV
// Modified 23/04/2024 // Modified 23/04/2024
// //
@ -21,14 +21,16 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package bfers package base64
import ( import (
"encoding/base32" "bins/mems"
"encoding/base64" "encoding/base64"
) )
func (b *Buffer) WriteBase64(value, null, empty []byte, isQuoted bool, quote byte) (er error) {
func Write(b *mems.ABuffer, value, null, empty []byte, isQuoted bool, quote byte) (er error) {
if value == nil { if value == nil {
_,_ = b.Write(null) _,_ = b.Write(null)
return nil return nil
@ -72,45 +74,3 @@ func (b *Buffer) WriteBase64(value, null, empty []byte, isQuoted bool, quote byt
func (b *Buffer) WriteBase32(value, null, empty []byte, isQuoted bool, quote byte) (er error) {
if value == nil {
_,_ = b.Write(null)
return nil
}
if len(value) == 0 {
_,_ = b.Write(empty)
return nil
}
p := b.Len()
if isQuoted {
b.WriteByte(quote)
}
var t [64]byte
ln := base32.StdEncoding.EncodedLen(len(value))
if ln <= len(t) {
dst := t[:ln]
base32.StdEncoding.Encode(dst, value)
_,er = b.Write(dst)
} else if ln <= 1024 {
dst := make([]byte, ln)
base32.StdEncoding.Encode(dst, value)
_,er = b.Write(dst)
} else if er == nil {
ec := base32.NewEncoder(base32.StdEncoding, b)
_,_ = ec.Write(value)
return ec.Close()
}
if er == nil {
if isQuoted {
b.WriteByte(quote)
}
} else {
b.Truncate(p)
}
return er
}

@ -24,7 +24,9 @@
package cjson package cjson
import ( import (
"bins/bfers" "bins/mems"
"codecs/base32"
"codecs/base64"
"math" "math"
"strconv" "strconv"
"time" "time"
@ -32,7 +34,7 @@ import (
) )
func WriteString(b *bfers.Buffer, value string, escapeHTML bool ) { func WriteString(b *mems.ABuffer, value string, escapeHTML bool ) {
if len(value) == 0 { if len(value) == 0 {
b.Write2Byte('"', '"') b.Write2Byte('"', '"')
return return
@ -100,7 +102,7 @@ func WriteString(b *bfers.Buffer, value string, escapeHTML bool ) {
func WriteUint (b *bfers.Buffer, value uint64 , quoted bool) { func WriteUint (b *mems.ABuffer, value uint64 , quoted bool) {
if quoted { if quoted {
b.WriteByte('"') b.WriteByte('"')
} }
@ -115,7 +117,7 @@ func WriteUint (b *bfers.Buffer, value uint64 , quoted bool) {
} }
func WriteBool (b *bfers.Buffer, value bool , quoted bool) { func WriteBool (b *mems.ABuffer, value bool , quoted bool) {
if value { if value {
b.WOQ(quoted,'"', G.TrueValue) b.WOQ(quoted,'"', G.TrueValue)
} else { } else {
@ -124,7 +126,7 @@ func WriteBool (b *bfers.Buffer, value bool , quoted bool) {
} }
func WriteInt (b *bfers.Buffer, value int64 , quoted bool) { func WriteInt (b *mems.ABuffer, value int64 , quoted bool) {
if quoted { if quoted {
b.WriteByte('"') b.WriteByte('"')
} }
@ -139,7 +141,7 @@ func WriteInt (b *bfers.Buffer, value int64 , quoted bool) {
} }
func WriteFloat (b *bfers.Buffer, f float64, bits int, quoted bool) { func WriteFloat (b *mems.ABuffer, f float64, bits int, quoted bool) {
var t [64]byte var t [64]byte
if math.IsInf(f, 0) || math.IsNaN(f) { if math.IsInf(f, 0) || math.IsNaN(f) {
_,_ = b.Write(G.FloatNaN) _,_ = b.Write(G.FloatNaN)
@ -169,7 +171,7 @@ func WriteFloat (b *bfers.Buffer, f float64, bits int, quoted bool) {
} }
func WriteDate(b *bfers.Buffer, value time.Time, layout string, quote bool) { func WriteDate(b *mems.ABuffer, value time.Time, layout string, quote bool) {
if layout == "" { if layout == "" {
layout = time.RFC3339 layout = time.RFC3339
} }
@ -183,9 +185,9 @@ func WriteDate(b *bfers.Buffer, value time.Time, layout string, quote bool) {
} }
func WriteBase64(b *bfers.Buffer, value []byte) (er error) { func WriteBase64(b *mems.ABuffer, value []byte) (er error) {
return b.WriteBase64(value,G.NullValue,G.EmptyValue,true,'"') } return base64.Write(b,value,G.NullValue,G.EmptyValue,true,'"') }
func WriteBase32(b *bfers.Buffer, value []byte) (er error) { func WriteBase32(b *mems.ABuffer, value []byte) (er error) {
return b.WriteBase32(value,G.NullValue,G.EmptyValue,true,'"') } return base32.Write(b,value,G.NullValue,G.EmptyValue,true,'"') }

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

@ -21,7 +21,7 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package timers package cronus
import "errs" import "errs"
@ -29,24 +29,24 @@ var (
G = struct { G = struct {
ErrExpired Err ErrExpired ErrCronus
ErrTimeout Err ErrTimeout ErrCronus
ErrIntervalInvalid Err ErrIntervalInvalid ErrCronus
ErrNotStarted Err ErrNotStarted ErrCronus
ErrNotPaused Err ErrNotPaused ErrCronus
ErrAlreadyStarted Err ErrAlreadyStarted ErrCronus
ErrTransitionInvalid Err ErrTransitionInvalid ErrCronus
ErrTimerTaskInvalid Err ErrTimerTaskInvalid ErrCronus
} { } {
ErrExpired: Err{ errs.ErrCode("expired")}, ErrExpired: ErrCronus{errs.ErrCode("expired")},
ErrTimeout: Err{ errs.ErrCode("timeout")}, ErrTimeout: ErrCronus{errs.ErrCode("timeout")},
ErrIntervalInvalid: Err{ errs.ErrCode("interval_invalid")}, ErrIntervalInvalid: ErrCronus{errs.ErrCode("interval_invalid")},
ErrNotStarted: Err{ errs.ErrCode("not_started")}, ErrNotStarted: ErrCronus{errs.ErrCode("not_started")},
ErrNotPaused: Err{ errs.ErrCode("not_paused")}, ErrNotPaused: ErrCronus{errs.ErrCode("not_paused")},
ErrAlreadyStarted: Err{ errs.ErrCode("already_started")}, ErrAlreadyStarted: ErrCronus{errs.ErrCode("already_started")},
ErrTransitionInvalid: Err{ errs.ErrCode("transition_invalid")}, ErrTransitionInvalid: ErrCronus{errs.ErrCode("transition_invalid")},
ErrTimerTaskInvalid: Err{ errs.ErrCode("timer_task_invalid")}, ErrTimerTaskInvalid: ErrCronus{errs.ErrCode("timer_task_invalid")},
} }

@ -21,7 +21,7 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package timers package cronus
import ( import (
"sync/atomic" "sync/atomic"

@ -22,7 +22,7 @@
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package timers package cronus
import ( import (
"time" "time"

@ -21,12 +21,12 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package timers package cronus
import "errs" import "errs"
type ( type (
Err struct { errs.ErrCode } ErrCronus struct { errs.ErrCode }
) )

@ -21,7 +21,7 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package timers package cronus
import ( import (
"sync/atomic" "sync/atomic"

@ -21,7 +21,7 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package timers package cronus
const ( const (

@ -21,7 +21,7 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package timers package cronus
import ( import (
"time" "time"

@ -21,7 +21,7 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package timers package cronus
import ( import (
"context" "context"

@ -21,7 +21,7 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package timers package cronus
import ( import (
"context" "context"

@ -21,7 +21,7 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package timers package cronus
import ( import (
"container/heap" "container/heap"

@ -21,7 +21,7 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package timers package cronus
const ( const (

@ -22,7 +22,7 @@
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package timers package cronus
import ( import (
"time" "time"

@ -21,7 +21,7 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package timers package cronus
type ( type (

@ -28,8 +28,8 @@ import "errs"
var ( var (
G = struct { G = struct {
ErrNotImplemented Err ErrNotImplemented ErrCrypts
}{ }{
ErrNotImplemented: Err { errs.ErrCode("crypter-not-implemented")} , ErrNotImplemented: ErrCrypts{errs.ErrCode("crypter-not-implemented")} ,
} }
) )

@ -25,6 +25,6 @@ package crypts
import "errs" import "errs"
type Err struct { errs.ErrCode } type ErrCrypts struct { errs.ErrCode }

@ -21,7 +21,7 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package times package dates
import "errs" import "errs"
@ -36,10 +36,10 @@ var (
G = struct { G = struct {
ErrInvalidDateRange Err ErrInvalidDateRange ErrDates
}{ }{
ErrInvalidDateRange : Err{ errs.ErrCode ("invalid-date-range")}, ErrInvalidDateRange : ErrDates{errs.ErrCode ("invalid-date-range")},
} }
) )

@ -44,12 +44,12 @@ func NewBYear (year int) *BYear {
panic(G.ErrInvalidYear) panic(G.ErrInvalidYear)
} }
at := BYearAtt(BYearAttSet) at := BYearAtt(BYearAttSet)
if times.IsYearLeap(year) { if dates.IsYearLeap(year) {
at|=BYearAttLeap at|=BYearAttLeap
} }
return &BYear { return &BYear {
atts : at, atts : at,
first: byte(times.DayOfWeek(year,1,1)), first: byte(dates.DayOfWeek(year,1,1)),
year : byte(year-1900), year : byte(year-1900),
} }
} }

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

@ -21,7 +21,7 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package times package dates
type ( type (

@ -22,7 +22,7 @@
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package times package dates
import ( import (
"strconv" "strconv"

@ -21,13 +21,13 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package times package dates
import "errs" import "errs"
type ( type (
Err struct { errs.ErrCode } ErrDates struct { errs.ErrCode }
) )

@ -22,7 +22,7 @@
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package times package dates
import ( import (
"strconv" "strconv"

@ -28,8 +28,6 @@ import (
"errs/ftext" "errs/ftext"
"errs/stack" "errs/stack"
"fmt" "fmt"
"reflect"
"sync"
) )
const ( const (
@ -73,12 +71,15 @@ var (
Formatter : ftext.DefaultFormatter(), Formatter : ftext.DefaultFormatter(),
} }
/*
g = struct { g = struct {
mux sync.RWMutex mux sync.RWMutex
stackTraceRType reflect.Type stackTraceRType reflect.Type
}{ }{
stackTraceRType : reflect.TypeOf(stack.Trace(nil)), stackTraceRType : reflect.TypeOf(stack.Trace(nil)),
} }
*/
) )

@ -21,7 +21,7 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package collr package collects
import ( import (
"reflect" "reflect"

@ -21,7 +21,7 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package collr package collects
type ( type (

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

@ -21,7 +21,7 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package collr package collects
import ( import (
"errors" "errors"

@ -21,7 +21,7 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package collr package collects
type ( type (

@ -21,7 +21,7 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package collr package collects
type ( type (

@ -21,7 +21,7 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package collr package collects
type ( type (

@ -21,7 +21,7 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package collr package collects
type ( type (

@ -21,7 +21,7 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package collr package collects
const ( const (

@ -21,7 +21,7 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package collr package collects
import ( import (
"sort" "sort"

@ -23,7 +23,7 @@
package errs package errs
import "errs/collr" import "errs/collects"
type ( type (
@ -67,4 +67,4 @@ func (e ErrCause) String () string {
return string(G.Formatter.FormatError(e)) } return string(G.Formatter.FormatError(e)) }
func (_ ErrCause) Collect(_ collr.Collector) {} func (_ ErrCause) Collect(_ collects.Collector) {}

@ -23,7 +23,7 @@
package errs package errs
import "errs/collr" import "errs/collects"
type ( type (
@ -69,6 +69,6 @@ func (e ErrCode) String () string {
return string(G.Formatter.FormatError(e)) } return string(G.Formatter.FormatError(e)) }
func (e ErrCode) Collect (collector collr.Collector) { func (e ErrCode) Collect (collector collects.Collector) {
collector.AddFieldString(fieldNameCode,string(e)) collector.AddFieldString(fieldNameCode,string(e))
} }

@ -24,7 +24,7 @@
package errs package errs
import ( import (
"errs/collr" "errs/collects"
"fmt" "fmt"
"time" "time"
) )
@ -103,7 +103,7 @@ func (e ErrInfo) String () string {
func (e ErrInfo) Collect (collector collr.Collector) { func (e ErrInfo) Collect (collector collects.Collector) {
collector.AddFieldString(fieldNameMessage,e.message) collector.AddFieldString(fieldNameMessage,e.message)
collector.AddFieldString(fieldNameInfo,e.info) collector.AddFieldString(fieldNameInfo,e.info)
collector.AddFieldDate (fieldNameDate,e.date) collector.AddFieldDate (fieldNameDate,e.date)

@ -23,7 +23,7 @@
package errs package errs
import "errs/collr" import "errs/collects"
type ( type (
@ -71,6 +71,6 @@ func (e ErrMulti) String () string {
func (_ ErrMulti) Collect (collector collr.Collector) { func (_ ErrMulti) Collect (collector collects.Collector) {
collector.AddFieldString(fieldNameCode,CodeMultiError) } collector.AddFieldString(fieldNameCode,CodeMultiError) }

@ -23,7 +23,7 @@
package errs package errs
import "errs/collr" import "errs/collects"
type ( type (
@ -68,5 +68,5 @@ func (e ErrPanic) String () string {
func (_ ErrPanic) Collect (collector collr.Collector) { func (_ ErrPanic) Collect (collector collects.Collector) {
collector.AddFieldString(fieldNameCode,CodePanicError) } collector.AddFieldString(fieldNameCode,CodePanicError) }

@ -24,7 +24,7 @@
package errs package errs
import ( import (
"errs/collr" "errs/collects"
"fmt" "fmt"
) )
@ -85,7 +85,7 @@ func (e ErrParam) String () string {
return string(G.Formatter.FormatError(e)) } return string(G.Formatter.FormatError(e)) }
func (e ErrParam) Collect(collector collr.Collector) { func (e ErrParam) Collect(collector collects.Collector) {
collector.AddFieldString(fieldNameCode,e.code) collector.AddFieldString(fieldNameCode,e.code)
if len(e.param) > 0 { if len(e.param) > 0 {
collector.AddFieldString(fieldNameParam,e.param) collector.AddFieldString(fieldNameParam,e.param)

@ -24,7 +24,7 @@
package errs package errs
import ( import (
"errs/collr" "errs/collects"
"errs/stack" "errs/stack"
) )
@ -83,4 +83,4 @@ func (e ErrTrace) String () string {
func (_ ErrTrace) Collect (_ collr.Collector) {} func (_ ErrTrace) Collect (_ collects.Collector) {}

@ -24,10 +24,10 @@
package fjson package fjson
import ( import (
"bins/bfers" "bins/mems"
"cdcs/cjson" "codecs/cjson"
"encoding/json" "encoding/json"
"errs/collr" "errs/collects"
"fmt" "fmt"
"strings" "strings"
) )
@ -37,7 +37,7 @@ type (
jsonBuilder struct { jsonBuilder struct {
f *JSONFormatter f *JSONFormatter
b *bfers.Buffer b *mems.ABuffer
encoder *json.Encoder encoder *json.Encoder
sep string sep string
pretty bool pretty bool
@ -49,22 +49,22 @@ type (
func newJsonBuilder (f *JSONFormatter) *jsonBuilder { func newJsonBuilder (f *JSONFormatter) *jsonBuilder {
sep := ":" sep := ":"
if f.UseSpace() && f.ShowPretty() { if f.HasUseSpace() && f.HasShowPretty() {
sep = ": " sep = ": "
} }
return &jsonBuilder{ return &jsonBuilder{
f : f, f : f,
b : bfers.NewBuffer(), b : mems.NewABuffer(),
pretty : f.ShowPretty(), pretty : f.HasShowPretty(),
sep : sep, sep : sep,
} }
} }
func (b *jsonBuilder) format (err error) { func (b *jsonBuilder) format (err error) {
cl := collr.NewErrorCollection(err) cl := collects.NewErrorCollection(err)
cl.Collect(b.f.AddFields(),b.f.AddCauses(),b.f.AddTrace()) cl.Collect(b.f.HasAddFields(),b.f.HasAddCauses(),b.f.HasAddTrace())
if cl.Invalid != nil { if cl.Invalid != nil {
b.writeFormatError(cl.Invalid) b.writeFormatError(cl.Invalid)
@ -75,7 +75,7 @@ func (b *jsonBuilder) format (err error) {
} }
func (b *jsonBuilder) write (coll *collr.ErrorCollection, cont bool, level int) { func (b *jsonBuilder) write (coll *collects.ErrorCollection, cont bool, level int) {
if b.invalid != nil { if b.invalid != nil {
return return
} }
@ -120,10 +120,10 @@ func (b *jsonBuilder) write (coll *collr.ErrorCollection, cont bool, level int)
if b.pretty { if b.pretty {
b.b.WriteByte('\n') b.b.WriteByte('\n')
} }
b.writeField(collr.FieldNameError,coll.ErrStr, indObj,true,false, false) b.writeField(collects.FieldNameError,coll.ErrStr, indObj,true,false, false)
if b.f.AddTypes() { if b.f.HasAddTypes() {
types := coll.Types types := coll.Types
b.b.WriteByte(',') b.b.WriteByte(',')
@ -132,10 +132,10 @@ func (b *jsonBuilder) write (coll *collr.ErrorCollection, cont bool, level int)
} }
if len(types) == 1 { if len(types) == 1 {
b.writeField(collr.FieldNameType, types[0].String(), indObj, true, false,false) b.writeField(collects.FieldNameType, types[0].String(), indObj, true, false,false)
} else { } else {
b.writeOpen(collr.FieldNameTypes, indObj, '[', b.pretty) b.writeOpen(collects.FieldNameTypes, indObj, '[', b.pretty)
for i, t := range coll.TypesStr { for i, t := range coll.TypesStr {
if b.pretty { if b.pretty {
b.b.WriteString(ind2Obj) b.b.WriteString(ind2Obj)
@ -165,7 +165,7 @@ func (b *jsonBuilder) write (coll *collr.ErrorCollection, cont bool, level int)
} }
coll.Fields.Sort() coll.Fields.Sort()
b.writeOpen(collr.FieldNameFields, indObj, '{', b.pretty) b.writeOpen(collects.FieldNameFields, indObj, '{', b.pretty)
var n = 0 var n = 0
for _, h := range heads { for _, h := range heads {
@ -201,10 +201,10 @@ func (b *jsonBuilder) write (coll *collr.ErrorCollection, cont bool, level int)
} }
if len(causes) == 1 { if len(causes) == 1 {
b.writeOpen(collr.FieldNameCause, indObj, 0, false) b.writeOpen(collects.FieldNameCause, indObj, 0, false)
b.write(&causes[0], true,level+1) b.write(&causes[0], true,level+1)
} else if len(causes) > 1 { } else if len(causes) > 1 {
b.writeOpen(collr.FieldNameCauses, indObj, '[', b.pretty) b.writeOpen(collects.FieldNameCauses, indObj, '[', b.pretty)
for i, ce := range causes { for i, ce := range causes {
if i > 0 { if i > 0 {
b.b.WriteByte(',') b.b.WriteByte(',')
@ -229,7 +229,7 @@ func (b *jsonBuilder) write (coll *collr.ErrorCollection, cont bool, level int)
if b.pretty { if b.pretty {
b.b.WriteByte('\n') b.b.WriteByte('\n')
} }
b.writeFieldName(collr.FieldNameTrace,indObj) b.writeFieldName(collects.FieldNameTrace,indObj)
if b.encoder == nil { if b.encoder == nil {
b.encoder = json.NewEncoder(b.b) b.encoder = json.NewEncoder(b.b)
@ -296,61 +296,61 @@ func (b *jsonBuilder) writeField (name, value, indent string, quote, coma, nl bo
} }
func (b *jsonBuilder) writeFieldValue (fields collr.Fields, field *collr.FieldHead, level int) bool { func (b *jsonBuilder) writeFieldValue (fields collects.Fields, field *collects.FieldHead, level int) bool {
switch field.Kind { switch field.Kind {
case collr.FieldKindFloat: case collects.FieldKindFloat:
n := fields.GetFieldValueFloat(field) n := fields.GetFieldValueFloat(field)
if n == 0 && b.f.IgnoreDefaults() { if n == 0 && b.f.HasIgnoreDefaults() {
return false return false
} }
cjson.WriteFloat(b.b,n,64,b.f.UseQuote()) cjson.WriteFloat(b.b,n,64,b.f.HasUseQuote())
return true return true
case collr.FieldKindInt: case collects.FieldKindInt:
n := fields.GetFieldValueInt(field) n := fields.GetFieldValueInt(field)
if n == 0 && b.f.IgnoreDefaults() { if n == 0 && b.f.HasIgnoreDefaults() {
return false return false
} }
cjson.WriteInt(b.b,int64(n),b.f.UseQuote()) cjson.WriteInt(b.b,int64(n),b.f.HasUseQuote())
return true return true
case collr.FieldKindString: case collects.FieldKindString:
s := fields.GetFieldValueString(field) s := fields.GetFieldValueString(field)
if len(s) == 0 && b.f.IgnoreDefaults() { if len(s) == 0 && b.f.HasIgnoreDefaults() {
return false return false
} }
cjson.WriteString(b.b,s,b.f.EscapeHTML()) cjson.WriteString(b.b,s,b.f.HasEscapeHTML())
return true return true
case collr.FieldKindTime: case collects.FieldKindTime:
d := fields.GetFieldValueDate(field) d := fields.GetFieldValueDate(field)
if d.IsZero() && b.f.IgnoreDefaults(){ if d.IsZero() && b.f.HasIgnoreDefaults(){
return false return false
} }
cjson.WriteDate(b.b,d,b.f.layout.TimeLayout,true) cjson.WriteDate(b.b,d,b.f.layout.TimeLayout,true)
return true return true
case collr.FieldKindDate: case collects.FieldKindDate:
d := fields.GetFieldValueDate(field) d := fields.GetFieldValueDate(field)
if d.IsZero() && b.f.IgnoreDefaults(){ if d.IsZero() && b.f.HasIgnoreDefaults(){
return false return false
} }
cjson.WriteDate(b.b,d,b.f.layout.DateLayout,true) cjson.WriteDate(b.b,d,b.f.layout.DateLayout,true)
return true return true
case collr.FieldKindBool: case collects.FieldKindBool:
t := fields.GetFieldValueBool(field) t := fields.GetFieldValueBool(field)
if !t && b.f.IgnoreDefaults() { if !t && b.f.HasIgnoreDefaults() {
return false return false
} }
cjson.WriteBool(b.b,t,b.f.UseQuote()) cjson.WriteBool(b.b,t,b.f.HasUseQuote())
return true return true
default: default:
a := fields.GetFieldValueAny(field) a := fields.GetFieldValueAny(field)
if a == nil { if a == nil {
if b.f.IgnoreDefaults() { if b.f.HasIgnoreDefaults() {
return false return false
} }
b.b.WOQ(true,'"',cjson.G.NullValue) b.b.WOQ(true,'"',cjson.G.NullValue)
@ -359,7 +359,7 @@ func (b *jsonBuilder) writeFieldValue (fields collr.Fields, field *collr.FieldHe
if b.encoder == nil { if b.encoder == nil {
b.encoder = json.NewEncoder(b.b) b.encoder = json.NewEncoder(b.b)
b.encoder.SetEscapeHTML(b.f.EscapeHTML()) b.encoder.SetEscapeHTML(b.f.HasEscapeHTML())
} }
if b.pretty { if b.pretty {
@ -377,7 +377,7 @@ func (b *jsonBuilder) writeFieldValue (fields collr.Fields, field *collr.FieldHe
b.b.Reset() b.b.Reset()
b.b.WriteByte('{') b.b.WriteByte('{')
b.writeFieldName("json-formatter-error","") b.writeFieldName("json-formatter-error","")
cjson.WriteString(b.b,err.Error(),b.f.EscapeHTML()) cjson.WriteString(b.b,err.Error(),b.f.HasEscapeHTML())
b.b.WriteByte('}') b.b.WriteByte('}')
} }

@ -69,5 +69,7 @@ func WithLayout (config LayoutFnc) JSONFormatterFnc {
func WithOptions (set, unset Option) JSONFormatterFnc { func WithOptions (set, unset Option) JSONFormatterFnc {
return func(f *JSONFormatter) { return func(f *JSONFormatter) {
f.Option |= set f.Option = f.Option.Add(set)
f.Option &^= unset } } f.Option = f.Option.Del(unset)
}
}

@ -46,33 +46,41 @@ type (
Option uint16 Option uint16
) )
func (o Option) AddTypes () bool { func (o Option) Add (opt Option) Option {
return o | opt
}
func (o Option) Del (opt Option) Option {
return o &^ opt }
func (o Option) HasAddTypes() bool {
return o&AddTypes != 0 } return o&AddTypes != 0 }
func (o Option) AddFields () bool { func (o Option) HasAddFields() bool {
return o&AddFields != 0 } return o&AddFields != 0 }
func (o Option) AddCauses () bool { func (o Option) HasAddCauses() bool {
return o&AddCauses != 0 } return o&AddCauses != 0 }
func (o Option) AddTrace () bool { func (o Option) HasAddTrace() bool {
return o&AddTrace != 0 } return o&AddTrace != 0 }
func (o Option) ShowPretty () bool { func (o Option) HasShowPretty() bool {
return o&ShowPretty != 0 } return o&ShowPretty != 0 }
func (o Option) UseSpace () bool { func (o Option) HasUseSpace() bool {
return o&UseSpace != 0 } return o&UseSpace != 0 }
func (o Option) UseQuote () bool { func (o Option) HasUseQuote() bool {
return o&UseQuote != 0 } return o&UseQuote != 0 }
func (o Option) SortFields () bool { func (o Option) HasSortFields() bool {
return o&SortFields != 0 } return o&SortFields != 0 }
func (o Option) IgnoreDefaults() bool { func (o Option) HasIgnoreDefaults() bool {
return o&IgnoreDefaults != 0 } return o&IgnoreDefaults != 0 }
func (o Option) EscapeHTML() bool { func (o Option) HasEscapeHTML() bool {
return o&EscapeHTML != 0 } return o&EscapeHTML != 0 }

@ -25,12 +25,12 @@ package ftext
import ( import (
"ansi" "ansi"
"btypes/astrings"
"errs/stack" "errs/stack"
"fmt" "fmt"
"reflect" "reflect"
"strings" "strings"
"sync" "sync"
"tbase/astrings"
) )

@ -44,31 +44,36 @@ type (
Option uint16 Option uint16
) )
func (o Option) Add (opt Option) Option {
return o | opt
}
func (o Option) Del (opt Option) Option {
return o &^ opt }
func (o Option) SetDefaults () Option { func (o Option) SetDefaults () Option {
return optionsDefault return optionsDefault }
}
func (o Option) AddTypes() bool { func (o Option) HasAddTypes() bool {
return o&AddTypes !=0 } return o&AddTypes !=0 }
func (o Option) AddFields() bool { func (o Option) HasAddFields() bool {
return o&AddFields !=0 } return o&AddFields !=0 }
func (o Option) AddCauses() bool { func (o Option) HasAddCauses() bool {
return o&AddCauses !=0 } return o&AddCauses !=0 }
func (o Option) AddTrace() bool { func (o Option) HasAddTrace() bool {
return o&AddTrace !=0 } return o&AddTrace !=0 }
func (o Option) IgnoreEmpty() bool { func (o Option) HasIgnoreEmpty() bool {
return o&IgnoreEmpty !=0 } return o&IgnoreEmpty !=0 }
func (o Option) ShowAnsi () bool { func (o Option) HasShowAnsi() bool {
return o&ShowAnsi !=0 } return o&ShowAnsi !=0 }
func (o Option) UseIndent() bool { func (o Option) HasUseIndent() bool {
return o&UseIndent !=0 } return o&UseIndent !=0 }

@ -25,8 +25,8 @@ package ftext
import ( import (
"ansi" "ansi"
"bins/bfers" "bins/mems"
"errs/collr" "errs/collects"
"fmt" "fmt"
"strings" "strings"
) )
@ -35,10 +35,10 @@ type (
TextBuilder struct { TextBuilder struct {
f *TextFormatter f *TextFormatter
b *bfers.Buffer b *mems.ABuffer
useAux bool useAux bool
auxB *bfers.Buffer auxB *mems.ABuffer
level int level int
ansiC ansi.Code ansiC ansi.Code
@ -53,12 +53,12 @@ type (
func newTextBuilder(formatter *TextFormatter) *TextBuilder { func newTextBuilder(formatter *TextFormatter) *TextBuilder {
b := &TextBuilder{ b := &TextBuilder{
f : formatter, f : formatter,
b : bfers.NewBuffer(), b : mems.NewABuffer(),
useAux: len(formatter.valueTrans) > 0, useAux: len(formatter.valueTrans) > 0,
ansiC : formatter.layout.AnsiC, ansiC : formatter.layout.AnsiC,
} }
if b.useAux { if b.useAux {
b.auxB = bfers.NewBuffer() b.auxB = mems.NewABuffer()
} else { } else {
b.auxB = b.b b.auxB = b.b
} }
@ -73,7 +73,7 @@ func (b *TextBuilder) AddText (text string) {
b.b.WriteString(text) } b.b.WriteString(text) }
func (b *TextBuilder) AddTextAnsi (ansiC ansi.Code, text string) { func (b *TextBuilder) AddTextAnsi (ansiC ansi.Code, text string) {
if b.f.ShowAnsi() { if b.f.HasShowAnsi() {
if ansiC == 0 { if ansiC == 0 {
ansiC = b.ansiC ansiC = b.ansiC
} }
@ -95,15 +95,15 @@ func (b *TextBuilder) SetAnsi(ansiC ansi.Code) {
func (b *TextBuilder) format (err error) { func (b *TextBuilder) format (err error) {
c := collr.NewErrorCollection(err) c := collects.NewErrorCollection(err)
if c.Collect(b.f.AddFields(), b.f.AddCauses(), b.f.AddTrace()); c.Invalid != nil { if c.Collect(b.f.HasAddFields(), b.f.HasAddCauses(), b.f.HasAddTrace()); c.Invalid != nil {
//b.writeFormatError(cl.Invalid) //b.writeFormatError(cl.Invalid)
return return
} }
b.write(c, 0) b.write(c, 0)
} }
func (b *TextBuilder) write (c *collr.ErrorCollection, level int) { func (b *TextBuilder) write (c *collects.ErrorCollection, level int) {
if b.invalid != nil { if b.invalid != nil {
return return
} }
@ -131,17 +131,17 @@ func (b *TextBuilder) write (c *collr.ErrorCollection, level int) {
}(b,&d, c.Err) }(b,&d, c.Err)
f.sections.Head.begin(b) f.sections.Head.begin(b)
b.writeFieldNameValue(collr.FieldNameError, c.ErrStr, ind) b.writeFieldNameValue(collects.FieldNameError, c.ErrStr, ind)
if f.AddTypes() { if f.HasAddTypes() {
if len(c.TypesStr) == 1 { if len(c.TypesStr) == 1 {
b.writeFieldNameValue(collr.FieldNameType, c.TypesStr[0], ind) b.writeFieldNameValue(collects.FieldNameType, c.TypesStr[0], ind)
} else { } else {
b.writeFieldNameValue(collr.FieldNameTypes, strings.Join(c.TypesStr, ","), ind) b.writeFieldNameValue(collects.FieldNameTypes, strings.Join(c.TypesStr, ","), ind)
} }
} }
f.sections.Head.end(b) f.sections.Head.end(b)
if f.AddFields() && c.Fields.Len() > 0 { if f.HasAddFields() && c.Fields.Len() > 0 {
f.sections.Fields.begin(b) f.sections.Fields.begin(b)
heads := c.Fields.GetHeads() heads := c.Fields.GetHeads()
for _,fl := range heads { for _,fl := range heads {
@ -217,7 +217,7 @@ func (b *TextBuilder) writeFieldEnd () {
func (b *TextBuilder) writeFieldNameValue(name string, value string, indent string) { func (b *TextBuilder) writeFieldNameValue(name string, value string, indent string) {
p:= b.b.Len() p:= b.b.Len()
b.writeFieldBegin(name,indent) b.writeFieldBegin(name,indent)
if b.f.IgnoreEmpty() && len(value) == 0 { if b.f.HasIgnoreEmpty() && len(value) == 0 {
b.b.Truncate(p) b.b.Truncate(p)
return return
} }
@ -226,7 +226,7 @@ func (b *TextBuilder) writeFieldNameValue(name string, value string, indent stri
} }
func (b *TextBuilder) writeField (fields collr.Fields, field *collr.FieldHead, indent string) { func (b *TextBuilder) writeField (fields collects.Fields, field *collects.FieldHead, indent string) {
p := b.b.Len() p := b.b.Len()
b.writeFieldBegin(field.Name,indent) b.writeFieldBegin(field.Name,indent)
if !b.writeFieldValue(fields,field) { if !b.writeFieldValue(fields,field) {
@ -237,41 +237,41 @@ func (b *TextBuilder) writeField (fields collr.Fields, field *collr.FieldHead, i
} }
func (b *TextBuilder) writeFieldValue (fields collr.Fields, field *collr.FieldHead) bool { func (b *TextBuilder) writeFieldValue (fields collects.Fields, field *collects.FieldHead) bool {
switch field.Kind { switch field.Kind {
case collr.FieldKindFloat: case collects.FieldKindFloat:
b.auxB.WriteFloatStr(fields.GetFieldValueFloat(field),'f',-1) b.auxB.WriteFloatStr(fields.GetFieldValueFloat(field),'f',-1)
case collr.FieldKindInt: case collects.FieldKindInt:
b.auxB.WriteIntStr(int64(fields.GetFieldValueInt(field)),10) b.auxB.WriteIntStr(int64(fields.GetFieldValueInt(field)),10)
case collr.FieldKindString: case collects.FieldKindString:
s := fields.GetFieldValueString(field) s := fields.GetFieldValueString(field)
if b.f.IgnoreEmpty() && len(s) == 0 { if b.f.HasIgnoreEmpty() && len(s) == 0 {
return false return false
} }
b.auxB.WriteString(fields.GetFieldValueString(field)) b.auxB.WriteString(fields.GetFieldValueString(field))
case collr.FieldKindTime: case collects.FieldKindTime:
b.auxB.WriteDateStr(fields.GetFieldValueDate(field), b.f.layout.TimeLayout) b.auxB.WriteDateStr(fields.GetFieldValueDate(field), b.f.layout.TimeLayout)
case collr.FieldKindDate: case collects.FieldKindDate:
b.auxB.WriteDateStr(fields.GetFieldValueDate(field), b.f.layout.DateLayout) b.auxB.WriteDateStr(fields.GetFieldValueDate(field), b.f.layout.DateLayout)
case collr.FieldKindBool: case collects.FieldKindBool:
b.auxB.WriteBoolStr(fields.GetFieldValueBool(field)) b.auxB.WriteBoolStr(fields.GetFieldValueBool(field))
default: default:
a := fields.GetFieldValueAny(field) a := fields.GetFieldValueAny(field)
if a == nil { if a == nil {
if b.f.IgnoreEmpty() { if b.f.HasIgnoreEmpty() {
return false return false
} }
b.auxB.WOQ(false,'"', g.nullValue) b.auxB.WOQ(false,'"', g.nullValue)
} else { } else {
s := fmt.Sprintf("%#v",a) s := fmt.Sprintf("%#v",a)
if b.f.IgnoreEmpty() && len(s) == 0 { if b.f.HasIgnoreEmpty() && len(s) == 0 {
return false return false
} }
b.auxB.WriteString(s) b.auxB.WriteString(s)

@ -24,8 +24,8 @@
package ftext package ftext
import ( import (
"btypes/astrings"
"errs/stack" "errs/stack"
"tbase/astrings"
) )
type ( type (
@ -102,8 +102,8 @@ func WithErrorFallbacks (format, cause, trace ErrorFallbackFnc) TextFormatterFnc
func WithOptions (set, unset Option) TextFormatterFnc { func WithOptions (set, unset Option) TextFormatterFnc {
return func(f *TextFormatter) { return func(f *TextFormatter) {
f.Option |= set f.Option = f.Option.Add(set)
f.Option &^= unset } } f.Option = f.Option.Del(unset) } }
func WithNameTransformers(transformer ...astrings.Transformer) TextFormatterFnc { func WithNameTransformers(transformer ...astrings.Transformer) TextFormatterFnc {

@ -21,7 +21,7 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package bfers package mems
import ( import (
"bins/chars" "bins/chars"
@ -31,17 +31,13 @@ import (
"unicode/utf8" "unicode/utf8"
) )
const (
maxInt = int(^uint(0) >> 1)
MinRead = 512
)
type ( type (
Buffer struct { ABuffer struct {
data []byte data []byte
off int off int
ini [64]byte ini [64]byte
@ -50,27 +46,27 @@ type (
) )
func NewBuffer() *Buffer { func NewABuffer() *ABuffer {
return &Buffer{} } return &ABuffer{} }
func (b *Buffer) Len() int { func (b *ABuffer) Len() int {
return len(b.data) - b.off } return len(b.data) - b.off }
func (b *Buffer) Cap() int { func (b *ABuffer) Cap() int {
return cap(b.data) } return cap(b.data) }
func (b *Buffer) isEmpty() bool { func (b *ABuffer) isEmpty() bool {
return len(b.data) <= b.off } return len(b.data) <= b.off }
func (b *Buffer) Bytes() []byte { func (b *ABuffer) Bytes() []byte {
return b.data[b.off:] } return b.data[b.off:] }
func (b *Buffer) String() string { func (b *ABuffer) String() string {
if b == nil { if b == nil {
return "<nil>" return "<nil>"
} }
@ -78,14 +74,14 @@ func (b *Buffer) String() string {
} }
func (b *Buffer) Reset() { func (b *ABuffer) Reset() {
b.data = b.data[:0] b.data = b.data[:0]
b.off = 0 b.off = 0
b.lastOp = opInvalid b.lastOp = opInvalid
} }
func (b *Buffer) Truncate(size int) { func (b *ABuffer) Truncate(size int) {
if size == 0 { if size == 0 {
b.Reset() b.Reset()
return return
@ -98,7 +94,7 @@ func (b *Buffer) Truncate(size int) {
} }
func (b *Buffer) Read(data []byte) (count int, err error) { func (b *ABuffer) Read(data []byte) (count int, err error) {
b.lastOp = opInvalid b.lastOp = opInvalid
if b.isEmpty() { if b.isEmpty() {
b.Reset() b.Reset()
@ -116,7 +112,7 @@ func (b *Buffer) Read(data []byte) (count int, err error) {
} }
func (b *Buffer) ReadFrom(reader io.Reader) (count int64, err error) { func (b *ABuffer) ReadFrom(reader io.Reader) (count int64, err error) {
b.lastOp = opInvalid b.lastOp = opInvalid
for { for {
i := b.tryGrowByStrategy(MinRead) i := b.tryGrowByStrategy(MinRead)
@ -137,7 +133,7 @@ func (b *Buffer) ReadFrom(reader io.Reader) (count int64, err error) {
} }
func (b *Buffer) ReadByte() (byte, error) { func (b *ABuffer) ReadByte() (byte, error) {
if b.isEmpty() { if b.isEmpty() {
b.Reset() b.Reset()
return 0, io.EOF return 0, io.EOF
@ -149,20 +145,20 @@ func (b *Buffer) ReadByte() (byte, error) {
} }
func (b *Buffer) ReadBytes(delimiter byte) (result []byte, er error) { func (b *ABuffer) ReadBytes(delimiter byte) (result []byte, er error) {
slice, er := b.readSlice(delimiter) slice, er := b.readSlice(delimiter)
result = append(result, slice...) result = append(result, slice...)
return result, er return result, er
} }
func (b *Buffer) ReadString(delimiter byte) (result string, err error) { func (b *ABuffer) ReadString(delimiter byte) (result string, err error) {
slice, err := b.readSlice(delimiter) slice, err := b.readSlice(delimiter)
return string(slice), err return string(slice), err
} }
func (b *Buffer) ReadRune() (run rune, size int, err error) { func (b *ABuffer) ReadRune() (run rune, size int, err error) {
if b.isEmpty() { if b.isEmpty() {
b.Reset() b.Reset()
return 0, 0, io.EOF return 0, 0, io.EOF
@ -180,7 +176,7 @@ func (b *Buffer) ReadRune() (run rune, size int, err error) {
} }
func (b *Buffer) readSlice(delimiter byte) (ln []byte, er error) { func (b *ABuffer) readSlice(delimiter byte) (ln []byte, er error) {
i := bytes.IndexByte(b.data[b.off:], delimiter) i := bytes.IndexByte(b.data[b.off:], delimiter)
end := b.off + i + 1 end := b.off + i + 1
if i < 0 { if i < 0 {
@ -194,7 +190,7 @@ func (b *Buffer) readSlice(delimiter byte) (ln []byte, er error) {
} }
func (b *Buffer) UnreadRune() error { func (b *ABuffer) UnreadRune() error {
if b.lastOp <= opInvalid { if b.lastOp <= opInvalid {
return G.ErrUnreadInvalid return G.ErrUnreadInvalid
} }
@ -206,7 +202,7 @@ func (b *Buffer) UnreadRune() error {
} }
func (b *Buffer) UnreadByte() error { func (b *ABuffer) UnreadByte() error {
if b.lastOp == opInvalid { if b.lastOp == opInvalid {
return G.ErrUnreadInvalid return G.ErrUnreadInvalid
} }
@ -218,7 +214,7 @@ func (b *Buffer) UnreadByte() error {
} }
func (b *Buffer) AppendWith(appender Appender) { func (b *ABuffer) AppendWith(appender Appender) {
b.lastOp = opInvalid b.lastOp = opInvalid
if appender != nil { if appender != nil {
b.data = appender.Append(b.data) b.data = appender.Append(b.data)
@ -226,20 +222,20 @@ func (b *Buffer) AppendWith(appender Appender) {
} }
func (b *Buffer) Write(value []byte) (int, error) { func (b *ABuffer) Write(value []byte) (int, error) {
b.lastOp = opInvalid b.lastOp = opInvalid
return copy(b.data[b.tryGrow(len(value)):], value), nil return copy(b.data[b.tryGrow(len(value)):], value), nil
} }
func (b *Buffer) W (value []byte) { func (b *ABuffer) W (value []byte) {
b.lastOp = opInvalid b.lastOp = opInvalid
copy(b.data[b.tryGrow(len(value)):], value) copy(b.data[b.tryGrow(len(value)):], value)
} }
// WOQ With Optional Quoted // WOQ With Optional Quoted
func (b *Buffer) WOQ (add bool, quote byte, value []byte) { func (b *ABuffer) WOQ (add bool, quote byte, value []byte) {
b.lastOp = opInvalid b.lastOp = opInvalid
if !add { if !add {
copy(b.data[b.tryGrow(len(value)):], value) copy(b.data[b.tryGrow(len(value)):], value)
@ -252,7 +248,7 @@ func (b *Buffer) WOQ (add bool, quote byte, value []byte) {
} }
func (b *Buffer) WriteHTML(source []byte) { func (b *ABuffer) WriteHTML(source []byte) {
st := 0 st := 0
for i,c := range source { for i,c := range source {
if c == '<' || c == '>' || c == '&' { if c == '<' || c == '>' || c == '&' {
@ -279,13 +275,13 @@ func (b *Buffer) WriteHTML(source []byte) {
} }
func (b *Buffer) WriteByte(value byte) { func (b *ABuffer) WriteByte(value byte) {
b.lastOp = opInvalid b.lastOp = opInvalid
b.data[b.tryGrow(1)] = value b.data[b.tryGrow(1)] = value
} }
func (b *Buffer) Write2Byte(valueA, valueB byte) { func (b *ABuffer) Write2Byte(valueA, valueB byte) {
b.lastOp = opInvalid b.lastOp = opInvalid
p := b.tryGrow(2) p := b.tryGrow(2)
b.data[p] = valueA b.data[p] = valueA
@ -293,15 +289,15 @@ func (b *Buffer) Write2Byte(valueA, valueB byte) {
} }
func (b *Buffer) WriteString(value string) { func (b *ABuffer) WriteString(value string) {
b.W([]byte(value)) } b.W([]byte(value)) }
func (b *Buffer) WriteTo(writer io.Writer) (int64, error) { func (b *ABuffer) WriteTo(writer io.Writer) (int64, error) {
return b.writeTo(writer, false) } return b.writeTo(writer, false) }
func (b *Buffer) FlushTo(writer io.Writer) (int64, error) { func (b *ABuffer) FlushTo(writer io.Writer) (int64, error) {
return b.writeTo(writer, true) } return b.writeTo(writer, true) }
@ -310,7 +306,7 @@ func (b *Buffer) FlushTo(writer io.Writer) (int64, error) {
func (b *Buffer) writeTo(writer io.Writer, reset bool) (count int64, err error) { func (b *ABuffer) writeTo(writer io.Writer, reset bool) (count int64, err error) {
if reset { if reset {
b.lastOp = opInvalid b.lastOp = opInvalid
} }
@ -335,7 +331,7 @@ func (b *Buffer) writeTo(writer io.Writer, reset bool) (count int64, err error)
} }
func (b *Buffer) tryGrow(size int) int { func (b *ABuffer) tryGrow(size int) int {
m := len(b.data) m := len(b.data)
if size <= cap(b.data)-m { if size <= cap(b.data)-m {
b.data = b.data[:m+size] b.data = b.data[:m+size]
@ -368,7 +364,7 @@ func (b *Buffer) tryGrow(size int) int {
} }
func (b *Buffer) tryGrowByResize(size int) (int, bool) { func (b *ABuffer) tryGrowByResize(size int) (int, bool) {
if l := len(b.data); size <= cap(b.data)-l { if l := len(b.data); size <= cap(b.data)-l {
b.data = b.data[:l+size] b.data = b.data[:l+size]
return l, true return l, true
@ -377,7 +373,7 @@ func (b *Buffer) tryGrowByResize(size int) (int, bool) {
} }
func (b *Buffer) tryGrowByStrategy(size int) int { func (b *ABuffer) tryGrowByStrategy(size int) int {
m := len(b.data) m := len(b.data)
if m == 0 && b.off != 0 { if m == 0 && b.off != 0 {
b.Reset() b.Reset()

@ -21,7 +21,7 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package bfers package mems
import ( import (
"encoding/binary" "encoding/binary"
@ -31,7 +31,7 @@ import (
func (b *Buffer) WriteBool(value bool) { func (b *ABuffer) WriteBool(value bool) {
if value { if value {
b.WriteByte(1) b.WriteByte(1)
return return
@ -40,11 +40,11 @@ func (b *Buffer) WriteBool(value bool) {
} }
func (b *Buffer) WriteRune(value rune, byteOrder binary.ByteOrder) { func (b *ABuffer) WriteRune(value rune, byteOrder binary.ByteOrder) {
b.WriteUint32(uint32(value), byteOrder) } b.WriteUint32(uint32(value), byteOrder) }
func (b *Buffer) WriteUint16(value uint16, byteOrder binary.ByteOrder) { func (b *ABuffer) WriteUint16(value uint16, byteOrder binary.ByteOrder) {
b.lastOp = opInvalid b.lastOp = opInvalid
if byteOrder == nil { if byteOrder == nil {
byteOrder = binary.LittleEndian byteOrder = binary.LittleEndian
@ -53,7 +53,7 @@ func (b *Buffer) WriteUint16(value uint16, byteOrder binary.ByteOrder) {
} }
func (b *Buffer) WriteUint32(value uint32, byteOrder binary.ByteOrder) { func (b *ABuffer) WriteUint32(value uint32, byteOrder binary.ByteOrder) {
b.lastOp = opInvalid b.lastOp = opInvalid
if byteOrder == nil { if byteOrder == nil {
byteOrder = binary.LittleEndian byteOrder = binary.LittleEndian
@ -62,7 +62,7 @@ func (b *Buffer) WriteUint32(value uint32, byteOrder binary.ByteOrder) {
} }
func (b *Buffer) WriteUint64(value uint64, byteOrder binary.ByteOrder) { func (b *ABuffer) WriteUint64(value uint64, byteOrder binary.ByteOrder) {
if byteOrder == nil { if byteOrder == nil {
byteOrder = binary.LittleEndian byteOrder = binary.LittleEndian
} }
@ -70,27 +70,27 @@ func (b *Buffer) WriteUint64(value uint64, byteOrder binary.ByteOrder) {
} }
func (b *Buffer) WriteInt16(value int16, byteOrder binary.ByteOrder) { func (b *ABuffer) WriteInt16(value int16, byteOrder binary.ByteOrder) {
b.WriteUint16(uint16(value), byteOrder) } b.WriteUint16(uint16(value), byteOrder) }
func (b *Buffer) WriteInt32(value int32, byteOrder binary.ByteOrder) { func (b *ABuffer) WriteInt32(value int32, byteOrder binary.ByteOrder) {
b.WriteUint32(uint32(value), byteOrder) } b.WriteUint32(uint32(value), byteOrder) }
func (b *Buffer) WriteInt64(value int64, byteOrder binary.ByteOrder) { func (b *ABuffer) WriteInt64(value int64, byteOrder binary.ByteOrder) {
b.WriteUint64(uint64(value), byteOrder) } b.WriteUint64(uint64(value), byteOrder) }
func (b *Buffer) WriteFloat32(value float32, byteOrder binary.ByteOrder) { func (b *ABuffer) WriteFloat32(value float32, byteOrder binary.ByteOrder) {
b.WriteUint32(math.Float32bits(value), byteOrder) } b.WriteUint32(math.Float32bits(value), byteOrder) }
func (b *Buffer) WriteFloat64(value float64, byteOrder binary.ByteOrder) { func (b *ABuffer) WriteFloat64(value float64, byteOrder binary.ByteOrder) {
b.WriteUint64(math.Float64bits(value), byteOrder) } b.WriteUint64(math.Float64bits(value), byteOrder) }
func (b *Buffer) WriteComplex64(value complex64, byteOrder binary.ByteOrder) { func (b *ABuffer) WriteComplex64(value complex64, byteOrder binary.ByteOrder) {
b.lastOp = opInvalid b.lastOp = opInvalid
if byteOrder == nil { if byteOrder == nil {
byteOrder = binary.LittleEndian byteOrder = binary.LittleEndian
@ -101,7 +101,7 @@ func (b *Buffer) WriteComplex64(value complex64, byteOrder binary.ByteOrder) {
} }
func (b *Buffer) WriteComplex128(value complex128, byteOrder binary.ByteOrder) { func (b *ABuffer) WriteComplex128(value complex128, byteOrder binary.ByteOrder) {
b.lastOp = opInvalid b.lastOp = opInvalid
if byteOrder == nil { if byteOrder == nil {
byteOrder = binary.LittleEndian byteOrder = binary.LittleEndian
@ -112,7 +112,7 @@ func (b *Buffer) WriteComplex128(value complex128, byteOrder binary.ByteOrder) {
} }
func (b *Buffer) WriteTime(value time.Time) error { func (b *ABuffer) WriteTime(value time.Time) error {
b.lastOp = opInvalid b.lastOp = opInvalid
d, e := value.MarshalBinary() d, e := value.MarshalBinary()
if e != nil { if e != nil {
@ -123,5 +123,5 @@ func (b *Buffer) WriteTime(value time.Time) error {
} }
func (b *Buffer) WriteDuration(val time.Duration) { func (b *ABuffer) WriteDuration(val time.Duration) {
b.WriteInt64(int64(val), binary.LittleEndian) } b.WriteInt64(int64(val), binary.LittleEndian) }

@ -21,7 +21,7 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package bfers package mems
import ( import (
"strconv" "strconv"
@ -29,12 +29,12 @@ import (
"unicode/utf8" "unicode/utf8"
) )
func (b *Buffer) WriteBoolStr(value bool) { func (b *ABuffer) WriteBoolStr(value bool) {
b.lastOp = opInvalid b.lastOp = opInvalid
b.data = strconv.AppendBool(b.data, value) b.data = strconv.AppendBool(b.data, value)
} }
func (b *Buffer) WriteRuneStr(value rune) int { func (b *ABuffer) WriteRuneStr(value rune) int {
if value < utf8.RuneSelf { if value < utf8.RuneSelf {
b.WriteByte(byte(value)) b.WriteByte(byte(value))
return 1 return 1
@ -46,7 +46,7 @@ func (b *Buffer) WriteRuneStr(value rune) int {
return cn return cn
} }
func (b *Buffer) WriteUIntStr(value uint64, base int) { func (b *ABuffer) WriteUIntStr(value uint64, base int) {
b.lastOp = opInvalid b.lastOp = opInvalid
if base == 0 { if base == 0 {
base = 10 base = 10
@ -54,7 +54,7 @@ func (b *Buffer) WriteUIntStr(value uint64, base int) {
b.data = strconv.AppendUint(b.data, value, base) b.data = strconv.AppendUint(b.data, value, base)
} }
func (b *Buffer) WriteIntStr(value int64, base int) { func (b *ABuffer) WriteIntStr(value int64, base int) {
b.lastOp = opInvalid b.lastOp = opInvalid
if base == 0 { if base == 0 {
base = 10 base = 10
@ -62,7 +62,7 @@ func (b *Buffer) WriteIntStr(value int64, base int) {
b.data = strconv.AppendInt(b.data, value, base) b.data = strconv.AppendInt(b.data, value, base)
} }
func (b *Buffer) WriteFloatStr(value float64, formatter byte, precision int) { func (b *ABuffer) WriteFloatStr(value float64, formatter byte, precision int) {
b.lastOp = opInvalid b.lastOp = opInvalid
if formatter == 0 { if formatter == 0 {
formatter = 'f' formatter = 'f'
@ -70,7 +70,7 @@ func (b *Buffer) WriteFloatStr(value float64, formatter byte, precision int) {
b.data = strconv.AppendFloat(b.data, value, formatter, precision, 64) b.data = strconv.AppendFloat(b.data, value, formatter, precision, 64)
} }
func (b *Buffer) WriteComplexStr(value complex128, formatter byte, precision int) { func (b *ABuffer) WriteComplexStr(value complex128, formatter byte, precision int) {
b.lastOp = opInvalid b.lastOp = opInvalid
if formatter == 0 { if formatter == 0 {
formatter = 'f' formatter = 'f'
@ -78,7 +78,7 @@ func (b *Buffer) WriteComplexStr(value complex128, formatter byte, precision int
b.data = append(b.data, strconv.FormatComplex(value, formatter, precision, 128)...) b.data = append(b.data, strconv.FormatComplex(value, formatter, precision, 128)...)
} }
func (b *Buffer) WriteDateStr (value time.Time, layout string) { func (b *ABuffer) WriteDateStr (value time.Time, layout string) {
b.lastOp = opInvalid b.lastOp = opInvalid
if layout == "" { if layout == "" {
layout = time.RFC822 layout = time.RFC822

@ -21,7 +21,8 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package bfers package mems
const ( const (
@ -30,27 +31,32 @@ const (
minSize = 1 << minBitSize minSize = 1 << minBitSize
maxSize = 1 << (minBitSize + poolSteps - 1) maxSize = 1 << (minBitSize + poolSteps - 1)
maxInt = int(^uint(0) >> 1)
MinRead = 512
poolSteps = 20 poolSteps = 20
poolThreshold = 42000 poolThreshold = 42000
poolPercentile = 0.95 poolPercentile = 0.95
) )
var ( var (
G = struct { G = struct {
ErrOutOfRange ErrBuffer ErrOutOfRange ErrMems
ErrWriteCount ErrBuffer ErrWriteCount ErrMems
ErrTooShort ErrBuffer ErrTooShort ErrMems
ErrTooLarge ErrBuffer ErrTooLarge ErrMems
ErrNegativeRead ErrBuffer ErrNegativeRead ErrMems
ErrUnreadInvalid ErrBuffer ErrUnreadInvalid ErrMems
}{ }{
ErrOutOfRange: ErrBuffer{"out-of-range"}, ErrOutOfRange: ErrMems("out-of-range"),
ErrWriteCount: ErrBuffer{"write-count"}, ErrWriteCount: ErrMems("write-count"),
ErrTooShort: ErrBuffer{"too-short"}, ErrTooShort: ErrMems("too-short"),
ErrTooLarge: ErrBuffer{"too-large"}, ErrTooLarge: ErrMems("too-large"),
ErrNegativeRead: ErrBuffer{"negative-read"}, ErrNegativeRead: ErrMems("negative-read"),
ErrUnreadInvalid: ErrBuffer{"unread-invalid"}, ErrUnreadInvalid: ErrMems("unread-invalid"),
} }
g = struct { g = struct {
@ -62,10 +68,10 @@ var (
func AcquireBuffer () *Buffer { func AcquireABuffer() *ABuffer {
return g.bufferPool.Get() } return g.bufferPool.Get() }
func ReleaseBuffer (buffer *Buffer) { func ReleaseABuffer(buffer *ABuffer) {
g.bufferPool.Put(buffer) } g.bufferPool.Put(buffer) }

@ -21,7 +21,7 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package bfers package mems
type ( type (

@ -21,13 +21,28 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package bfers package mems
import "errs/collects"
type ( type (
ErrBuffer struct { string } // ErrMems no puede heredar directamente de Errs.Code
// ya que es utilizada por fjson y ftext lo que crea
// un ciclo de importaciones
//
ErrMems string
) )
func (e ErrBuffer) Error() string {
return e.string func (e ErrMems) Error() string {
} return string(e) }
func (e ErrMems) Code () string {
return string(e) }
func (e ErrMems) Collect (c collects.Collector) {
c.AddFieldString(collects.FieldNameCode,string(e)) }

@ -21,7 +21,7 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package bfers package mems
const ( const (

@ -21,7 +21,7 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package bfers package mems
import ( import (
"sort" "sort"
@ -73,18 +73,18 @@ func (p *Pool) CallsThreshold() uint64 {
return atomic.LoadUint64(&p.threshold) } return atomic.LoadUint64(&p.threshold) }
func (p *Pool) Get() *Buffer { func (p *Pool) Get() *ABuffer {
b := p.inner.Get() b := p.inner.Get()
p.AddAcquired() p.AddAcquired()
if b == nil { if b == nil {
p.AddCreated() p.AddCreated()
return NewBuffer() return NewABuffer()
} }
return b.(*Buffer) return b.(*ABuffer)
} }
func (p *Pool) Put(buffer *Buffer) { func (p *Pool) Put(buffer *ABuffer) {
if buffer == nil { if buffer == nil {
return return
} }

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save

Powered by TurnKey Linux.