(reader *bufio.Reader)
| 411 | } |
| 412 | |
| 413 | func readRESPArray(reader *bufio.Reader) ([]string, error) { |
| 414 | prefix, errRead := reader.ReadByte() |
| 415 | if errRead != nil { |
| 416 | return nil, errRead |
| 417 | } |
| 418 | if prefix != '*' { |
| 419 | return nil, fmt.Errorf("protocol error") |
| 420 | } |
| 421 | line, errLine := readRESPLine(reader) |
| 422 | if errLine != nil { |
| 423 | return nil, errLine |
| 424 | } |
| 425 | count, errParse := strconv.Atoi(line) |
| 426 | if errParse != nil || count < 0 { |
| 427 | return nil, fmt.Errorf("protocol error") |
| 428 | } |
| 429 | args := make([]string, 0, count) |
| 430 | for i := 0; i < count; i++ { |
| 431 | value, errString := readRESPString(reader) |
| 432 | if errString != nil { |
| 433 | return nil, errString |
| 434 | } |
| 435 | args = append(args, value) |
| 436 | } |
| 437 | return args, nil |
| 438 | } |
| 439 | |
| 440 | func readRESPString(reader *bufio.Reader) (string, error) { |
| 441 | prefix, errRead := reader.ReadByte() |
no test coverage detected