1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-15 22:50:24 +02:00

suport encode interface

This commit is contained in:
Tao Wen
2017-01-26 00:25:17 +08:00
parent ce1a1f1e98
commit 9b587c0f22
10 changed files with 188 additions and 21 deletions

View File

@ -1,5 +1,9 @@
package jsoniter
import (
"unsafe"
)
type arrayLazyAny struct {
baseAny
buf []byte
@ -231,3 +235,26 @@ func (any *arrayLazyAny) IterateArray() (func() (Any, bool), bool) {
}
}, true
}
func (any *arrayLazyAny) GetArray() []Any {
any.fillCache()
return any.cache
}
func (any *arrayLazyAny) SetArray(newList []Any) bool {
any.fillCache()
any.cache = newList
return true
}
func (any *arrayLazyAny) WriteTo(stream *Stream) {
if len(any.remaining) == len(any.buf) {
// nothing has been parsed yet
stream.WriteRaw(*(*string)(unsafe.Pointer(&any.buf)))
} else {
any.fillCache()
stream.WriteVal(any.cache)
}
}