// Copyright (C) 2019 Marius Schellenberger

package store

import (
	"bytes"
	"encoding/gob"
)

type gobMarshaler struct{}

func NewGOB() Marshaler {
	return gobMarshaler{}
}

func (gobMarshaler) Marshal(v interface{}) (b []byte, err error) {
	buf := new(bytes.Buffer)
	err = gob.NewEncoder(buf).Encode(v)
	b = buf.Bytes()
	return
}

func (gobMarshaler) Unmarshal(data []byte, v interface{}) error {
	return gob.NewDecoder(bytes.NewBuffer(data)).Decode(v)
}
