| 741 | |
| 742 | #[inline(always)] |
| 743 | pub fn read_var_u32(&mut self) -> Result<u32, Error> { |
| 744 | let b0 = self.value_at(self.cursor)? as u32; |
| 745 | if b0 < 0x80 { |
| 746 | self.move_next(1); |
| 747 | return Ok(b0); |
| 748 | } |
| 749 | |
| 750 | let b1 = self.value_at(self.cursor + 1)? as u32; |
| 751 | let mut encoded = (b0 & 0x7F) | ((b1 & 0x7F) << 7); |
| 752 | if b1 < 0x80 { |
| 753 | self.move_next(2); |
| 754 | return Ok(encoded); |
| 755 | } |
| 756 | |
| 757 | let b2 = self.value_at(self.cursor + 2)? as u32; |
| 758 | encoded |= (b2 & 0x7F) << 14; |
| 759 | if b2 < 0x80 { |
| 760 | self.move_next(3); |
| 761 | return Ok(encoded); |
| 762 | } |
| 763 | |
| 764 | let b3 = self.value_at(self.cursor + 3)? as u32; |
| 765 | encoded |= (b3 & 0x7F) << 21; |
| 766 | if b3 < 0x80 { |
| 767 | self.move_next(4); |
| 768 | return Ok(encoded); |
| 769 | } |
| 770 | |
| 771 | let b4 = self.value_at(self.cursor + 4)? as u32; |
| 772 | encoded |= b4 << 28; |
| 773 | self.move_next(5); |
| 774 | Ok(encoded) |
| 775 | } |
| 776 | |
| 777 | // ============ UINT64 (TypeId = 13) ============ |
| 778 | |