Returns the number of bytes needed to encode the value in unsigned LEB128.
| 237 | |
| 238 | // Returns the number of bytes needed to encode the value in unsigned LEB128. |
| 239 | static inline uint32_t SignedLeb128Size(int32_t data) { |
| 240 | // Like UnsignedLeb128Size(), but we need one bit beyond the highest bit that differs from sign. |
| 241 | data = data ^ (data >> 31); |
| 242 | uint32_t x = 1 /* we need to encode the sign bit */ + 6 + 32 - CLZ(data | 1U); |
| 243 | return (x * 37) >> 8; |
| 244 | } |
| 245 | |
| 246 | static inline uint8_t* EncodeUnsignedLeb128(uint8_t* dest, uint32_t value) { |
| 247 | uint8_t out = value & 0x7f; |