Compare commits
2 Commits
b111db0410
...
d634f1d9fd
| Author | SHA1 | Date |
|---|---|---|
|
|
d634f1d9fd | 2 years ago |
|
|
13d4e6c10c | 2 years ago |
@ -0,0 +1,5 @@
|
|||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<state>
|
||||||
|
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||||
|
</state>
|
||||||
|
</component>
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// 🚀 Project ACTIVE4
|
||||||
|
// 🔗 Active Thing (activething.com) git.activething.com/go
|
||||||
|
//
|
||||||
|
// File name flags.go
|
||||||
|
// ✍️ Created by DEV
|
||||||
|
// 📅 Modified 16/06/2024
|
||||||
|
//
|
||||||
|
// 🔒 Copyright 2024 activething.com
|
||||||
|
//
|
||||||
|
// 📜 LICENSE --------------------------------------------------------------
|
||||||
|
// 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 packs
|
||||||
|
|
||||||
|
type (
|
||||||
|
Flags uint16
|
||||||
|
)
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
module packs
|
||||||
|
|
||||||
|
go 1.22
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// 🚀 Project ACTIVE4
|
||||||
|
// 🔗 Active Thing (activething.com) git.activething.com/go
|
||||||
|
//
|
||||||
|
// File name active.go
|
||||||
|
// ✍️ Created by DEV
|
||||||
|
// 📅 Modified 16/06/2024
|
||||||
|
//
|
||||||
|
// 🔒 Copyright 2024 activething.com
|
||||||
|
//
|
||||||
|
// 📜 LICENSE --------------------------------------------------------------
|
||||||
|
// 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 "reflect"
|
||||||
|
|
||||||
|
const (
|
||||||
|
maxIndexKinds = int(reflect.UnsafePointer)
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
G = struct {
|
||||||
|
kpackers kindPackers
|
||||||
|
}{
|
||||||
|
kpackers: makeKindPackers(),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,49 @@
|
|||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// 🚀 Project ACTIVE4
|
||||||
|
// 🔗 Active Thing (activething.com) git.activething.com/go
|
||||||
|
//
|
||||||
|
// File name kind_packer.go
|
||||||
|
// ✍️ Created by DEV
|
||||||
|
// 📅 Modified 16/06/2024
|
||||||
|
//
|
||||||
|
// 🔒 Copyright 2024 activething.com
|
||||||
|
//
|
||||||
|
// 📜 LICENSE --------------------------------------------------------------
|
||||||
|
// 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 "reflect"
|
||||||
|
|
||||||
|
type (
|
||||||
|
|
||||||
|
|
||||||
|
kindPacker struct {
|
||||||
|
packFn rvaluePackFn
|
||||||
|
keyable bool
|
||||||
|
emptyFn func(v reflect.Value) bool
|
||||||
|
}
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
func isEmpty(v reflect.Value) bool {
|
||||||
|
return v.Len() == 0 }
|
||||||
|
|
||||||
|
|
||||||
|
func isZero(v reflect.Value) bool {
|
||||||
|
return v.IsZero() }
|
||||||
|
|
||||||
|
|
||||||
|
func noEmpty(_ reflect.Value) bool {
|
||||||
|
return false }
|
||||||
@ -0,0 +1,116 @@
|
|||||||
|
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// 🚀 Project ACTIVE4
|
||||||
|
// 🔗 Active Thing (activething.com) git.activething.com/go
|
||||||
|
//
|
||||||
|
// File name kind_packers.go
|
||||||
|
// ✍️ Created by DEV
|
||||||
|
// 📅 Modified 16/06/2024
|
||||||
|
//
|
||||||
|
// 🔒 Copyright 2024 activething.com
|
||||||
|
//
|
||||||
|
// 📜 LICENSE --------------------------------------------------------------
|
||||||
|
// 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 (
|
||||||
|
"fmt"
|
||||||
|
"packs"
|
||||||
|
"reflect"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
kindPackers [maxIndexKinds + 1]kindPacker
|
||||||
|
)
|
||||||
|
|
||||||
|
func makeKindPackers() kindPackers {
|
||||||
|
|
||||||
|
notPacker := kindPacker{
|
||||||
|
packFn: unsupportedTypePacker,
|
||||||
|
emptyFn: noEmpty,
|
||||||
|
keyable: false}
|
||||||
|
boolPacker:= kindPacker{
|
||||||
|
packFn: func(p *packer, v reflect.Value, f packs.Flags) { fmt.Println("bool") },
|
||||||
|
emptyFn: isZero,
|
||||||
|
keyable: true }
|
||||||
|
intPacker := kindPacker{
|
||||||
|
packFn: func(p *packer, v reflect.Value, f packs.Flags) {},
|
||||||
|
emptyFn: isZero,
|
||||||
|
keyable: true}
|
||||||
|
uintPacker := kindPacker{
|
||||||
|
packFn: func(p *packer, v reflect.Value, f packs.Flags) {},
|
||||||
|
emptyFn: isZero,
|
||||||
|
keyable: true}
|
||||||
|
floatPacker := kindPacker{
|
||||||
|
packFn: func(p *packer, v reflect.Value, f packs.Flags) {},
|
||||||
|
emptyFn: isZero,
|
||||||
|
keyable: true}
|
||||||
|
listPacker := kindPacker{
|
||||||
|
packFn : func(p *packer, v reflect.Value, f packs.Flags) {},
|
||||||
|
emptyFn: isEmpty,
|
||||||
|
keyable: false}
|
||||||
|
ifacePacker:=kindPacker{
|
||||||
|
packFn : func(p *packer, v reflect.Value, f packs.Flags) {},
|
||||||
|
keyable: false,
|
||||||
|
emptyFn: isZero }
|
||||||
|
mapPacker := kindPacker{
|
||||||
|
packFn: func(p *packer, v reflect.Value, f packs.Flags) {},
|
||||||
|
emptyFn: isEmpty,
|
||||||
|
keyable: false}
|
||||||
|
strPacker := kindPacker{
|
||||||
|
packFn: func(p *packer, v reflect.Value, f packs.Flags) {},
|
||||||
|
keyable: true,
|
||||||
|
emptyFn: isEmpty}
|
||||||
|
objPacker := kindPacker{
|
||||||
|
packFn: func(p *packer, v reflect.Value, f packs.Flags) {},
|
||||||
|
keyable: false,
|
||||||
|
emptyFn: noEmpty}
|
||||||
|
ptrPacker := kindPacker{
|
||||||
|
packFn: func(p *packer, v reflect.Value, f packs.Flags) {},
|
||||||
|
keyable: false,
|
||||||
|
emptyFn: noEmpty}
|
||||||
|
|
||||||
|
return kindPackers{
|
||||||
|
/* Invalid */ notPacker,
|
||||||
|
/* Bool */ boolPacker,
|
||||||
|
/* Int */ intPacker,
|
||||||
|
/* Int8 */ intPacker,
|
||||||
|
/* Int16 */ intPacker,
|
||||||
|
/* Int32 */ intPacker,
|
||||||
|
/* Int64 */ intPacker,
|
||||||
|
/* Uint */ uintPacker,
|
||||||
|
/* Uint8 */ uintPacker,
|
||||||
|
/* Uint16 */ uintPacker,
|
||||||
|
/* Uint32 */ uintPacker,
|
||||||
|
/* Uint64 */ uintPacker,
|
||||||
|
/* Uintptr */ uintPacker,
|
||||||
|
/* Float32 */ floatPacker,
|
||||||
|
/* Float64 */ floatPacker,
|
||||||
|
/* Complex64 */ notPacker,
|
||||||
|
/* Complex128 */ notPacker,
|
||||||
|
/* Array */ listPacker,
|
||||||
|
/* Chan */ notPacker,
|
||||||
|
/* Func */ notPacker,
|
||||||
|
/* Interface */ ifacePacker,
|
||||||
|
/* Map */ mapPacker,
|
||||||
|
/* Pointer */ ptrPacker,
|
||||||
|
/* Slice */ listPacker,
|
||||||
|
/* String */ strPacker,
|
||||||
|
/* Struct */ objPacker,
|
||||||
|
/* UnsafePointer*/ notPacker,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// 🚀 Project ACTIVE4
|
||||||
|
// 🔗 Active Thing (activething.com) git.activething.com/go
|
||||||
|
//
|
||||||
|
// File name builder.go
|
||||||
|
// ✍️ Created by DEV
|
||||||
|
// 📅 Modified 16/06/2024
|
||||||
|
//
|
||||||
|
// 🔒 Copyright 2024 activething.com
|
||||||
|
//
|
||||||
|
// 📜 LICENSE --------------------------------------------------------------
|
||||||
|
// 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
|
||||||
|
|
||||||
|
type (
|
||||||
|
|
||||||
|
|
||||||
|
packer struct {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// 🚀 Project ACTIVE4
|
||||||
|
// 🔗 Active Thing (activething.com) git.activething.com/go
|
||||||
|
//
|
||||||
|
// File name rvalue_packer.go
|
||||||
|
// ✍️ Created by DEV
|
||||||
|
// 📅 Modified 16/06/2024
|
||||||
|
//
|
||||||
|
// 🔒 Copyright 2024 activething.com
|
||||||
|
//
|
||||||
|
// 📜 LICENSE --------------------------------------------------------------
|
||||||
|
// 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 (
|
||||||
|
"fmt"
|
||||||
|
"packs"
|
||||||
|
"reflect"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
|
||||||
|
rvaluePackFn func(p *packer, v reflect.Value, f packs.Flags)
|
||||||
|
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
func unsupportedTypePacker(_ *packer, _ reflect.Value, _ packs.Flags) {
|
||||||
|
fmt.Println("Unsiportado type")
|
||||||
|
}
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,51 @@
|
|||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// 🚀 Project ACTIVE4
|
||||||
|
// 🔗 Active Thing (activething.com) git.activething.com/go
|
||||||
|
//
|
||||||
|
// File name kind_benchmarks.go
|
||||||
|
// ✍️ Created by DEV
|
||||||
|
// 📅 Modified 16/06/2024
|
||||||
|
//
|
||||||
|
// 🔒 Copyright 2024 activething.com
|
||||||
|
//
|
||||||
|
// 📜 LICENSE --------------------------------------------------------------
|
||||||
|
// 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 test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math/rand"
|
||||||
|
"packs/pjson"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkKindWithSlice(b *testing.B) {
|
||||||
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
k := reflect.Kind(rand.Intn(26))
|
||||||
|
_ = pjson.WithSlice(k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
func BenchmarkKindWithSwith(b *testing.B) {
|
||||||
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
k := reflect.Kind(rand.Intn(26))
|
||||||
|
_ = pjson.WithSwitch(k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
Loading…
Reference in new issue