You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
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
|
|
|
|
}
|