1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-12 22:47:42 +02:00

add Any GetInterface

This commit is contained in:
Tao Wen 2017-01-26 15:44:10 +08:00
parent 97472ecd96
commit 9abc2f52b0
9 changed files with 46 additions and 0 deletions

View File

@ -18,6 +18,7 @@ type Any interface {
SetArray(newList []Any) bool
GetObject() map[string]Any
SetObject(map[string]Any) bool
GetInterface() interface{}
WriteTo(stream *Stream)
Parse() *Iterator
}

View File

@ -271,3 +271,8 @@ func (any *arrayLazyAny) WriteTo(stream *Stream) {
stream.WriteVal(any.cache)
}
}
func (any *arrayLazyAny) GetInterface() interface{} {
any.fillCache()
return any.cache
}

View File

@ -44,6 +44,10 @@ func (any *trueAny) Parse() *Iterator {
return nil
}
func (any *trueAny) GetInterface() interface{} {
return true
}
type falseAny struct {
baseAny
}
@ -87,3 +91,7 @@ func (any *falseAny) WriteTo(stream *Stream) {
func (any *falseAny) Parse() *Iterator {
return nil
}
func (any *falseAny) GetInterface() interface{} {
return false
}

View File

@ -74,3 +74,8 @@ func (any *floatLazyAny) ToString() string {
func (any *floatLazyAny) WriteTo(stream *Stream) {
stream.Write(any.buf)
}
func (any *floatLazyAny) GetInterface() interface{} {
any.fillCache()
return any.cache
}

View File

@ -76,6 +76,11 @@ func (any *intLazyAny) WriteTo(stream *Stream) {
stream.Write(any.buf)
}
func (any *intLazyAny) GetInterface() interface{} {
any.fillCache()
return any.cache
}
type intAny struct {
baseAny
err error
@ -121,3 +126,7 @@ func (any *intAny) WriteTo(stream *Stream) {
func (any *intAny) Parse() *Iterator {
return nil
}
func (any *intAny) GetInterface() interface{} {
return any.val
}

View File

@ -46,3 +46,7 @@ func (any *invalidAny) Get(path ...interface{}) Any {
func (any *invalidAny) Parse() *Iterator {
return nil
}
func (any *invalidAny) GetInterface() interface{} {
return nil
}

View File

@ -43,3 +43,7 @@ func (any *nilAny) WriteTo(stream *Stream) {
func (any *nilAny) Parse() *Iterator {
return nil
}
func (any *nilAny) GetInterface() interface{} {
return nil
}

View File

@ -292,3 +292,8 @@ func (any *objectLazyAny) WriteTo(stream *Stream) {
stream.WriteVal(any.cache)
}
}
func (any *objectLazyAny) GetInterface() interface{} {
any.fillCache()
return any.cache
}

View File

@ -101,3 +101,8 @@ func (any *stringLazyAny) ToString() string {
func (any *stringLazyAny) WriteTo(stream *Stream) {
stream.Write(any.buf)
}
func (any *stringLazyAny) GetInterface() interface{} {
any.fillCache()
return any.cache
}