Return the number of key-value pairs and the offset of the first pair, for the map starting at `offset`. Returns `None` if not a map.
(buf: &[u8], offset: usize)
| 426 | /// Return the number of key-value pairs and the offset of the first pair, |
| 427 | /// for the map starting at `offset`. Returns `None` if not a map. |
| 428 | pub fn map_header(buf: &[u8], offset: usize) -> Option<(usize, usize)> { |
| 429 | let tag = get(buf, offset)?; |
| 430 | match tag { |
| 431 | 0x80..=0x8f => Some(((tag & 0x0f) as usize, offset + 1)), |
| 432 | MAP16 => Some((read_u16_be(buf, offset + 1)? as usize, offset + 3)), |
| 433 | MAP32 => Some((read_u32_be(buf, offset + 1)? as usize, offset + 5)), |
| 434 | _ => None, |
| 435 | } |
| 436 | } |
| 437 | |
| 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. |