Return the number of elements and the offset of the first element, for the array starting at `offset`. Returns `None` if not an array.
(buf: &[u8], offset: usize)
| 438 | /// Return the number of elements and the offset of the first element, |
| 439 | /// for the array starting at `offset`. Returns `None` if not an array. |
| 440 | pub fn array_header(buf: &[u8], offset: usize) -> Option<(usize, usize)> { |
| 441 | let tag = get(buf, offset)?; |
| 442 | match tag { |
| 443 | 0x90..=0x9f => Some(((tag & 0x0f) as usize, offset + 1)), |
| 444 | ARRAY16 => Some((read_u16_be(buf, offset + 1)? as usize, offset + 3)), |
| 445 | ARRAY32 => Some((read_u32_be(buf, offset + 1)? as usize, offset + 5)), |
| 446 | _ => None, |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | #[cfg(test)] |
| 451 | mod tests { |