-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathfin.go
48 lines (39 loc) · 994 Bytes
/
fin.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
package nsq
import (
"bufio"
"github.com/pkg/errors"
)
// Fin represents the FIN command.
type Fin struct {
// MessageID is the ID of the message to mark finished.
MessageID MessageID
}
// Name returns the name of the command in order to satisfy the Command
// interface.
func (c Fin) Name() string {
return "FIN"
}
// Write serializes the command to the given buffered output, satisfies the
// Command interface.
func (c Fin) Write(w *bufio.Writer) (err error) {
if _, err = w.WriteString("FIN "); err != nil {
err = errors.Wrap(err, "writing FIN command")
return
}
if _, err = c.MessageID.WriteTo(w); err != nil {
err = errors.Wrap(err, "writing FIN message ID")
return
}
if err = w.WriteByte('\n'); err != nil {
err = errors.Wrap(err, "writing FIN command")
return
}
return
}
func readFin(line string) (cmd Fin, err error) {
if cmd.MessageID, err = ParseMessageID(line); err != nil {
err = errors.Wrap(err, "reading FIN message ID")
return
}
return
}