Read a `bin` value at `*off`, advancing `*off` past it. Zero-copy — the returned slice borrows from `buf`. Returns `None` for non-bin tags or truncated input.
(buf: &'a [u8], off: &mut usize)
| 288 | /// the returned slice borrows from `buf`. Returns `None` for non-bin tags |
| 289 | /// or truncated input. |
| 290 | pub fn read_bin_advance<'a>(buf: &'a [u8], off: &mut usize) -> Option<&'a [u8]> { |
| 291 | let tag = get(buf, *off)?; |
| 292 | let (len, header) = match tag { |
| 293 | BIN8 => (get(buf, *off + 1)? as usize, 2), |
| 294 | BIN16 => (read_u16_be(buf, *off + 1)? as usize, 3), |
| 295 | BIN32 => (read_u32_be(buf, *off + 1)? as usize, 5), |
| 296 | _ => return None, |
| 297 | }; |
| 298 | let start = *off + header; |
| 299 | let end = start + len; |
| 300 | let data = buf.get(start..end)?; |
| 301 | *off = end; |
| 302 | Some(data) |
| 303 | } |
| 304 | |
| 305 | /// Read an unsigned integer that fits in a `u32` at `*off`, advancing `*off` |
| 306 | /// past it. Accepts positive fixint, uint8, uint16, uint32. Returns `None` |
no test coverage detected