DecodeString decodes a length-delimited string from the stream and returns the value. io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
()
| 164 | // |
| 165 | // io.ErrUnexpectedEOF is returned if the operation would read past the end of the data. |
| 166 | func (d *Decoder) DecodeString() (string, error) { |
| 167 | if d.offset >= len(d.p) { |
| 168 | return "", io.ErrUnexpectedEOF |
| 169 | } |
| 170 | b, err := d.DecodeBytes() |
| 171 | if err != nil { |
| 172 | return "", fmt.Errorf("invalid data at byte %d: %w", d.offset, err) |
| 173 | } |
| 174 | switch d.mode { |
| 175 | case DecoderModeFast: |
| 176 | return *(*string)(unsafe.Pointer(&b)), nil //nolint: gosec // using unsafe on purpose |
| 177 | |
| 178 | default: |
| 179 | // safe mode by default |
| 180 | return string(b), nil |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | // DecodeBytes decodes a length-delimited slice of bytes from the stream and returns the value. |
| 185 | // |