ReadStatusWithLines reads a status, arguments, and a set of text lines.
()
| 216 | |
| 217 | // ReadStatusWithLines reads a status, arguments, and a set of text lines. |
| 218 | func (conn *PktlineConnection) ReadStatusWithLines() (int, []string, []string, error) { |
| 219 | args := make([]string, 0, 100) |
| 220 | lines := make([]string, 0, 100) |
| 221 | status := 0 |
| 222 | seenDelim := false |
| 223 | seenStatus := false |
| 224 | for { |
| 225 | s, pktLen, err := conn.pl.ReadPacketTextWithLength() |
| 226 | if err != nil { |
| 227 | return 0, nil, nil, errors.NewProtocolError(tr.Tr.Get("error reading packet"), err) |
| 228 | } |
| 229 | switch { |
| 230 | case pktLen == 0: |
| 231 | if !seenStatus { |
| 232 | return 0, nil, nil, errors.NewProtocolError(tr.Tr.Get("no status seen"), nil) |
| 233 | } |
| 234 | return status, args, lines, nil |
| 235 | case seenDelim: |
| 236 | lines = append(lines, s) |
| 237 | case !seenStatus: |
| 238 | ok := false |
| 239 | if strings.HasPrefix(s, "status ") { |
| 240 | status, err = strconv.Atoi(s[7:]) |
| 241 | ok = err == nil |
| 242 | } |
| 243 | if !ok { |
| 244 | return 0, nil, nil, errors.NewProtocolError(tr.Tr.Get("expected status line, got %q", s), err) |
| 245 | } |
| 246 | seenStatus = true |
| 247 | case pktLen == 1: |
| 248 | if seenDelim { |
| 249 | return 0, nil, nil, errors.NewProtocolError(tr.Tr.Get("unexpected delimiter packet"), nil) |
| 250 | } |
| 251 | seenDelim = true |
| 252 | default: |
| 253 | args = append(args, s) |
| 254 | } |
| 255 | } |
| 256 | } |
no test coverage detected