DecodeBool decodes a boolean value from the stream and returns the value. io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
()
| 146 | // |
| 147 | // io.ErrUnexpectedEOF is returned if the operation would read past the end of the data. |
| 148 | func (d *Decoder) DecodeBool() (b bool, err error) { |
| 149 | if d.offset >= len(d.p) { |
| 150 | return false, io.ErrUnexpectedEOF |
| 151 | } |
| 152 | v, n, err := DecodeVarint(d.p[d.offset:]) |
| 153 | if err != nil { |
| 154 | return false, fmt.Errorf("invalid data at byte %d: %w", d.offset, err) |
| 155 | } |
| 156 | if n == 0 { |
| 157 | return false, fmt.Errorf("invalid data at byte %d: %w", d.offset, ErrInvalidVarintData) |
| 158 | } |
| 159 | d.offset += n |
| 160 | return (v != 0), nil |
| 161 | } |
| 162 | |
| 163 | // DecodeString decodes a length-delimited string from the stream and returns the value. |
| 164 | // |