You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
package gob
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/gob"
|
|
|
|
|
|
|
|
"gitoa.ru/go-4devs/encoding"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
_ encoding.Unmarshal = Unmarshal
|
|
|
|
_ encoding.Marshal = Marshal
|
|
|
|
)
|
|
|
|
|
|
|
|
// Unmarshal by gob decoder.
|
|
|
|
func Unmarshal(data []byte, v interface{}) error {
|
|
|
|
buf := bytes.NewBuffer(data)
|
|
|
|
|
|
|
|
return gob.NewDecoder(buf).Decode(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Marshal by gob encoder.
|
|
|
|
func Marshal(v interface{}) ([]byte, error) {
|
|
|
|
var data bytes.Buffer
|
|
|
|
if err := gob.NewEncoder(&data).Encode(v); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return data.Bytes(), nil
|
|
|
|
}
|