Returns the number of bytes needed to encode the value in unsigned LEB128.
| 199 | |
| 200 | // Returns the number of bytes needed to encode the value in unsigned LEB128. |
| 201 | static inline uint32_t UnsignedLeb128Size(uint32_t data) { |
| 202 | // bits_to_encode = (data != 0) ? 32 - CLZ(x) : 1 // 32 - CLZ(data | 1) |
| 203 | // bytes = ceil(bits_to_encode / 7.0); // (6 + bits_to_encode) / 7 |
| 204 | uint32_t x = 6 + 32 - CLZ(data | 1U); |
| 205 | // Division by 7 is done by (x * 37) >> 8 where 37 = ceil(256 / 7). |
| 206 | // This works for 0 <= x < 256 / (7 * 37 - 256), i.e. 0 <= x <= 85. |
| 207 | return (x * 37) >> 8; |
| 208 | } |
| 209 | |
| 210 | static inline bool IsLeb128Terminator(const uint8_t* ptr) { |
| 211 | return *ptr <= 0x7f; |
no test coverage detected