-
Notifications
You must be signed in to change notification settings - Fork 342
/
range.go
47 lines (42 loc) · 1004 Bytes
/
range.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
45
46
47
package committed
import "google.golang.org/protobuf/proto"
// Range represents a range of sorted Keys
type Range struct {
ID ID
MinKey Key
MaxKey Key
EstimatedSize uint64 // EstimatedSize estimated Range size in bytes
Count int64
Tombstone bool
}
func (r Range) Copy() *Range {
return &Range{
ID: r.ID,
MinKey: r.MinKey.Copy(),
MaxKey: r.MaxKey.Copy(),
EstimatedSize: r.EstimatedSize,
Count: r.Count,
Tombstone: r.Tombstone,
}
}
func MarshalRange(r Range) ([]byte, error) {
return proto.Marshal(&RangeData{
MinKey: r.MinKey,
MaxKey: r.MaxKey,
EstimatedSize: r.EstimatedSize,
Count: r.Count,
})
}
func UnmarshalRange(b []byte) (Range, error) {
var p RangeData
err := proto.Unmarshal(b, &p)
if err != nil {
return Range{}, err
}
return Range{
MinKey: p.MinKey,
MaxKey: p.MaxKey,
EstimatedSize: p.EstimatedSize,
Count: p.Count,
}, nil
}