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.
starmap/transfer.go

39 lines
711 B
Go

4 years ago
package starmap
import (
"bytes"
"encoding/gob"
)
func init() {
gob.Register(&basicReply{})
}
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 encodeMap(src StarMap) ([]byte, error) {
var buf bytes.Buffer
enc := gob.NewEncoder(&buf)
err := enc.Encode(&src)
return buf.Bytes(), err
}
func decodeMap(src []byte) (StarMap, error) {
dec := gob.NewDecoder(bytes.NewReader(src))
var dst StarMap
err := dec.Decode(&dst)
return dst, err
}