| 111 | } |
| 112 | |
| 113 | func (rd *realDecoder) getArrayLength() (int, error) { |
| 114 | if rd.remaining() < 4 { |
| 115 | rd.off = len(rd.raw) |
| 116 | return -1, ErrInsufficientData |
| 117 | } |
| 118 | // cast to int32 first to get correct signedness for length before then |
| 119 | // casting to int for ease of interop |
| 120 | tmp := int(int32(binary.BigEndian.Uint32(rd.raw[rd.off:]))) |
| 121 | rd.off += 4 |
| 122 | if tmp < -1 { |
| 123 | return -1, errInvalidArrayLength |
| 124 | } else if tmp > rd.remaining() { |
| 125 | rd.off = len(rd.raw) |
| 126 | return -1, ErrInsufficientData |
| 127 | } else if tmp > int(MaxResponseSize) { |
| 128 | return -1, errInvalidArrayLength |
| 129 | } |
| 130 | return tmp, nil |
| 131 | } |
| 132 | |
| 133 | func (rd *realDecoder) getBool() (bool, error) { |
| 134 | b, err := rd.getInt8() |