From 94c0f32ae422e890b7128f6115dc91f9c6f74aeb Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Mon, 19 Sep 2016 14:44:56 +0100 Subject: [PATCH] Add specific GOB encoding methods --- util/pack/pack.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/util/pack/pack.go b/util/pack/pack.go index 115893c5..20c963f0 100644 --- a/util/pack/pack.go +++ b/util/pack/pack.go @@ -128,13 +128,23 @@ func init() { // Encode encodes a data object into a GOB. 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) gob.NewEncoder(buf).Encode(src) return buf.Bytes() } -// Decode decodes a GOB into a data object. -func Decode(src []byte, dst interface{}) { +// FromGOB decodes a GOB into a data object. +func FromGOB(src []byte, dst interface{}) { buf := bytes.NewBuffer(src) gob.NewDecoder(buf).Decode(dst) }