2020-10-02 03:56:13 +00:00
|
|
|
package cbor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
2020-10-25 08:38:55 +00:00
|
|
|
func Marshal(dst io.Writer, v interface{}) error {
|
2020-10-02 03:56:13 +00:00
|
|
|
e := Encoder(dst)
|
|
|
|
err := e.Encode(v)
|
|
|
|
returnEncoderToPool(e)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-10-25 08:38:55 +00:00
|
|
|
func Unmarshal(dst interface{}, data io.Reader) error {
|
2020-10-02 03:56:13 +00:00
|
|
|
d := Decoder(data)
|
|
|
|
err := d.Decode(dst)
|
|
|
|
returnDecoderToPool(d)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-10-25 08:38:55 +00:00
|
|
|
func MustMarshal(dst io.Writer, v interface{}) {
|
2020-10-02 03:56:13 +00:00
|
|
|
err := Marshal(dst, v)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-25 08:38:55 +00:00
|
|
|
func MustUnmarshal(dst interface{}, data io.Reader) {
|
2020-10-02 03:56:13 +00:00
|
|
|
err := Unmarshal(dst, data)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|