32 lines
524 B
Go
32 lines
524 B
Go
package fs
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/gob"
|
|
"io"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func DefaultMarshalValue[V any](value V) (io.Reader, error) {
|
|
var buf bytes.Buffer
|
|
encoder := gob.NewEncoder(&buf)
|
|
|
|
if err := encoder.Encode(value); err != nil {
|
|
return nil, errors.WithStack(err)
|
|
}
|
|
|
|
return &buf, nil
|
|
}
|
|
|
|
func DefaultUnmarshalValue[V any](d io.Reader) (V, error) {
|
|
var value V
|
|
encoder := gob.NewDecoder(d)
|
|
|
|
if err := encoder.Decode(&value); err != nil {
|
|
return *new(V), errors.WithStack(err)
|
|
}
|
|
|
|
return value, nil
|
|
}
|