-
Notifications
You must be signed in to change notification settings - Fork 23
/
runs.go
77 lines (65 loc) · 1.72 KB
/
runs.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
package parser
import (
"fmt"
)
type RunInfo struct {
Type string
Level int
FromOffset int64
ToOffset int64
Length int64
CompressedLength int64
IsSparse bool
ClusterSize int64
Reader string
}
func (self RunInfo) String() string {
prefix := ""
for i := 0; i < self.Level; i++ {
prefix += " "
}
properties := ""
if self.IsSparse {
properties += "Sparse "
}
if self.CompressedLength != 0 {
properties += fmt.Sprintf("Compressed Length %v", self.CompressedLength)
}
return fmt.Sprintf("%s %d %v: FileOffset %v -> DiskOffset %v (Length %v, %v Cluster %v) Delegate %v",
prefix, self.Level,
self.Type, self.FromOffset, self.ToOffset, self.Length,
properties, self.ClusterSize, self.Reader)
}
func DebugRawRuns(runs []*Run) {
fmt.Printf("Runs ....\n")
for idx, r := range runs {
fmt.Printf("%d Disk Offset %d RelativeUrnOffset %d (Length %d)\n",
idx, r.Offset, r.RelativeUrnOffset, r.Length)
}
}
func DebugRuns(stream RangeReaderAt, level int) []*RunInfo {
result := make([]*RunInfo, 0)
switch t := stream.(type) {
case *MappedReader:
result = append(result, &RunInfo{
Type: "MappedReader",
Level: level,
FromOffset: t.FileOffset,
ToOffset: t.TargetOffset,
Length: t.Length,
CompressedLength: t.CompressedLength,
IsSparse: t.IsSparse,
ClusterSize: t.ClusterSize,
Reader: fmt.Sprintf("%T", t.Reader),
})
reader_t, ok := t.Reader.(RangeReaderAt)
if ok {
result = append(result, DebugRuns(reader_t, level+1)...)
}
case *RangeReader:
for _, r := range t.runs {
result = append(result, DebugRuns(r, level)...)
}
}
return result
}