mirror of
https://github.com/kubernetes/sample-controller.git
synced 2026-02-15 00:07:52 +08:00
Automatic merge from submit-queue. Manually cherrypick #65034 to 1.10 Manually cherrypicking #65034. Using hack/cherry_pick_pull.sh to cherrypick is difficult because that requires cherrypicking #63059 first. This PR imported the latest jsoniterator library so that case sensitivity during unmarhsaling is optional. The PR also set Kubernetes json serializer to be case sensitive. Fix #64612. ```release-notes Kubernetes json deserializer is now case-sensitive to restore compatibility with pre-1.8 servers. If your config files contains fields with wrong case, the config files will be now invalid. ``` Kubernetes-commit: 32ac1c9073b132b8ba18aa830f46b77dcceb0723
124 lines
2.6 KiB
Go
124 lines
2.6 KiB
Go
package jsoniter
|
|
|
|
import (
|
|
"io"
|
|
"unsafe"
|
|
)
|
|
|
|
type numberLazyAny struct {
|
|
baseAny
|
|
cfg *frozenConfig
|
|
buf []byte
|
|
err error
|
|
}
|
|
|
|
func (any *numberLazyAny) ValueType() ValueType {
|
|
return NumberValue
|
|
}
|
|
|
|
func (any *numberLazyAny) MustBeValid() Any {
|
|
return any
|
|
}
|
|
|
|
func (any *numberLazyAny) LastError() error {
|
|
return any.err
|
|
}
|
|
|
|
func (any *numberLazyAny) ToBool() bool {
|
|
return any.ToFloat64() != 0
|
|
}
|
|
|
|
func (any *numberLazyAny) ToInt() int {
|
|
iter := any.cfg.BorrowIterator(any.buf)
|
|
defer any.cfg.ReturnIterator(iter)
|
|
val := iter.ReadInt()
|
|
if iter.Error != nil && iter.Error != io.EOF {
|
|
any.err = iter.Error
|
|
}
|
|
return val
|
|
}
|
|
|
|
func (any *numberLazyAny) ToInt32() int32 {
|
|
iter := any.cfg.BorrowIterator(any.buf)
|
|
defer any.cfg.ReturnIterator(iter)
|
|
val := iter.ReadInt32()
|
|
if iter.Error != nil && iter.Error != io.EOF {
|
|
any.err = iter.Error
|
|
}
|
|
return val
|
|
}
|
|
|
|
func (any *numberLazyAny) ToInt64() int64 {
|
|
iter := any.cfg.BorrowIterator(any.buf)
|
|
defer any.cfg.ReturnIterator(iter)
|
|
val := iter.ReadInt64()
|
|
if iter.Error != nil && iter.Error != io.EOF {
|
|
any.err = iter.Error
|
|
}
|
|
return val
|
|
}
|
|
|
|
func (any *numberLazyAny) ToUint() uint {
|
|
iter := any.cfg.BorrowIterator(any.buf)
|
|
defer any.cfg.ReturnIterator(iter)
|
|
val := iter.ReadUint()
|
|
if iter.Error != nil && iter.Error != io.EOF {
|
|
any.err = iter.Error
|
|
}
|
|
return val
|
|
}
|
|
|
|
func (any *numberLazyAny) ToUint32() uint32 {
|
|
iter := any.cfg.BorrowIterator(any.buf)
|
|
defer any.cfg.ReturnIterator(iter)
|
|
val := iter.ReadUint32()
|
|
if iter.Error != nil && iter.Error != io.EOF {
|
|
any.err = iter.Error
|
|
}
|
|
return val
|
|
}
|
|
|
|
func (any *numberLazyAny) ToUint64() uint64 {
|
|
iter := any.cfg.BorrowIterator(any.buf)
|
|
defer any.cfg.ReturnIterator(iter)
|
|
val := iter.ReadUint64()
|
|
if iter.Error != nil && iter.Error != io.EOF {
|
|
any.err = iter.Error
|
|
}
|
|
return val
|
|
}
|
|
|
|
func (any *numberLazyAny) ToFloat32() float32 {
|
|
iter := any.cfg.BorrowIterator(any.buf)
|
|
defer any.cfg.ReturnIterator(iter)
|
|
val := iter.ReadFloat32()
|
|
if iter.Error != nil && iter.Error != io.EOF {
|
|
any.err = iter.Error
|
|
}
|
|
return val
|
|
}
|
|
|
|
func (any *numberLazyAny) ToFloat64() float64 {
|
|
iter := any.cfg.BorrowIterator(any.buf)
|
|
defer any.cfg.ReturnIterator(iter)
|
|
val := iter.ReadFloat64()
|
|
if iter.Error != nil && iter.Error != io.EOF {
|
|
any.err = iter.Error
|
|
}
|
|
return val
|
|
}
|
|
|
|
func (any *numberLazyAny) ToString() string {
|
|
return *(*string)(unsafe.Pointer(&any.buf))
|
|
}
|
|
|
|
func (any *numberLazyAny) WriteTo(stream *Stream) {
|
|
stream.Write(any.buf)
|
|
}
|
|
|
|
func (any *numberLazyAny) GetInterface() interface{} {
|
|
iter := any.cfg.BorrowIterator(any.buf)
|
|
defer any.cfg.ReturnIterator(iter)
|
|
return iter.Read()
|
|
}
|