.github
alerting
client
config
controller
core
docs
example
jsonpath
k8s
k8stest
metric
pattern
security
storage
util
vendor
cloud.google.com
github.com
TwinProduction
beorn7
cespare
davecgh
go-ping
gogo
golang
google
googleapis
gorilla
imdario
json-iterator
go
.codecov.yml
.gitignore
.travis.yml
Gopkg.lock
Gopkg.toml
LICENSE
README.md
adapter.go
any.go
any_array.go
any_bool.go
any_float.go
any_int32.go
any_int64.go
any_invalid.go
any_nil.go
any_number.go
any_object.go
any_str.go
any_uint32.go
any_uint64.go
build.sh
config.go
fuzzy_mode_convert_table.md
go.mod
go.sum
iter.go
iter_array.go
iter_float.go
iter_int.go
iter_object.go
iter_skip.go
iter_skip_sloppy.go
iter_skip_strict.go
iter_str.go
jsoniter.go
pool.go
reflect.go
reflect_array.go
reflect_dynamic.go
reflect_extension.go
reflect_json_number.go
reflect_json_raw_message.go
reflect_map.go
reflect_marshaler.go
reflect_native.go
reflect_optional.go
reflect_slice.go
reflect_struct_decoder.go
reflect_struct_encoder.go
stream.go
stream_float.go
stream_int.go
stream_str.go
test.sh
kballard
mattn
matttproud
miekg
modern-go
prometheus
remyoudompheng
spf13
go.etcd.io
golang.org
google.golang.org
gopkg.in
k8s.io
lukechampine.com
modernc.org
sigs.k8s.io
modules.txt
watchdog
web
.dockerignore
.gitattributes
.gitignore
Dockerfile
LICENSE.md
Makefile
README.md
config.yaml
go.mod
go.sum
main.go
279 lines
4.7 KiB
Go
279 lines
4.7 KiB
Go
package jsoniter
|
|
|
|
import (
|
|
"reflect"
|
|
"unsafe"
|
|
)
|
|
|
|
type arrayLazyAny struct {
|
|
baseAny
|
|
cfg *frozenConfig
|
|
buf []byte
|
|
err error
|
|
}
|
|
|
|
func (any *arrayLazyAny) ValueType() ValueType {
|
|
return ArrayValue
|
|
}
|
|
|
|
func (any *arrayLazyAny) MustBeValid() Any {
|
|
return any
|
|
}
|
|
|
|
func (any *arrayLazyAny) LastError() error {
|
|
return any.err
|
|
}
|
|
|
|
func (any *arrayLazyAny) ToBool() bool {
|
|
iter := any.cfg.BorrowIterator(any.buf)
|
|
defer any.cfg.ReturnIterator(iter)
|
|
return iter.ReadArray()
|
|
}
|
|
|
|
func (any *arrayLazyAny) ToInt() int {
|
|
if any.ToBool() {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func (any *arrayLazyAny) ToInt32() int32 {
|
|
if any.ToBool() {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func (any *arrayLazyAny) ToInt64() int64 {
|
|
if any.ToBool() {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func (any *arrayLazyAny) ToUint() uint {
|
|
if any.ToBool() {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func (any *arrayLazyAny) ToUint32() uint32 {
|
|
if any.ToBool() {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func (any *arrayLazyAny) ToUint64() uint64 {
|
|
if any.ToBool() {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func (any *arrayLazyAny) ToFloat32() float32 {
|
|
if any.ToBool() {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func (any *arrayLazyAny) ToFloat64() float64 {
|
|
if any.ToBool() {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func (any *arrayLazyAny) ToString() string {
|
|
return *(*string)(unsafe.Pointer(&any.buf))
|
|
}
|
|
|
|
func (any *arrayLazyAny) ToVal(val interface{}) {
|
|
iter := any.cfg.BorrowIterator(any.buf)
|
|
defer any.cfg.ReturnIterator(iter)
|
|
iter.ReadVal(val)
|
|
}
|
|
|
|
func (any *arrayLazyAny) Get(path ...interface{}) Any {
|
|
if len(path) == 0 {
|
|
return any
|
|
}
|
|
switch firstPath := path[0].(type) {
|
|
case int:
|
|
iter := any.cfg.BorrowIterator(any.buf)
|
|
defer any.cfg.ReturnIterator(iter)
|
|
valueBytes := locateArrayElement(iter, firstPath)
|
|
if valueBytes == nil {
|
|
return newInvalidAny(path)
|
|
}
|
|
iter.ResetBytes(valueBytes)
|
|
return locatePath(iter, path[1:])
|
|
case int32:
|
|
if '*' == firstPath {
|
|
iter := any.cfg.BorrowIterator(any.buf)
|
|
defer any.cfg.ReturnIterator(iter)
|
|
arr := make([]Any, 0)
|
|
iter.ReadArrayCB(func(iter *Iterator) bool {
|
|
found := iter.readAny().Get(path[1:]...)
|
|
if found.ValueType() != InvalidValue {
|
|
arr = append(arr, found)
|
|
}
|
|
return true
|
|
})
|
|
return wrapArray(arr)
|
|
}
|
|
return newInvalidAny(path)
|
|
default:
|
|
return newInvalidAny(path)
|
|
}
|
|
}
|
|
|
|
func (any *arrayLazyAny) Size() int {
|
|
size := 0
|
|
iter := any.cfg.BorrowIterator(any.buf)
|
|
defer any.cfg.ReturnIterator(iter)
|
|
iter.ReadArrayCB(func(iter *Iterator) bool {
|
|
size++
|
|
iter.Skip()
|
|
return true
|
|
})
|
|
return size
|
|
}
|
|
|
|
func (any *arrayLazyAny) WriteTo(stream *Stream) {
|
|
stream.Write(any.buf)
|
|
}
|
|
|
|
func (any *arrayLazyAny) GetInterface() interface{} {
|
|
iter := any.cfg.BorrowIterator(any.buf)
|
|
defer any.cfg.ReturnIterator(iter)
|
|
return iter.Read()
|
|
}
|
|
|
|
type arrayAny struct {
|
|
baseAny
|
|
val reflect.Value
|
|
}
|
|
|
|
func wrapArray(val interface{}) *arrayAny {
|
|
return &arrayAny{baseAny{}, reflect.ValueOf(val)}
|
|
}
|
|
|
|
func (any *arrayAny) ValueType() ValueType {
|
|
return ArrayValue
|
|
}
|
|
|
|
func (any *arrayAny) MustBeValid() Any {
|
|
return any
|
|
}
|
|
|
|
func (any *arrayAny) LastError() error {
|
|
return nil
|
|
}
|
|
|
|
func (any *arrayAny) ToBool() bool {
|
|
return any.val.Len() != 0
|
|
}
|
|
|
|
func (any *arrayAny) ToInt() int {
|
|
if any.val.Len() == 0 {
|
|
return 0
|
|
}
|
|
return 1
|
|
}
|
|
|
|
func (any *arrayAny) ToInt32() int32 {
|
|
if any.val.Len() == 0 {
|
|
return 0
|
|
}
|
|
return 1
|
|
}
|
|
|
|
func (any *arrayAny) ToInt64() int64 {
|
|
if any.val.Len() == 0 {
|
|
return 0
|
|
}
|
|
return 1
|
|
}
|
|
|
|
func (any *arrayAny) ToUint() uint {
|
|
if any.val.Len() == 0 {
|
|
return 0
|
|
}
|
|
return 1
|
|
}
|
|
|
|
func (any *arrayAny) ToUint32() uint32 {
|
|
if any.val.Len() == 0 {
|
|
return 0
|
|
}
|
|
return 1
|
|
}
|
|
|
|
func (any *arrayAny) ToUint64() uint64 {
|
|
if any.val.Len() == 0 {
|
|
return 0
|
|
}
|
|
return 1
|
|
}
|
|
|
|
func (any *arrayAny) ToFloat32() float32 {
|
|
if any.val.Len() == 0 {
|
|
return 0
|
|
}
|
|
return 1
|
|
}
|
|
|
|
func (any *arrayAny) ToFloat64() float64 {
|
|
if any.val.Len() == 0 {
|
|
return 0
|
|
}
|
|
return 1
|
|
}
|
|
|
|
func (any *arrayAny) ToString() string {
|
|
str, _ := MarshalToString(any.val.Interface())
|
|
return str
|
|
}
|
|
|
|
func (any *arrayAny) Get(path ...interface{}) Any {
|
|
if len(path) == 0 {
|
|
return any
|
|
}
|
|
switch firstPath := path[0].(type) {
|
|
case int:
|
|
if firstPath < 0 || firstPath >= any.val.Len() {
|
|
return newInvalidAny(path)
|
|
}
|
|
return Wrap(any.val.Index(firstPath).Interface())
|
|
case int32:
|
|
if '*' == firstPath {
|
|
mappedAll := make([]Any, 0)
|
|
for i := 0; i < any.val.Len(); i++ {
|
|
mapped := Wrap(any.val.Index(i).Interface()).Get(path[1:]...)
|
|
if mapped.ValueType() != InvalidValue {
|
|
mappedAll = append(mappedAll, mapped)
|
|
}
|
|
}
|
|
return wrapArray(mappedAll)
|
|
}
|
|
return newInvalidAny(path)
|
|
default:
|
|
return newInvalidAny(path)
|
|
}
|
|
}
|
|
|
|
func (any *arrayAny) Size() int {
|
|
return any.val.Len()
|
|
}
|
|
|
|
func (any *arrayAny) WriteTo(stream *Stream) {
|
|
stream.WriteVal(any.val)
|
|
}
|
|
|
|
func (any *arrayAny) GetInterface() interface{} {
|
|
return any.val.Interface()
|
|
}
|