2019-08-25 17:16:12 +02:00
|
|
|
package gobmarsh
|
|
|
|
|
2019-08-25 21:33:56 +02:00
|
|
|
// Easier marshalling to and from gob encoding
|
|
|
|
|
2019-08-25 17:16:12 +02:00
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/gob"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Marshal(v interface{}) ([]byte, error) {
|
|
|
|
b := new(bytes.Buffer)
|
|
|
|
err := gob.NewEncoder(b).Encode(v)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return b.Bytes(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func Unmarshal(data []byte, v interface{}) error {
|
|
|
|
b := bytes.NewBuffer(data)
|
|
|
|
return gob.NewDecoder(b).Decode(v)
|
|
|
|
}
|