-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
60 lines (54 loc) · 1.53 KB
/
config.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
package goteafiles
import (
"reflect"
)
type TeaFileConfig func(*TeaFile)
func WithDataType(typ reflect.Type) TeaFileConfig {
// TODO populate time section if there is time types in the
// data type
return func (tf *TeaFile) {
tf.dataType = typ
itemSection := ItemSection{}
itemSection.Info.ItemSize = int32(typ.Size())
itemSection.Info.FieldCount = int32(typ.NumField())
itemSection.Info.ItemTypeName = typ.Name()
for i := 0; i < typ.NumField(); i++ {
dataField := typ.Field(i)
itemField := ItemSectionField{}
itemField.Name = dataField.Name
itemField.Offset = int32(dataField.Offset)
itemField.Index = int32(i)
itemField.Type = kindToFieldType[dataField.Type.Kind()]
itemSection.Fields = append(itemSection.Fields, itemField)
}
tf.itemSection = &itemSection
}
}
func WithContentDescription(description string) TeaFileConfig {
return func (tf *TeaFile) {
tf.contentDescriptionSection = &ContentDescriptionSection{
ContentDescription: description,
}
}
}
func WithNameValues(nameValues map[string]interface{}) TeaFileConfig {
return func (tf *TeaFile) {
tf.nameValueSection = &NameValueSection{
NameValues: nameValues,
}
}
}
func WithTimeFields(epoch int64, ticksPerDay int64, indexes []int32) TeaFileConfig {
return func (tf *TeaFile) {
var offsets []int32
for _, idx := range indexes {
offsets = append(offsets, tf.itemSection.Fields[idx].Offset)
}
tf.timeSection = &TimeSection{
Epoch: epoch,
TicksPerDay: ticksPerDay,
Count: int32(len(offsets)),
Offsets: offsets,
}
}
}