-
Notifications
You must be signed in to change notification settings - Fork 4
/
api_control_directory.go
91 lines (72 loc) · 1.96 KB
/
api_control_directory.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
81
82
83
84
85
86
87
88
89
90
package ledger
import (
"github.com/insolar/assured-ledger/ledger-core/ledger/jet"
"github.com/insolar/assured-ledger/ledger-core/vanilla/throw"
)
type ControlLocator StorageLocator
const MaxControlChapterID = MaxChapterID>>1
func NewControlLocator(chapterID ChapterID, ofs uint32) ControlLocator {
switch {
case chapterID == 0:
panic(throw.IllegalValue())
case chapterID > MaxControlChapterID:
panic(throw.IllegalValue())
case ofs > MaxChapterOffset:
panic(throw.IllegalValue())
}
return ControlLocator(chapterID) << 24 | ControlLocator(ofs)
}
func NewDropControlLocator(id jet.ExactID, chapterID ChapterID, ofs uint64) ControlLocator {
switch {
case chapterID == 0:
panic(throw.IllegalValue())
case chapterID > MaxChapterID:
panic(throw.IllegalValue())
case id == 0:
panic(throw.IllegalValue())
case ofs > MaxChapterOffset:
panic(throw.IllegalValue())
}
return ControlLocator(id)<<47 | ControlLocator(chapterID) << 24 | ControlLocator(ofs)
}
func (v ControlLocator) IsZero() bool {
return v == 0
}
func (v ControlLocator) ExactID() jet.ExactID {
return jet.ExactID(v >> 47)
}
func (v ControlLocator) ChapterID() ChapterID {
return ChapterID(v >> 24) & MaxChapterID
}
func (v ControlLocator) ChapterOffset() uint32 {
return uint32(v) & MaxChapterOffset
}
func (v ControlLocator) Offset() uint64 {
return uint64(v) & 0x7FFF_FFFF_FFFF
}
/************************************/
func NewDropOrdinal(id jet.ExactID, ordinal Ordinal) DropOrdinal {
switch {
case id.IsZero():
panic(throw.IllegalValue())
case ordinal == 0:
panic(throw.IllegalValue())
}
return DropOrdinal(id)<<32 | DropOrdinal(ordinal)
}
func NewNoDropOrdinal(ordinal Ordinal) DropOrdinal {
if ordinal == 0 {
panic(throw.IllegalValue())
}
return DropOrdinal(ordinal)
}
type DropOrdinal uint64
func (v DropOrdinal) Ordinal() Ordinal {
return Ordinal(v)
}
func (v DropOrdinal) ExactID() jet.ExactID {
return jet.ExactID(v>>32)
}
func (v DropOrdinal) IsZero() bool {
return v == 0
}