-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd_dereference_data.go
59 lines (49 loc) · 1.24 KB
/
cmd_dereference_data.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
package flowstate
import (
"fmt"
"strconv"
"strings"
)
func DereferenceData(stateCtx *StateCtx, data *Data, annotation string) *DereferenceDataCommand {
return &DereferenceDataCommand{
StateCtx: stateCtx,
Data: data,
Annotation: annotation,
}
}
type DereferenceDataCommand struct {
command
StateCtx *StateCtx
Data *Data
Annotation string
}
var DefaultDereferenceDataDoer = DoerFunc(func(cmd0 Command) error {
cmd, ok := cmd0.(*DereferenceDataCommand)
if !ok {
return ErrCommandNotSupported
}
serializedData := cmd.StateCtx.Current.Annotations[cmd.Annotation]
if serializedData == "" {
return fmt.Errorf("data is not serialized")
}
splits := strings.SplitN(serializedData, ":", 3)
if len(splits) != 3 {
return fmt.Errorf("data is not serialized correctly")
}
if splits[0] != "data" {
return fmt.Errorf("data is not serialized correctly")
}
if splits[1] == "" {
return fmt.Errorf("serialized data ID is empty")
}
if splits[2] == "" {
return fmt.Errorf("serialized data revision is empty")
}
dRev, err := strconv.ParseInt(splits[2], 10, 64)
if err != nil {
return fmt.Errorf("serialized data revision is not integer: %w", err)
}
cmd.Data.ID = DataID(splits[1])
cmd.Data.Rev = dRev
return nil
})