-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathrdy.go
47 lines (38 loc) · 968 Bytes
/
rdy.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
package nsq
import (
"bufio"
"strconv"
"github.com/pkg/errors"
)
// Rdy represents the RDY command.
type Rdy struct {
// Count is the number of messages that a consumer is ready to accept.
Count int
}
// Name returns the name of the command in order to satisfy the Command
// interface.
func (c Rdy) Name() string {
return "RDY"
}
// Write serializes the command to the given buffered output, satisfies the
// Command interface.
func (c Rdy) Write(w *bufio.Writer) (err error) {
if _, err = w.WriteString("RDY "); err != nil {
err = errors.Wrap(err, "writing RDY command")
return
}
b := strconv.AppendUint(make([]byte, 0, 64), uint64(c.Count), 10)
b = append(b, '\n')
if _, err = w.Write(b); err != nil {
err = errors.Wrap(err, "writint RDY count")
return
}
return
}
func readRdy(line string) (cmd Rdy, err error) {
if cmd.Count, err = strconv.Atoi(line); err != nil {
err = errors.Wrap(err, "reading RDY count")
return
}
return
}