From 9abc2f52b0dd16eb7151290535a3d413f9e67899 Mon Sep 17 00:00:00 2001 From: Tao Wen Date: Thu, 26 Jan 2017 15:44:10 +0800 Subject: [PATCH] add Any GetInterface --- feature_any.go | 1 + feature_any_array.go | 5 +++++ feature_any_bool.go | 8 ++++++++ feature_any_float.go | 5 +++++ feature_any_int.go | 9 +++++++++ feature_any_invalid.go | 4 ++++ feature_any_nil.go | 4 ++++ feature_any_object.go | 5 +++++ feature_any_string.go | 5 +++++ 9 files changed, 46 insertions(+) diff --git a/feature_any.go b/feature_any.go index 48d09bf..6541889 100644 --- a/feature_any.go +++ b/feature_any.go @@ -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 } diff --git a/feature_any_array.go b/feature_any_array.go index 1649347..105634b 100644 --- a/feature_any_array.go +++ b/feature_any_array.go @@ -270,4 +270,9 @@ func (any *arrayLazyAny) WriteTo(stream *Stream) { any.fillCache() stream.WriteVal(any.cache) } +} + +func (any *arrayLazyAny) GetInterface() interface{} { + any.fillCache() + return any.cache } \ No newline at end of file diff --git a/feature_any_bool.go b/feature_any_bool.go index 41daaa0..8586fd1 100644 --- a/feature_any_bool.go +++ b/feature_any_bool.go @@ -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 +} diff --git a/feature_any_float.go b/feature_any_float.go index 2b36463..21a48a9 100644 --- a/feature_any_float.go +++ b/feature_any_float.go @@ -73,4 +73,9 @@ 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 } \ No newline at end of file diff --git a/feature_any_int.go b/feature_any_int.go index eec2408..ead85e9 100644 --- a/feature_any_int.go +++ b/feature_any_int.go @@ -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 @@ -120,4 +125,8 @@ func (any *intAny) WriteTo(stream *Stream) { func (any *intAny) Parse() *Iterator { return nil +} + +func (any *intAny) GetInterface() interface{} { + return any.val } \ No newline at end of file diff --git a/feature_any_invalid.go b/feature_any_invalid.go index 1f08475..e586c02 100644 --- a/feature_any_invalid.go +++ b/feature_any_invalid.go @@ -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 +} diff --git a/feature_any_nil.go b/feature_any_nil.go index ec4cb98..8a447ad 100644 --- a/feature_any_nil.go +++ b/feature_any_nil.go @@ -42,4 +42,8 @@ func (any *nilAny) WriteTo(stream *Stream) { func (any *nilAny) Parse() *Iterator { return nil +} + +func (any *nilAny) GetInterface() interface{} { + return nil } \ No newline at end of file diff --git a/feature_any_object.go b/feature_any_object.go index 7b48d11..c9cb310 100644 --- a/feature_any_object.go +++ b/feature_any_object.go @@ -291,4 +291,9 @@ func (any *objectLazyAny) WriteTo(stream *Stream) { any.fillCache() stream.WriteVal(any.cache) } +} + +func (any *objectLazyAny) GetInterface() interface{} { + any.fillCache() + return any.cache } \ No newline at end of file diff --git a/feature_any_string.go b/feature_any_string.go index 9eb21ea..582cdc5 100644 --- a/feature_any_string.go +++ b/feature_any_string.go @@ -100,4 +100,9 @@ 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 } \ No newline at end of file