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.
38 lines
682 B
Go
38 lines
682 B
Go
3 years ago
|
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 Decode(src []byte) (interface{}, error) {
|
||
|
dec := gob.NewDecoder(bytes.NewReader(src))
|
||
|
var dst interface{}
|
||
|
err := dec.Decode(&dst)
|
||
|
return dst, err
|
||
|
}
|
||
|
|
||
|
func (nmsg *SMsg) Decode() (interface{}, error) {
|
||
|
return Decode([]byte(nmsg.Value))
|
||
|
}
|
||
|
|
||
|
func (nmsg *CMsg) Decode() (interface{}, error) {
|
||
|
return Decode([]byte(nmsg.Value))
|
||
|
}
|