diff options
author | Joshua Haberman <joshua@reverberate.org> | 2009-03-01 22:58:38 -0800 |
---|---|---|
committer | Joshua Haberman <joshua@reverberate.org> | 2009-03-01 22:58:38 -0800 |
commit | 73ab650ad1968b13abbf1869c4739cfdf2752671 (patch) | |
tree | 63858d7e7600dac4640bdef3974bb07f3d59b2fc /pbstream.c | |
parent | 14624e34d82468773516a4ff3eb3a4d6bc030658 (diff) |
Added function for skipping data.
Diffstat (limited to 'pbstream.c')
-rw-r--r-- | pbstream.c | 41 |
1 files changed, 37 insertions, 4 deletions
@@ -29,8 +29,7 @@ static pbstream_status_t get_v_uint64_t(char **buf, uint64_t *val) { - uint8_t* ptr = (uint8_t*)*buf; - uint32_t b; + uint8_t *ptr = (uint8_t*)*buf, b; uint32_t part0 = 0, part1 = 0, part2 = 0; /* From the original proto2 implementation. */ @@ -52,10 +51,29 @@ done: return PBSTREAM_STATUS_OK; } +static pbstream_status_t skip_v_uint64_t(char **buf) +{ + uint8_t *ptr = (uint8_t*)*buf, b; + b = *(ptr++); if (!(b & 0x80)) goto done; + b = *(ptr++); if (!(b & 0x80)) goto done; + b = *(ptr++); if (!(b & 0x80)) goto done; + b = *(ptr++); if (!(b & 0x80)) goto done; + b = *(ptr++); if (!(b & 0x80)) goto done; + b = *(ptr++); if (!(b & 0x80)) goto done; + b = *(ptr++); if (!(b & 0x80)) goto done; + b = *(ptr++); if (!(b & 0x80)) goto done; + b = *(ptr++); if (!(b & 0x80)) goto done; + b = *(ptr++); if (!(b & 0x80)) goto done; + return PBSTREAM_ERROR_UNTERMINATED_VARINT; + +done: + *buf = (char*)ptr; + return PBSTREAM_STATUS_OK; +} + static pbstream_status_t get_v_uint32_t(char **buf, uint32_t *val) { - uint8_t* ptr = (uint8_t*)*buf; - uint32_t b; + uint8_t *ptr = (uint8_t*)*buf, b; uint32_t result; /* From the original proto2 implementation. */ @@ -72,6 +90,21 @@ done: return PBSTREAM_STATUS_OK; } +static pbstream_status_t skip_v_uint32_t(char **buf) +{ + uint8_t *ptr = (uint8_t*)*buf, b; + b = *(ptr++); if (!(b & 0x80)) goto done; + b = *(ptr++); if (!(b & 0x80)) goto done; + b = *(ptr++); if (!(b & 0x80)) goto done; + b = *(ptr++); if (!(b & 0x80)) goto done; + b = *(ptr++); if (!(b & 0x80)) goto done; + return PBSTREAM_ERROR_UNTERMINATED_VARINT; + +done: + *buf = (char*)ptr; + return PBSTREAM_STATUS_OK; +} + static pbstream_status_t get_f_uint32_t(char **buf, uint32_t *val) { uint8_t *b = (uint8_t*)*buf; |