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.
45 lines
768 B
Go
45 lines
768 B
Go
2 years ago
|
package notify
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"encoding/gob"
|
||
|
)
|
||
|
|
||
|
func Register(data interface{}) {
|
||
|
gob.Register(data)
|
||
|
}
|
||
|
|
||
|
func RegisterName(name string, data interface{}) {
|
||
|
gob.RegisterName(name, data)
|
||
|
}
|
||
|
|
||
|
func RegisterAll(data []interface{}) {
|
||
|
for _, v := range data {
|
||
|
gob.Register(v)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func RegisterNames(data map[string]interface{}) {
|
||
|
for k, v := range data {
|
||
|
gob.RegisterName(k, 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
|
||
|
}
|