// Copyright (C) 2023 Marius Schellenberger

package store

import (
	"bytes"
	"encoding/gob"
)

type gobMarshaler struct{}

func NewGOB() Marshaler {
	return gobMarshaler{}
}

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

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