-
Notifications
You must be signed in to change notification settings - Fork 0
/
extentbuilder.go
56 lines (49 loc) · 967 Bytes
/
extentbuilder.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
package gli
type Extent struct {
size int
offset int
stride int
components int
normalize bool
num int
}
type ExtentBuilder struct {
size int
start int
pos int
ext []*Extent
}
func ExtentBuild(componentsize int) ExtentBuilder {
return ExtentBuilder{
size: componentsize,
}
}
func (b ExtentBuilder) Skip(components int) ExtentBuilder {
b.pos += components * b.size
return b
}
func (b ExtentBuilder) Size(componentsize int) ExtentBuilder {
b.size = componentsize
return b
}
func (b ExtentBuilder) Ext(components int, ext *Extent) ExtentBuilder {
b.ext = append(b.ext, ext)
ext.size = b.size
ext.offset = b.pos
ext.components = components
b.pos += components
return b
}
func (b ExtentBuilder) Seq(num int) ExtentBuilder {
if num > 0 {
stride := b.pos - b.start
for _, ext := range b.ext {
ext.num = num
ext.stride = stride
}
b.pos += stride * num
}
b.start = b.pos
b.ext = b.ext[:0]
return b
}