2021-12-03 02:44:21 +00:00
|
|
|
package database
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/gob"
|
|
|
|
)
|
|
|
|
|
2021-12-03 03:15:48 +00:00
|
|
|
func PogrebPut(db KeyDB, name []byte, obj interface{}) {
|
2021-12-03 02:44:21 +00:00
|
|
|
var resGob bytes.Buffer
|
|
|
|
resEnc := gob.NewEncoder(&resGob)
|
|
|
|
err := resEnc.Encode(obj)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
err = db.Put(name, resGob.Bytes())
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-03 03:15:48 +00:00
|
|
|
func PogrebGet(db KeyDB, name []byte, obj interface{}) bool {
|
2021-12-03 02:44:21 +00:00
|
|
|
resBytes, err := db.Get(name)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
if resBytes == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
resGob := bytes.NewBuffer(resBytes)
|
|
|
|
resDec := gob.NewDecoder(resGob)
|
|
|
|
err = resDec.Decode(obj)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|