Overwrite encoded Leb128 with a new value. The new value must be less than or equal to the old value to ensure that it fits the allocated space.
| 271 | // Overwrite encoded Leb128 with a new value. The new value must be less than |
| 272 | // or equal to the old value to ensure that it fits the allocated space. |
| 273 | static inline void UpdateUnsignedLeb128(uint8_t* dest, uint32_t value) { |
| 274 | const uint8_t* old_end = dest; |
| 275 | uint32_t old_value = DecodeUnsignedLeb128(&old_end); |
| 276 | DCHECK_LE(UnsignedLeb128Size(value), UnsignedLeb128Size(old_value)); |
| 277 | for (uint8_t* end = EncodeUnsignedLeb128(dest, value); end < old_end; end++) { |
| 278 | // Use longer encoding than necessary to fill the allocated space. |
| 279 | end[-1] |= 0x80; |
| 280 | end[0] = 0; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | static inline uint8_t* EncodeSignedLeb128(uint8_t* dest, int32_t value) { |
| 285 | uint32_t extra_bits = static_cast<uint32_t>(value ^ (value >> 31)) >> 6; |
no test coverage detected