go-json/json.go

18 lines
333 B
Go
Raw Normal View History

2020-04-19 13:51:22 +03:00
package json
2020-04-21 08:19:50 +03:00
import "bytes"
2020-04-19 13:51:22 +03:00
func Marshal(v interface{}) ([]byte, error) {
2020-04-21 08:19:50 +03:00
var b *bytes.Buffer
enc := NewEncoder(b)
defer enc.release()
return enc.encodeForMarshal(v)
2020-04-19 13:51:22 +03:00
}
2020-04-22 07:06:52 +03:00
func Unmarshal(data []byte, v interface{}) error {
src := make([]byte, len(data))
copy(src, data)
var dec Decoder
return dec.decodeForUnmarshal(src, v)
}