prysm-pulse/beacon-chain/db/kv/encoding.go
Preston Van Loon e203f66fe0 DB Improvements: Snappy compression, remove some unnecessary batch / goroutines (#4125)
* do not use batch for SaveAttestations
* use snappy compression
* Encode / decode everything with snappy
* Add snappy migration path
* batch is probably fine...
* fix test
* gofmt
* Merge branch 'master' of github.com:prysmaticlabs/prysm into remove-batch-attestations
* add sanity check
* remove that thing
* gaz
* Merge branch 'master' of github.com:prysmaticlabs/prysm into remove-batch-attestations
2019-11-27 06:32:56 +00:00

35 lines
656 B
Go

package kv
import (
"github.com/gogo/protobuf/proto"
"github.com/golang/snappy"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
)
func decode(data []byte, dst proto.Message) error {
if featureconfig.Get().EnableSnappyDBCompression {
var err error
data, err = snappy.Decode(nil, data)
if err != nil {
return err
}
}
if err := proto.Unmarshal(data, dst); err != nil {
return err
}
return nil
}
func encode(msg proto.Message) ([]byte, error) {
enc, err := proto.Marshal(msg)
if err != nil {
return nil, err
}
if !featureconfig.Get().EnableSnappyDBCompression {
return enc, nil
}
return snappy.Encode(nil, enc), nil
}