This repository has been archived by the owner on Aug 23, 2023. It is now read-only.
/
spans.go
70 lines (61 loc) · 1.33 KB
/
spans.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
package chunk
type SpanCode uint8
var ChunkSpans = [32]uint32{
1,
5,
10,
15,
20,
30,
60, // 1m
90, // 1.5m
2 * 60, // 2m
3 * 60, // 3m
5 * 60, // 5m
10 * 60, // 10m
15 * 60, // 15m
20 * 60, // 20m
30 * 60, // 30m
45 * 60, // 45m
3600, // 1h
90 * 60, // 1.5h
2 * 3600, // 2h
150 * 60, // 2.5h
3 * 3600, // 3h
4 * 3600, // 4h
5 * 3600, // 5h
6 * 3600, // 6h
7 * 3600, // 7h
8 * 3600, // 8h
9 * 3600, // 9h
10 * 3600, // 10h
12 * 3600, // 12h
15 * 3600, // 15h
18 * 3600, // 18h
24 * 3600, // 24h
}
var RevChunkSpans = make(map[uint32]SpanCode, len(ChunkSpans))
func init() {
for k, v := range ChunkSpans {
RevChunkSpans[v] = SpanCode(k)
}
}
// MaxConfigurableSpan returns the largest configurable span.
func MaxConfigurableSpan() uint32 {
return ChunkSpans[len(ChunkSpans)-1]
}
// SpanOfChunk takes a chunk and tries to determine its span.
// It returns 0 if it failed to determine the span, this could fail
// either because the given chunk is invalid or because it has an old format
func ExtractChunkSpan(chunk []byte) uint32 {
if len(chunk) < 2 {
return 0
}
if Format(chunk[0]) != FormatStandardGoTszWithSpan && Format(chunk[0]) != FormatGoTszLongWithSpan {
return 0
}
if int(chunk[1]) >= len(ChunkSpans) {
return 0
}
return ChunkSpans[SpanCode(chunk[1])]
}