-
Notifications
You must be signed in to change notification settings - Fork 9
/
utils.go
58 lines (49 loc) · 1.28 KB
/
utils.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
package simconnect
import (
"errors"
"fmt"
"time"
simconnect_data "github.com/JRascagneres/Simconnect-Go/simconnect-data"
)
func derefDataType(fieldType string) (uint32, error) {
var dataType uint32
switch fieldType {
case "int32", "bool":
dataType = simconnect_data.DATATYPE_INT32
case "int64":
dataType = simconnect_data.DATATYPE_INT64
case "float32":
dataType = simconnect_data.DATATYPE_FLOAT32
case "float64":
dataType = simconnect_data.DATATYPE_FLOAT64
case "[8]byte":
dataType = simconnect_data.DATATYPE_STRING8
case "[32]byte":
dataType = simconnect_data.DATATYPE_STRING32
case "[64]byte":
dataType = simconnect_data.DATATYPE_STRING64
case "[128]byte":
dataType = simconnect_data.DATATYPE_STRING128
case "[256]byte":
dataType = simconnect_data.DATATYPE_STRING256
case "[260]byte":
dataType = simconnect_data.DATATYPE_STRING260
default:
return 0, fmt.Errorf("DATATYPE not implemented: %s", fieldType)
}
return dataType, nil
}
func retryFunc(maxRetryCount int, waitDuration time.Duration, dataFunc func() (bool, error)) error {
numAttempts := 1
for {
shouldRetry, _ := dataFunc()
if !shouldRetry {
return nil
}
numAttempts++
if numAttempts >= maxRetryCount {
return errors.New("timeout exceeded err")
}
time.Sleep(waitDuration)
}
}