a6edcd222e
This removes a lot of the boilerplate code that comes with (un)marshalling to gob encoding in Go.
21 lines
342 B
Go
21 lines
342 B
Go
package gobmarsh
|
|
|
|
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)
|
|
}
|