-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathreply.go
44 lines (37 loc) · 839 Bytes
/
reply.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
package routeros
import (
"strings"
"github.com/go-routeros/routeros/v3/proto"
)
// Reply has all the sentences from a reply.
type Reply struct {
Re []*proto.Sentence
Done *proto.Sentence
}
func (r *Reply) String() string {
var sb strings.Builder
for _, sen := range r.Re {
sb.WriteString(sen.String())
sb.WriteRune('\n')
}
if r.Done != nil {
sb.WriteString(r.Done.String())
}
return sb.String()
}
func (r *Reply) processSentence(sen *proto.Sentence) (bool, error) {
switch sen.Word {
case reSentence:
r.Re = append(r.Re, sen)
case doneSentence:
r.Done = sen
return true, nil
case trapSentence, fatalSentence:
return sen.Word == fatalSentence, &DeviceError{sen}
case "":
// API docs say that empty sentences should be ignored
default:
return true, &UnknownReplyError{sen}
}
return false, nil
}