-
Notifications
You must be signed in to change notification settings - Fork 8
/
results.go
66 lines (59 loc) · 1.7 KB
/
results.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
// Package rplidar implements a general rplidar LIDAR as a camera.
package rplidar
import "go.viam.com/rplidar/gen"
type (
// Result describes the status of an rplidar operation.
Result uint32
// ResultError is a result that encodes an error.
ResultError struct {
Result
}
)
// The set of possible results.
var (
ResultOk = Result(gen.RESULT_OK)
ResultAlreadyDone = Result(gen.RESULT_ALREADY_DONE)
ResultInvalidData = Result(gen.RESULT_INVALID_DATA)
ResultOpFail = Result(gen.RESULT_OPERATION_FAIL)
ResultOpTimeout = Result(gen.RESULT_OPERATION_TIMEOUT)
ResultOpStop = Result(gen.RESULT_OPERATION_STOP)
ResultOpNotSupported = Result(gen.RESULT_OPERATION_NOT_SUPPORT)
ResultFormatNotSupported = Result(gen.RESULT_FORMAT_NOT_SUPPORT)
ResultInsufficientMemory = Result(gen.RESULT_INSUFFICIENT_MEMORY)
)
// Failed returns an error if the result is that of a failure.
func (r Result) Failed() error {
if uint64(r)&gen.RESULT_FAIL_BIT == 0 {
return nil
}
return ResultError{r}
}
// String returns a human readable version of a result.
func (r Result) String() string {
switch r {
case ResultOk:
return "Ok"
case ResultAlreadyDone:
return "AlreadyDone"
case ResultInvalidData:
return "InvalidData"
case ResultOpFail:
return "OpFail"
case ResultOpTimeout:
return "OpTimeout"
case ResultOpStop:
return "OpStop"
case ResultOpNotSupported:
return "OpNotSupported"
case ResultFormatNotSupported:
return "FormatNotSupported"
case ResultInsufficientMemory:
return "InsufficientMemory"
default:
return "Unknown"
}
}
// Error returns the error as a human readable string.
func (r ResultError) Error() string {
return r.String()
}