Guest User

Untitled

a guest
Jun 24th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #pragma once
  2. #include <stdint.h>
  3. #include <array.h>
  4.  
  5. // read variable length quantity
  6. uint32_t _vlq_read(const uint8_t *&out) {
  7. uint32_t val = 0;
  8. for (;;) {
  9. const uint8_t c = *(out++);
  10. val = (val << 7) | (c & 0x7f);
  11. if ((c & 0x80) == 0) {
  12. break;
  13. }
  14. }
  15. return val;
  16. }
  17.  
  18. // write variable length quantity
  19. void _vlq_write(uint8_t *&out, uint32_t val) {
  20. std::array<uint8_t, 16> data;
  21. int32_t i = 0;
  22. for (; val; ++i) {
  23. data[i] = val & 0x7f;
  24. val >>= 7;
  25. }
  26. do {
  27. --i;
  28. *(out++) = data[i] | (i ? 0x80 : 0x00);
  29. } while (i > 0);
  30. }
Add Comment
Please, Sign In to add comment