-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.go
44 lines (36 loc) · 1.14 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package raftbadger
import (
"bytes"
"encoding/binary"
"github.com/hashicorp/go-msgpack/codec"
)
// decodeMsgpack 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)
}
// encodeMsgpack 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
}
// bytesToUint64 converts bytes to an uint64
func bytesToUint64(b []byte) uint64 {
return binary.BigEndian.Uint64(b)
}
// uint64ToBytes converts a uint64 to []byte
func uint64ToBytes(u uint64) []byte {
buf := make([]byte, 8)
binary.BigEndian.PutUint64(buf, u)
return buf
}
type nullLogger struct{}
func (l *nullLogger) Errorf(msg string, args ...interface{}) {}
func (l *nullLogger) Warningf(msg string, args ...interface{}) {}
func (l *nullLogger) Infof(msg string, args ...interface{}) {}
func (l *nullLogger) Debugf(msg string, args ...interface{}) {}