forked from mirror/go-json
23 lines
407 B
Go
23 lines
407 B
Go
package json
|
|
|
|
import "bytes"
|
|
|
|
func Marshal(v interface{}) ([]byte, error) {
|
|
var b *bytes.Buffer
|
|
enc := NewEncoder(b)
|
|
bytes, err := enc.encodeForMarshal(v)
|
|
if err != nil {
|
|
enc.release()
|
|
return nil, err
|
|
}
|
|
enc.release()
|
|
return bytes, nil
|
|
}
|
|
|
|
func Unmarshal(data []byte, v interface{}) error {
|
|
src := make([]byte, len(data))
|
|
copy(src, data)
|
|
var dec Decoder
|
|
return dec.decodeForUnmarshal(src, v)
|
|
}
|