-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gob.go
42 lines (35 loc) · 877 Bytes
/
gob.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package serializing
import (
"bytes"
"encoding/gob"
)
func init() {
RegisterAlgo("gob", func(m map[string]interface{}) Algorithm {
return GOB{}
})
}
// GOB supports GOB serialization of arbitrary data structures
type GOB struct {
Algorithm
}
// Name identifies the Algorithm as a string for exporting configurations
func (GOB) Name() string {
return "gob"
}
// Config converts an Algorthim's internal configuration into a map for export
func (GOB) Config() map[string]interface{} {
return nil
}
// Serialize ::: GOB
func (g GOB) Serialize(value interface{}) ([]byte, error) {
var hold bytes.Buffer
enc := gob.NewEncoder(&hold)
err := enc.Encode(value)
return hold.Bytes(), err
}
// Unserialize ::: GOB
func (g GOB) Unserialize(source []byte, dest interface{}) error {
hold := bytes.NewBuffer(source)
dec := gob.NewDecoder(hold)
return dec.Decode(dest)
}