| 1038 | |
| 1039 | #[inline(always)] |
| 1040 | pub fn read_var_u36_small(&mut self) -> Result<u64, Error> { |
| 1041 | // Keep this API panic-free even if cursor is externally set past buffer end. |
| 1042 | self.check_bound(0)?; |
| 1043 | let start = self.cursor; |
| 1044 | let slice = self.slice_after_cursor(); |
| 1045 | |
| 1046 | if slice.len() >= 8 { |
| 1047 | // here already check bound |
| 1048 | let bulk = self.read_u64()?; |
| 1049 | let mut result = bulk & 0x7F; |
| 1050 | let mut read_idx = start; |
| 1051 | |
| 1052 | if (bulk & 0x80) != 0 { |
| 1053 | read_idx += 1; |
| 1054 | result |= (bulk >> 1) & 0x3F80; |
| 1055 | if (bulk & 0x8000) != 0 { |
| 1056 | read_idx += 1; |
| 1057 | result |= (bulk >> 2) & 0x1FC000; |
| 1058 | if (bulk & 0x800000) != 0 { |
| 1059 | read_idx += 1; |
| 1060 | result |= (bulk >> 3) & 0xFE00000; |
| 1061 | if (bulk & 0x80000000) != 0 { |
| 1062 | read_idx += 1; |
| 1063 | result |= (bulk >> 4) & 0xFF0000000; |
| 1064 | } |
| 1065 | } |
| 1066 | } |
| 1067 | } |
| 1068 | self.cursor = read_idx + 1; |
| 1069 | return Ok(result); |
| 1070 | } |
| 1071 | |
| 1072 | let mut result = 0u64; |
| 1073 | let mut shift = 0; |
| 1074 | while self.cursor < self.bf.len() { |
| 1075 | let b = self.read_u8_uncheck(); |
| 1076 | result |= ((b & 0x7F) as u64) << shift; |
| 1077 | if (b & 0x80) == 0 { |
| 1078 | break; |
| 1079 | } |
| 1080 | shift += 7; |
| 1081 | if shift >= 36 { |
| 1082 | return Err(Error::encode_error("var_u36_small overflow")); |
| 1083 | } |
| 1084 | } |
| 1085 | Ok(result) |
| 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | #[allow(clippy::needless_lifetimes)] |