package notify

import (
	"bytes"
	"encoding/gob"
)

func Register(data interface{}) {
	gob.Register(data)
}

func RegisterAll(data []interface{}) {
	for _, v := range data {
		gob.Register(v)
	}
}
func encode(src interface{}) ([]byte, error) {
	var buf bytes.Buffer
	enc := gob.NewEncoder(&buf)
	err := enc.Encode(&src)
	return buf.Bytes(), err
}

func Encode(src interface{}) ([]byte, error) {
	return encode(src)
}

func Decode(src []byte) (interface{}, error) {
	dec := gob.NewDecoder(bytes.NewReader(src))
	var dst interface{}
	err := dec.Decode(&dst)
	return dst, err
}
