Add specific GOB encoding methods
This commit is contained in:
parent
643750bc23
commit
94c0f32ae4
1 changed files with 12 additions and 2 deletions
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue