代码拉取完成,页面将自动刷新
package memstore
import (
"bytes"
"encoding/gob"
"io"
"time"
)
// why?
// on the future we may change how these encoders/decoders
// and we may need different method for store and other for entry.
func init() {
gob.Register(Store{})
gob.Register(Entry{})
gob.Register(time.Time{})
}
// GobEncode accepts a store and writes
// as series of bytes to the "w" writer.
func GobEncode(store Store, w io.Writer) error {
enc := gob.NewEncoder(w)
err := enc.Encode(store)
return err
}
// GobSerialize same as GobEncode but it returns
// the bytes using a temp buffer.
func GobSerialize(store Store) ([]byte, error) {
w := new(bytes.Buffer)
err := GobEncode(store, w)
return w.Bytes(), err
}
// GobEncodeEntry accepts an entry and writes
// as series of bytes to the "w" writer.
func GobEncodeEntry(entry Entry, w io.Writer) error {
enc := gob.NewEncoder(w)
err := enc.Encode(entry)
return err
}
// GobSerializeEntry same as GobEncodeEntry but it returns
// the bytes using a temp buffer.
func GobSerializeEntry(entry Entry) ([]byte, error) {
w := new(bytes.Buffer)
err := GobEncodeEntry(entry, w)
return w.Bytes(), err
}
// GobDecode accepts a series of bytes and returns
// the store.
func GobDecode(b []byte) (store Store, err error) {
dec := gob.NewDecoder(bytes.NewBuffer(b))
// no reference because of:
// gob: decoding into local type *memstore.Store, received remote type Entry
err = dec.Decode(&store)
return
}
// GobDecodeEntry accepts a series of bytes and returns
// the entry.
func GobDecodeEntry(b []byte) (entry Entry, err error) {
dec := gob.NewDecoder(bytes.NewBuffer(b))
err = dec.Decode(&entry)
return
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。