CmdToService returns the service command representing command c.
(c Cmd)
| 25 | |
| 26 | // CmdToService returns the service command representing command c. |
| 27 | func CmdToService(c Cmd) (*Command, error) { |
| 28 | out := &Command{ |
| 29 | Name: c.CmdName(), |
| 30 | Thread: c.Thread(), |
| 31 | } |
| 32 | |
| 33 | if api := c.API(); api != nil { |
| 34 | out.API = &path.API{ID: path.NewID(id.ID(api.ID()))} |
| 35 | } |
| 36 | |
| 37 | for _, p := range c.CmdParams() { |
| 38 | param := &Parameter{ |
| 39 | Name: p.Name, |
| 40 | Value: box.NewValue(p.Get()), |
| 41 | } |
| 42 | if p.Constants > 0 { |
| 43 | param.Constants = out.API.ConstantSet(p.Constants) |
| 44 | } |
| 45 | out.Parameters = append(out.Parameters, param) |
| 46 | } |
| 47 | |
| 48 | if p := c.CmdResult(); p != nil { |
| 49 | out.Result = &Parameter{ |
| 50 | Name: p.Name, |
| 51 | Value: box.NewValue(p.Get()), |
| 52 | } |
| 53 | if p.Constants >= 0 { |
| 54 | out.Result.Constants = out.API.ConstantSet(p.Constants) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | return out, nil |
| 59 | } |
| 60 | |
| 61 | // ServiceToCmd returns the command built from c. |
| 62 | func ServiceToCmd(a arena.Arena, c *Command) (Cmd, error) { |