diff options
author | Joshua Haberman <joshua@reverberate.org> | 2009-07-29 20:36:08 -0700 |
---|---|---|
committer | Joshua Haberman <joshua@reverberate.org> | 2009-07-29 20:36:08 -0700 |
commit | 5fa6912da86d8f264a23c9545c1a877a31603a49 (patch) | |
tree | ffd5d921ee047e2bd6d29508dcf98d99d89d4267 | |
parent | cd3d737d5e14937fb88b80979ab4743a5c3e7fb6 (diff) |
Fleshed out serialization functions a bit more.
-rw-r--r-- | src/upb_serialize.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/upb_serialize.h b/src/upb_serialize.h index 39dc79c..de5e57d 100644 --- a/src/upb_serialize.h +++ b/src/upb_serialize.h @@ -33,6 +33,14 @@ extern "C" { INLINE upb_status_t upb_put_v_uint64_t(uint8_t *buf, uint8_t *end, uint64_t val, uint8_t **outbuf) { + do { + uint8_t byte = val & 0x7f; + val >>= 7; + if(val) byte |= 0x80; + if(buf >= end) return UPB_STATUS_NEED_MORE_DATA; + *buf++ = byte; + } while(val); + *outbuf = buf; return UPB_STATUS_OK; } @@ -47,6 +55,10 @@ INLINE upb_status_t upb_put_v_uint32_t(uint8_t *buf, uint8_t *end, INLINE upb_status_t upb_put_f_uint32_t(uint8_t *buf, uint8_t *end, uint32_t val, uint8_t **outbuf) { + uint8_t *uint32_end = buf + sizeof(uint32_t); + if(uint32_end > end) return UPB_STATUS_NEED_MORE_DATA; + *(uint32_t*)buf = val; + *outbuf = uint32_end; return UPB_STATUS_OK; } @@ -54,6 +66,10 @@ INLINE upb_status_t upb_put_f_uint32_t(uint8_t *buf, uint8_t *end, INLINE upb_status_t upb_put_f_uint64_t(uint8_t *buf, uint8_t *end, uint64_t val, uint8_t **outbuf) { + uint8_t *uint64_end = buf + sizeof(uint64_t); + if(uint64_end > end) return UPB_STATUS_NEED_MORE_DATA; + *(uint64_t*)buf = val; + *outbuf = uint64_end; return UPB_STATUS_OK; } |