Created
September 29, 2018 07:38
-
-
Save nickelpro/4d873abb260589d5f03baa837011c0cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char *enc_varint(char *dest, uint32_t source) { | |
for(; source >= 0x80; dest++, source >>= 7) { | |
*dest = 0x80 | (source & 0x7F); | |
} | |
*dest = source & 0x7F; | |
return ++dest; | |
} | |
char *dec_varint(int32_t *dest, char *source) { | |
for(; *(unsigned char *) source & 0x80; source++, *(uint32_t *) dest <<= 7) { | |
*(uint32_t *) dest |= *source & 0x7F; | |
} | |
*(uint32_t *) dest |= *source & 0x7F; | |
return ++source; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment