-
Notifications
You must be signed in to change notification settings - Fork 110
/
encoder.go
55 lines (48 loc) · 1.8 KB
/
encoder.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
package inject
import (
"context"
"go.viam.com/rdk/components/encoder"
)
// Encoder is an injected encoder.
type Encoder struct {
encoder.Encoder
DoFunc func(ctx context.Context, cmd map[string]interface{}) (map[string]interface{}, error)
ResetPositionFunc func(ctx context.Context, extra map[string]interface{}) error
GetPositionFunc func(ctx context.Context,
positionType *encoder.PositionType,
extra map[string]interface{},
) (float64, encoder.PositionType, error)
GetPropertiesFunc func(ctx context.Context, extra map[string]interface{}) (map[encoder.Feature]bool, error)
}
// ResetPosition calls the injected Zero or the real version.
func (e *Encoder) ResetPosition(ctx context.Context, extra map[string]interface{}) error {
if e.ResetPositionFunc == nil {
return e.Encoder.ResetPosition(ctx, extra)
}
return e.ResetPositionFunc(ctx, extra)
}
// GetPosition calls the injected GetPosition or the real version.
func (e *Encoder) GetPosition(
ctx context.Context,
positionType *encoder.PositionType,
extra map[string]interface{},
) (float64, encoder.PositionType, error) {
if e.GetPositionFunc == nil {
return e.Encoder.GetPosition(ctx, positionType, extra)
}
return e.GetPositionFunc(ctx, positionType, extra)
}
// GetProperties calls the injected Properties or the real version.
func (e *Encoder) GetProperties(ctx context.Context, extra map[string]interface{}) (map[encoder.Feature]bool, error) {
if e.GetPropertiesFunc == nil {
return e.Encoder.GetProperties(ctx, extra)
}
return e.GetPropertiesFunc(ctx, extra)
}
// DoCommand calls the injected DoCommand or the real version.
func (e *Encoder) DoCommand(ctx context.Context, cmd map[string]interface{}) (map[string]interface{}, error) {
if e.DoFunc == nil {
return e.Encoder.DoCommand(ctx, cmd)
}
return e.DoFunc(ctx, cmd)
}