ReadMapLen reads the length of the map type. If responding to the array type (RespArray/RespSet/RespPush), it must be a multiple of 2 and return n/2. Other types will return an error.
()
| 696 | // it must be a multiple of 2 and return n/2. |
| 697 | // Other types will return an error. |
| 698 | func (r *Reader) ReadMapLen() (int, error) { |
| 699 | line, err := r.ReadLine() |
| 700 | if err != nil { |
| 701 | return 0, err |
| 702 | } |
| 703 | switch line[0] { |
| 704 | case RespMap: |
| 705 | return replyLen(line) |
| 706 | case RespArray, RespSet, RespPush: |
| 707 | // Some commands and RESP2 protocol may respond to array types. |
| 708 | n, err := replyLen(line) |
| 709 | if err != nil { |
| 710 | return 0, err |
| 711 | } |
| 712 | if n%2 != 0 { |
| 713 | return 0, fmt.Errorf("redis: the length of the array must be a multiple of 2, got: %d", n) |
| 714 | } |
| 715 | return n / 2, nil |
| 716 | default: |
| 717 | return 0, fmt.Errorf("redis: can't parse map reply: %.100q", line) |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | // DiscardNext read and discard the data represented by the next line. |
| 722 | func (r *Reader) DiscardNext() error { |
no test coverage detected