| 958 | |
| 959 | #[inline(always)] |
| 960 | pub fn read_utf8_string(&mut self, len: usize) -> Result<String, Error> { |
| 961 | self.check_bound(len)?; |
| 962 | let src = &self.bf[self.cursor..self.cursor + len]; |
| 963 | // Rust is the only runtime that checks UTF-8 string payloads by default; other runtimes |
| 964 | // preserve their platform replacement behavior for invalid byte sequences. |
| 965 | let string = |
| 966 | std::str::from_utf8(src).map_err(|_| Error::encoding_error("invalid UTF-8 string"))?; |
| 967 | let string = string.to_owned(); |
| 968 | self.move_next(len); |
| 969 | Ok(string) |
| 970 | } |
| 971 | |
| 972 | #[inline(always)] |
| 973 | pub fn read_utf8_string_unchecked(&mut self, len: usize) -> Result<String, Error> { |