Add marshalling functions for gob

This removes a lot of the boilerplate code that comes with
(un)marshalling to gob encoding in Go.
This commit is contained in:
Daan Sprenkels 2019-08-25 17:16:12 +02:00
parent 983fa8d389
commit a6edcd222e
1 changed files with 20 additions and 0 deletions

20
gobmarsh/marshal.go Normal file
View File

@ -0,0 +1,20 @@
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)
}