1 Star 0 Fork 0

WSRer/raft-pebbledb

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
util.go 987 Bytes
Copy Edit Raw Blame History
WSRer authored 2024-03-14 15:11 +08:00 . init
package raftpebbledb
import (
"bytes"
"encoding/binary"
"github.com/hashicorp/go-msgpack/v2/codec"
)
// Decode reverses the encode operation on a byte slice input
func decodeMsgPack(buf []byte, out interface{}) error {
r := bytes.NewBuffer(buf)
hd := codec.MsgpackHandle{}
dec := codec.NewDecoder(r, &hd)
return dec.Decode(out)
}
// Encode writes an encoded object to a new bytes buffer
func encodeMsgPack(in interface{}) (*bytes.Buffer, error) {
buf := bytes.NewBuffer(nil)
hd := codec.MsgpackHandle{}
enc := codec.NewEncoder(buf, &hd)
err := enc.Encode(in)
return buf, err
}
// Converts bytes to an integer
func bytesToUint64(b []byte) uint64 {
return binary.BigEndian.Uint64(b)
}
// Converts a uint to a byte slice
func uint64ToBytes(u uint64) []byte {
buf := make([]byte, 8)
binary.BigEndian.PutUint64(buf, u)
return buf
}
// FirstError returns the first error.
func FirstError(err1 error, err2 error) error {
if err1 != nil {
return err1
}
return err2
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/asphodelus_dev/raft-pebbledb.git
git@gitee.com:asphodelus_dev/raft-pebbledb.git
asphodelus_dev
raft-pebbledb
raft-pebbledb
9b41567bbf5a

Search