-
Notifications
You must be signed in to change notification settings - Fork 0
/
versioning.go
51 lines (43 loc) · 915 Bytes
/
versioning.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
package decs
type versionTracker struct {
cbusID string
state map[string]*version
}
type version struct {
current uint
lastHandled uint
}
func newVersion() *version {
return &version{}
}
func newVersionTracker(cbusID string) *versionTracker {
return &versionTracker{
cbusID: cbusID,
state: make(map[string]*version),
}
}
func (vt *versionTracker) version(cbusID string) *version {
v := vt.state[cbusID]
if v == nil {
v = newVersion()
vt.state[cbusID] = v
}
return v
}
func (vt *versionTracker) next() uint {
v := vt.version(vt.cbusID)
v.current++
return v.current
}
func (vt *versionTracker) alreadyHandled(cmd *command) bool {
v := vt.version(cmd.BusId)
handled := v.lastHandled >= cmd.Version_
if !handled {
v.lastHandled = cmd.Version_
}
return handled
}
func (vt *versionTracker) update(cbusID string, version uint) {
v := vt.state[cbusID]
v.lastHandled = version
}