// Encode prepares a result and writes it to an io.Writer func (rs *Result) Encode(wr io.Writer) error { msg, seg, err := capnp.NewMessage(capnp.SingleSegment(nil)) if err != nil { return err } root, err := protocol.NewRootResult(seg) if err != nil { return err } err = rs.SubResult.encode(&root, seg) if err != nil { return err } root.SetId(rs.Id) root.SetStatus(protocol.Status(rs.Status)) root.SetAction(protocol.Action(rs.SubResult.getAction())) err = capnp.NewEncoder(wr).Encode(msg) if err != nil { return err } return nil }
// Encode prepares a command to be issued over the wire. func (c *Command) Encode(wr io.Writer) error { msg, seg, err := capnp.NewMessage(capnp.SingleSegment(nil)) if err != nil { return err } root, err := protocol.NewRootCommand(seg) if err != nil { return err } err = c.SubCommand.encode(&root, seg) if err != nil { return err } root.SetId(c.Id) root.SetAction(protocol.Action(c.SubCommand.getAction())) err = capnp.NewEncoder(wr).Encode(msg) if err != nil { return err } return nil }