Add specific GOB encoding methods

This commit is contained in:
Tobie Morgan Hitchcock 2016-09-19 14:44:56 +01:00
parent 643750bc23
commit 94c0f32ae4

View file

@ -128,13 +128,23 @@ func init() {
// Encode encodes a data object into a GOB. // Encode encodes a data object into a GOB.
func Encode(src interface{}) (dst []byte) { func Encode(src interface{}) (dst []byte) {
return ToGOB(src)
}
// Decode decodes a GOB into a data object.
func Decode(src []byte, dst interface{}) {
FromGOB(src, dst)
}
// ToGOB encodes a data object into a GOB.
func ToGOB(src interface{}) (dst []byte) {
buf := bytes.NewBuffer(nil) buf := bytes.NewBuffer(nil)
gob.NewEncoder(buf).Encode(src) gob.NewEncoder(buf).Encode(src)
return buf.Bytes() return buf.Bytes()
} }
// Decode decodes a GOB into a data object. // FromGOB decodes a GOB into a data object.
func Decode(src []byte, dst interface{}) { func FromGOB(src []byte, dst interface{}) {
buf := bytes.NewBuffer(src) buf := bytes.NewBuffer(src)
gob.NewDecoder(buf).Decode(dst) gob.NewDecoder(buf).Decode(dst)
} }