From 73ab650ad1968b13abbf1869c4739cfdf2752671 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sun, 1 Mar 2009 22:58:38 -0800 Subject: Added function for skipping data. --- pbstream.c | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/pbstream.c b/pbstream.c index 2362e5c..a181128 100644 --- a/pbstream.c +++ b/pbstream.c @@ -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; -- cgit v1.2.3