-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmeta.go
80 lines (64 loc) · 1.29 KB
/
meta.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package bitcask
const (
TombstoneFlagBit = 0
MetaNoExpire = 0
)
type Meta struct {
// user specified meta data
AppMeta map[string]string
AppMetaSize int
// control meta data
Expire uint64
Etag []byte
// bitmap flag
Flags uint8
}
func NewMeta(appMeta map[string]string) *Meta {
meta := &Meta{
AppMeta: nil,
AppMetaSize: 0,
Expire: MetaNoExpire,
Etag: nil,
Flags: 0,
}
return meta.SetAppMeta(appMeta)
}
func NewMetaWithTombstone() *Meta {
meta := NewMeta(nil)
return meta.SetTombstone(true)
}
func (m *Meta) SetAppMeta(appMeta map[string]string) *Meta {
// FIXME: insufficient
size := 0
for k, v := range appMeta {
size += len(k) + len(v)
}
m.AppMeta = appMeta
m.AppMetaSize = size
return m
}
func (m *Meta) SetExpire(expire uint64) *Meta {
m.Expire = expire
return m
}
func (m *Meta) SetEtag(etag []byte) *Meta {
m.Etag = etag
return m
}
func (m *Meta) SetTombstone(enable bool) *Meta {
if enable {
m.Flags |= (uint8)(1 << TombstoneFlagBit)
} else {
m.Flags &= ^(uint8)(1 << TombstoneFlagBit)
}
return m
}
func (m *Meta) AppMetadata() map[string]string {
return m.AppMeta
}
func (m *Meta) IsTombstone() bool {
return m.Flags&(1<<TombstoneFlagBit) != 0
}
func (m *Meta) AppMetaApproximateSize() int {
return m.AppMetaSize
}