Encode variant intger and return the size
| 477 | |
| 478 | // Encode variant intger and return the size |
| 479 | inline void EncodeInteger(butil::IOBufAppender* out, uint8_t msb, |
| 480 | uint8_t prefix_size, uint32_t value) { |
| 481 | uint8_t max_prefix_value = (1 << prefix_size) - 1; |
| 482 | if (value < max_prefix_value) { |
| 483 | msb |= value; |
| 484 | out->push_back(msb); |
| 485 | return; |
| 486 | } |
| 487 | value -= max_prefix_value; |
| 488 | msb |= max_prefix_value; |
| 489 | out->push_back(msb); |
| 490 | for (; value >= 128; ) { |
| 491 | const uint8_t c = (value & 0x7f) | 0x80; |
| 492 | value >>= 7; |
| 493 | out->push_back(c); |
| 494 | } |
| 495 | out->push_back(static_cast<uint8_t>(value)); |
| 496 | } |
| 497 | |
| 498 | // Static variables |
| 499 | static HuffmanTree* s_huffman_tree = NULL; |
no test coverage detected