terminando el packer

packs2
DEV 3 years ago
parent 7d3ec68bad
commit 1a4b3476e8

@ -24,26 +24,78 @@
package main package main
import ( import (
"activething.com/go/gogo/core/bits"
"activething.com/go/gogo/core/errs" "activething.com/go/gogo/core/errs"
"activething.com/go/gogo/core/results"
"activething.com/go/gogo/packs/pjson" "activething.com/go/gogo/packs/pjson"
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"encoding/base64"
"fmt" "fmt"
"io"
) )
type A struct { type A struct {
CampoInt int `pack:"campo,q"` CampoInt int `pack:"campo,q,e"`
Cadena string `json:"cadena,b64"` Cadena string `json:"cadena,e,b64"`
Seguro string `pack:"seguro,e"`
Arrays []byte `pack:"arr,b64"` Arrays []byte `pack:"arr,b64"`
} }
type encrypter struct {
key []byte
}
func (e encrypter) Encrypt (data []byte) results.Bytes {
b,er := aes.NewCipher(e.key)
ct := make([]byte,aes.BlockSize+len(data))
iv := ct[:aes.BlockSize]
if _, er = io.ReadFull(rand.Reader, iv); er != nil {
return results.MakeBytesError(fmt.Errorf("could not encrypt: %v", er))
}
st := cipher.NewCFBEncrypter(b,iv)
st.XORKeyStream(ct[aes.BlockSize:],data)
return results.BytesSuccess(ct)
}
func (e encrypter) Decrypt (data string) (string,error) {
cipherText, er := base64.StdEncoding.DecodeString(data)
if er != nil {
return "", fmt.Errorf("could not base64 decode: %v", er)
}
block, err := aes.NewCipher(e.key)
if err != nil {
return "", fmt.Errorf("could not create new cipher: %v", er)
}
if len(cipherText) < aes.BlockSize {
return "", fmt.Errorf("invalid ciphertext block size")
}
iv := cipherText[:aes.BlockSize]
cipherText = cipherText[aes.BlockSize:]
stream := cipher.NewCFBDecrypter(block, iv)
stream.XORKeyStream(cipherText, cipherText)
return string(cipherText), nil
}
func main() { func main() {
en := encrypter{key: []byte{0,1,2,3,45,6,6,7,8,9,0,1,1,1,1,1}}
pk := pjson.NewPacker() pk := pjson.NewPacker(pjson.PackerWithEncrypter(en))
t := A { t := A {
CampoInt: 23, CampoInt: 23,
Cadena: "Esto es una cadena", Cadena: "Esto es una cadena",
Seguro: "Esto debe de ir encruptdao",
Arrays: []byte{233,222,221}, Arrays: []byte{233,222,221},
} }
@ -79,11 +131,24 @@ func main() {
errs.Test(pk.Error(),true) errs.Test(pk.Error(),true)
fmt.Printf("Paquete %s\n",pk.Packet()) fmt.Printf("Paquete %s\n",pk.Packet())
f := bits.BFlags16(256) /*
res := en.Encrypt([]byte("Esto debe de ir encruptdao"))
if res.IsError() {
panic(res.Error())
}
dt := string(res.Success())
fmt.Printf("seguro %s\n",dt)
st,er := en.Decrypt(dt)
if er != nil {
panic(er)
}
fmt.Printf("decrupt %s\n",st)
*/
}
fmt.Printf("%016b\n",f)
//fmt.Printf("%08b\n",f.GetSet(1))
}

@ -68,7 +68,7 @@ func (f BFlags16) Extract() []BFlags16 {
} }
func (f BFlags16) FlagsToNames ( namer func(flags BFlags16) string) []string { func (f BFlags16) FlagsToNames (namer func(flags BFlags16) string) []string {
if f == 0 { if f == 0 {
return []string{} return []string{}
} }

@ -1,25 +1,30 @@
// ------------------------------------------------------------------------ /*
// Project atila *
// Active Thing (activething.com) git.activething.com/go * ---------------------------------------------------------
// * Project $PROJECT_NAME
// File name gogo.go * Active Thing (activething.com) git.activething.com/go
// Created by DEV *
// Modified 15/02/2024 * File name $FILE_NAME
// * Created by ${USER}
// Copyright 2024 activething.com * Modified ${DAY}/${MONTH}/${YEAR}
// ------------------------------------------------------------------------ *
// Licensed under the Apache License, Version 2.0 (the "License"); * Copyright ${YEAR} activething.com
// you may not use this file except in compliance with the License. * ---------------------------------------------------------
// You may obtain a copy of the License at * // Licensed under the Apache License, Version 2.0 (the "License");
// * // you may not use this file except in compliance with the License.
// http://www.apache.org/licenses/LICENSE-2.0 * // You may obtain a copy of the License at
// * //
// Unless required by applicable law or agreed to in writing, software * // http://www.apache.org/licenses/LICENSE-2.0
// distributed under the License is distributed on an "AS IS" BASIS, * //
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * // Unless required by applicable law or agreed to in writing, software
// See the License for the specific language governing permissions and * // distributed under the License is distributed on an "AS IS" BASIS,
// limitations under the License. * // 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 bits package bits

@ -0,0 +1,35 @@
// ------------------------------------------------------------------------
// Project atila
// Active Thing (activething.com) git.activething.com/go
//
// File name crypter.go
// Created by DEV
// Modified 16/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 crypts
type (
Crypter interface {
Encrypter
Decrypter
}
)

@ -2,9 +2,9 @@
// Project atila // Project atila
// Active Thing (activething.com) git.activething.com/go // Active Thing (activething.com) git.activething.com/go
// //
// File name r_bytes.go // File name decrypter.go
// Created by DEV // Created by DEV
// Modified 15/02/2024 // Modified 16/02/2024
// //
// Copyright 2024 activething.com // Copyright 2024 activething.com
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -21,36 +21,22 @@
// limitations under the License. // limitations under the License.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package results package crypts
import "activething.com/go/gogo/core/results"
type ( type (
Decrypter interface {
Decrypt (data []byte) results.Bytes
}
RBytesSuccess []byte DecrypterNop struct {}
RBytesError struct { error }
) )
func (_ RBytesSuccess) IsError () bool { return false }
func (_ RBytesSuccess) Error () error { return nil }
func (r RBytesSuccess) Success () []byte { return []byte(r) }
func (_ RBytesError) IsError () bool { return true }
func (_ RBytesError) Success () []byte { return nil }
func (r RBytesError) Error () error { return r.error }
func (_ DecrypterNop) Decrypt (_ []byte) results.Bytes {
return results.MakeBytesError(G.ErrNotImplemented) }

@ -0,0 +1,41 @@
// ------------------------------------------------------------------------
// Project atila
// Active Thing (activething.com) git.activething.com/go
//
// File name encrypter.go
// Created by DEV
// Modified 16/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 crypts
import "activething.com/go/gogo/core/results"
type (
Encrypter interface {
Encrypt (data []byte) results.Bytes
}
EncrypterNop struct {}
)
func (_ EncrypterNop) Encrypt (_ []byte) results.Bytes {
return results.MakeBytesError(G.ErrNotImplemented) }

@ -0,0 +1,4 @@
module activething.com/go/gogo/core/crypts
go 1.20

@ -0,0 +1,35 @@
// ------------------------------------------------------------------------
// Project atila
// Active Thing (activething.com) git.activething.com/go
//
// File name gogo.go
// Created by DEV
// Modified 16/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 crypts
import "activething.com/go/gogo/core/errs"
var (
G = struct {
ErrNotImplemented errs.ErrCode
}{
ErrNotImplemented: errs.ErrCode("core:crypts.not-implemented"),
}
)

@ -1,66 +0,0 @@
/*
*
* ---------------------------------------------------------
* Project $PROJECT_NAME
* Active Thing (activething.com) git.activething.com/go
*
* File name $FILE_NAME
* Created by ${USER}
* Modified ${DAY}/${MONTH}/${YEAR}
*
* Copyright ${YEAR} 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 opts
// Apply
// aplica una serie de funciones OptionFnc a un objeto dado y lo retorna modificado.
func Apply[T any](target *T, options ...OptionFnc[T]) *T {
if target == nil {
return nil
}
for _, fn := range options {
fn(target)
}
return target
}
// ApplyAndCheck
// aplica una serie de funciones OptionErrFnc a un objeto y retorna el objeto modificado,
// junto con un posible error en caso de configuración incorrecta.
func ApplyAndCheck[T any](target *T, options ...OptionErrFnc[T]) (*T, error) {
for _, fn := range options {
if err := fn(target); err != nil {
return nil, err
}
}
return target, nil
}
// ApplyAndCheckAll
// aplica una serie de funciones OptionErrFnc a un objeto y retorna el objeto modificado,
// junto con una lista de errores que se han producido durante la configuración.
func ApplyAndCheckAll[T any](target T, options ...OptionErrFnc[T]) (T, []error) {
var lst []error
for _, fn := range options {
if err := fn(&target); err != nil {
lst = append(lst, err)
}
}
return target, lst
}

@ -38,3 +38,44 @@ type (
// //
OptionErrFnc[T any] func(obj *T) error OptionErrFnc[T any] func(obj *T) error
) )
// Apply
// aplica una serie de funciones OptionFnc a un objeto dado y lo retorna modificado.
func Apply[T any](target *T, options ...OptionFnc[T]) *T {
if target == nil {
return nil
}
for _, fn := range options {
fn(target)
}
return target
}
// ApplyAndCheck
// aplica una serie de funciones OptionErrFnc a un objeto y retorna el objeto modificado,
// junto con un posible error en caso de configuración incorrecta.
func ApplyAndCheck[T any](target *T, options ...OptionErrFnc[T]) (*T, error) {
for _, fn := range options {
if err := fn(target); err != nil {
return nil, err
}
}
return target, nil
}
// ApplyAndCheckAll
// aplica una serie de funciones OptionErrFnc a un objeto y retorna el objeto modificado,
// junto con una lista de errores que se han producido durante la configuración.
func ApplyAndCheckAll[T any](target T, options ...OptionErrFnc[T]) (T, []error) {
var lst []error
for _, fn := range options {
if err := fn(&target); err != nil {
lst = append(lst, err)
}
}
return target, lst
}

@ -0,0 +1,66 @@
// ------------------------------------------------------------------------
// Project atila
// Active Thing (activething.com) git.activething.com/go
//
// File name r_bytes.go
// Created by DEV
// Modified 15/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 results
type (
Bytes interface {
IsError () bool
Success () []byte
Error () error
}
BytesSuccess []byte
BytesError struct {
error
}
)
func (_ BytesSuccess) IsError () bool { return false }
func (_ BytesSuccess) Error () error { return nil }
func (r BytesSuccess) Success () []byte { return r }
func MakeBytesError (cause error) BytesError {
return BytesError{ cause } }
func (_ BytesError) IsError () bool { return true }
func (_ BytesError) Success () []byte { return nil }
func (r BytesError) Error () error { return r.error }

@ -0,0 +1,4 @@
module activething.com/go/gogo/core/results
go 1.20

@ -27,28 +27,33 @@ package results
type ( type (
Int interface {
Success () int
Error () error
}
RIntSuccess int IntSuccess int
RIntError struct { IntError struct {
error error
} }
) )
func (_ RIntSuccess) IsError () bool { return false } func (_ IntSuccess) IsError () bool { return false }
func (_ RIntSuccess) Error () error { return nil } func (_ IntSuccess) Error () error { return nil }
func (r RIntSuccess) Success () int { return int(r) } func (r IntSuccess) Success () int { return int(r) }
func (_ RIntError) IsError () bool { return true } func (_ IntError) IsError () bool { return true }
func (_ RIntError) Success () int { return 0 } func (_ IntError) Success () int { return 0 }
func (r RIntError) Error () error { return r.error } func (r IntError) Error () error { return r.error }

@ -36,7 +36,7 @@ type (
ResultSuccess[T any] struct { ResultSuccess[T any] struct {
T data T
} }
ResultError[T any] struct { ResultError[T any] struct {
@ -51,7 +51,7 @@ func (_ ResultSuccess[T]) IsError () bool {
return false } return false }
func (r ResultSuccess[T]) Success() T { func (r ResultSuccess[T]) Success() T {
return r.T } return r.data }
func (_ ResultSuccess[T]) Error() error { func (_ ResultSuccess[T]) Error() error {
return nil } return nil }

@ -27,28 +27,33 @@ package results
type ( type (
String interface {
Success () string
Error () error
}
RStringSuccess string StringSuccess string
RStringError struct { StringError struct {
error error
} }
) )
func (_ RStringSuccess) IsError () bool { return false } func (_ StringSuccess) IsError () bool { return false }
func (_ RStringSuccess) Error () error { return nil } func (_ StringSuccess) Error () error { return nil }
func (r RStringSuccess) Success () string { return string(r) } func (r StringSuccess) Success () string { return string(r) }
func (_ RStringError) IsError () bool { return true } func (_ StringError) IsError () bool { return true }
func (_ RStringError) Success () string { return "" } func (_ StringError) Success () string { return "" }
func (r RStringError) Error () error { return r.error } func (r StringError) Error () error { return r.error }

@ -11,6 +11,8 @@ use (
./core/errs ./core/errs
./core/opts ./core/opts
./core/syncs ./core/syncs
./core/results
./core/crypts
./packs ./packs

@ -38,6 +38,7 @@ const (
FlagQuote FlagQuote
FlagScapeHTML FlagScapeHTML
FlagString FlagString
FlagEncrypted
FlagBinary64 Flags = 0b0000100000000000 FlagBinary64 Flags = 0b0000100000000000
FlagBinary32 Flags = 0b0000010000000000 FlagBinary32 Flags = 0b0000010000000000
@ -52,7 +53,7 @@ const (
) )
type Flags bits.BFlags16 type Flags bits.BFlags16
func (f Flags) Omit () bool { return f&FlagOmit != 0 } func (f Flags) Omit () bool { return f&FlagOmit != 0 }
@ -65,6 +66,8 @@ func (f Flags) EscapeHTML () bool { return f&FlagScapeHTML != 0 }
func (f Flags) String () bool { return f&FlagString != 0 } func (f Flags) String () bool { return f&FlagString != 0 }
func (f Flags) Encrypted() bool { return f&FlagEncrypted != 0 }
func (f Flags) Binary () bool { return f&(FlagBinary64|FlagBinary32) != 0 } func (f Flags) Binary () bool { return f&(FlagBinary64|FlagBinary32) != 0 }
@ -75,6 +78,13 @@ func (f Flags) Bin32 () bool { return f&FlagBinary32 != 0 }
func (f Flags) SetDate (flagDate Flags) Flags {
return (f&flagMaskDate) | flagDate }
func (f Flags) SetBinary (flagBinary Flags) Flags {
return (f&flagMaskBin) | flagBinary }
@ -99,6 +109,7 @@ func (f Flags) Names () string {
return "" return ""
} }
func (f Flags) binName () string { func (f Flags) binName () string {
switch f & flagMaskBin { switch f & flagMaskBin {
case FlagBinary64 : return "b64" case FlagBinary64 : return "b64"
@ -108,7 +119,6 @@ func (f Flags) binName () string {
} }
func (f Flags) dateName() string { func (f Flags) dateName() string {
switch f & flagMaskDate { switch f & flagMaskDate {
case FlagDateUnix : return "unix" case FlagDateUnix : return "unix"
@ -132,16 +142,14 @@ func (f Flags) DateFormat () string {
func FlagByName (flag string) (f Flags) { func FlagByName (flag string) (f Flags) {
//defer func(){
// fmt.Printf("Set flag : %s = %d\n",flag,f)
//}()
switch strings.ToLower(flag) { switch strings.ToLower(flag) {
case "-","omit" : return FlagOmit case "-","omit" : return FlagOmit
case "e","omitempty": return FlagOmitEmpty case "o","omitempty": return FlagOmitEmpty
case "q","quote" : return FlagQuote case "q","quote" : return FlagQuote
case "h","html" : return FlagScapeHTML case "h","html" : return FlagScapeHTML
case "s","string" : return FlagString case "s","string" : return FlagString
case "e","encrypted": return FlagEncrypted
// formato binario // formato binario
case "b64","bin64" : return FlagBinary64 case "b64","bin64" : return FlagBinary64
@ -159,6 +167,9 @@ func FlagByName (flag string) (f Flags) {
} }
func FlagsWithNames(flags ... string) Flags { func FlagsWithNames(flags ... string) Flags {
var f Flags var f Flags
for _,n := range flags { for _,n := range flags {
@ -170,6 +181,7 @@ func FlagsWithNames(flags ... string) Flags {
func FlagsWithString(flags string, onOption func(string) Flags) Flags { func FlagsWithString(flags string, onOption func(string) Flags) Flags {
var f Flags var f Flags
if len(flags) == 0 { if len(flags) == 0 {
return f return f
@ -183,13 +195,12 @@ func FlagsWithString(flags string, onOption func(string) Flags) Flags {
return nf return nf
} }
func FlagsFromPackTag (raw reflect.StructTag) (string,Flags,bool) {
return FlagsFromTag(raw,TagKey,FlagByName) }
func FlagsTag(raw reflect.StructTag) (string,Flags,bool) {
return TagFlags (raw, TagKey,FlagByName)
}
func TagFlags (raw reflect.StructTag, tag string, onOption func(string) Flags) (string,Flags,bool) { func FlagsFromTag(raw reflect.StructTag, tag string, onOption func(string) Flags) (string,Flags,bool) {
st,ok := raw.Lookup(tag) st,ok := raw.Lookup(tag)
if !ok { if !ok {
return "",0,false return "",0,false

@ -25,6 +25,8 @@ package packs
import ( import (
"activething.com/go/gogo/core/bins" "activething.com/go/gogo/core/bins"
"activething.com/go/gogo/core/crypts"
"activething.com/go/gogo/core/opts"
"activething.com/go/gogo/core/syncs" "activething.com/go/gogo/core/syncs"
"sync/atomic" "sync/atomic"
) )
@ -42,29 +44,36 @@ type (
Error error Error error
checks map[any]struct{} checks map[any]struct{}
counts []int counts []int
Encrypter crypts.Encrypter
} }
StateOptionFnc func (*State)
) )
func NewState() *State { func NewState(options ...opts.OptionFnc[State]) *State {
if atomic.CompareAndSwapUint32(&G.poolsSem,0,1) { if atomic.CompareAndSwapUint32(&G.poolsSem,0,1) {
G.statePool = syncs.NewPool[State]( G.statePool = syncs.NewPool[State](
syncs.PoolWithNew[State](func() *State { syncs.PoolWithNew[State](func() *State {
return &State{ return &State{
Buffer: bins.NewBuffer(), Buffer : bins.NewBuffer(),
checks: make(map[any]struct{}), checks : make(map[any]struct{}),
counts: []int{0}, counts : []int{0},
Encrypter: crypts.EncrypterNop{},
} }
}), }),
) )
} }
return G.statePool.Get() if len(options) == 0 {
return G.statePool.Get()
}
return opts.Apply(G.statePool.Get(),options ...)
} }
func ReleaseState (state *State) { func ReleaseState (state *State) {
if state == nil { if state == nil {
state.Encrypter = crypts.EncrypterNop{}
state.Buffer.Reset() state.Buffer.Reset()
state.Error = nil state.Error = nil
state.counts= append(state.counts[:0],0) state.counts= append(state.counts[:0],0)

@ -30,6 +30,7 @@ import (
"encoding/base32" "encoding/base32"
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"fmt"
"math" "math"
"reflect" "reflect"
"strconv" "strconv"
@ -253,6 +254,17 @@ func packString (state *packs.State, value string , flags packs.Flags) {
return return
} }
if flags.Encrypted() {
r := state.Encrypter.Encrypt([]byte(value))
if r.IsError() {
state.SetError(r.Error())
return
}
packBinary(state,r.Success(),flags|packs.FlagBinary64)
fmt.Printf("Errir %v\n",state.Error)
return
}
if flags.Binary() { if flags.Binary() {
packBinary(state,[]byte(value),flags) packBinary(state,[]byte(value),flags)
return return
@ -330,6 +342,18 @@ func packBinary (state *packs.State, value []byte , flags packs.Flags) {
state.Write2Byte('"','"') state.Write2Byte('"','"')
return return
} }
if flags.Encrypted() {
r := state.Encrypter.Encrypt(value)
if r.IsError() {
state.SetError(r.Error())
return
}
packBinary(state,r.Success(),flags|packs.FlagBinary64)
return
}
state.WriteByte('"') state.WriteByte('"')
if flags.Bin64() { if flags.Bin64() {

@ -0,0 +1,41 @@
// ------------------------------------------------------------------------
// Project atila
// Active Thing (activething.com) git.activething.com/go
//
// File name packer_opts.go
// Created by DEV
// Modified 16/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 (
"activething.com/go/gogo/core/crypts"
"activething.com/go/gogo/core/opts"
)
func PackerWithEncrypter (encrypter crypts.Encrypter) opts.OptionFnc[Packer] {
return func(p *Packer) {
if encrypter == nil {
encrypter = crypts.EncrypterNop{}
}
p.state.Encrypter = encrypter
}
}

@ -82,7 +82,7 @@ func newRObject(rtype reflect.Type) *rObject {
continue continue
} }
nm, fg, has := packs.FlagsTag(sf.Tag) nm, fg, has := packs.FlagsFromPackTag(sf.Tag)
if !has { if !has {
nm, fg, has = jsonTags(sf.Tag) nm, fg, has = jsonTags(sf.Tag)
} }
@ -95,8 +95,6 @@ func newRObject(rtype reflect.Type) *rObject {
} }
} }
index:=make([]int,len(f.index)+1) index:=make([]int,len(f.index)+1)
copy(index,f.index) copy(index,f.index)
index[len(f.index)] = i index[len(f.index)] = i
@ -248,7 +246,7 @@ FieldLoop:
func jsonTags (tag reflect.StructTag) (string,packs.Flags,bool) { func jsonTags (tag reflect.StructTag) (string,packs.Flags,bool) {
return packs.TagFlags(tag,jsonTag,func(n string) packs.Flags { return packs.FlagsFromTag(tag,jsonTag,func(n string) packs.Flags {
switch n { switch n {
case "omitempty" : return packs.FlagOmitEmpty case "omitempty" : return packs.FlagOmitEmpty
case "quote" : return packs.FlagQuote case "quote" : return packs.FlagQuote

Loading…
Cancel
Save

Powered by TurnKey Linux.