[PATCH 1/3] pack-bitmap: make read_be32() public
- From
Jeff King <peff@peff.net>
- Date
- Sep 28, 2022, 04:19 UTC
- Message-ID
- <YzPLZ3J+FDibgF7o@coredump.intra.peff.net>
- In-Reply-To
- <YzPLBN09zzlTdNgc@coredump.intra.peff.net>
It's a handy shortcut for other in-order parsers of binary formats. We'll drag along read_be8(), as well, for consistency, and add read_be16() to round out the set.
We'll also switch the signature to take a void pointer. This lets it be used equally well with either signed or unsigned byte strings (the get_be functions all cast to unsigned under the hood, so we don't care either way at this level).
Signed-off-by: Jeff King <peff@peff.net> --- compat/bswap.h | 22 ++++++++++++++++++++++ pack-bitmap.c | 12 ------------ 2 files changed, 22 insertions(+), 12 deletions(-)
diff --git a/compat/bswap.h b/compat/bswap.h index 512f6f4b99..6cda2cc50d 100644 --- a/compat/bswap.h +++ b/compat/bswap.h @@ -190,4 +190,26 @@ static inline void put_be64(void *ptr, uint64_t value) p[7] = value >> 0; } +static inline uint32_t read_be32(const void *vbuffer, size_t *pos) +{ + const unsigned char *buffer = vbuffer; + uint32_t result = get_be32(buffer + *pos); + (*pos) += sizeof(result); + return result; +} + +static inline uint16_t read_be16(const void *vbuffer, size_t *pos) +{ + const unsigned char *buffer = vbuffer; + uint16_t result = get_be16(buffer + *pos); + (*pos) += sizeof(result); + return result; +} + +static inline uint8_t read_u8(const void *vbuffer, size_t *pos) +{ + const unsigned char *buffer = vbuffer; + return buffer[(*pos)++]; +} + #endif /* COMPAT_BSWAP_H */ diff --git a/pack-bitmap.c b/pack-bitmap.c index 440407f1be..51d1e79b70 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -242,18 +242,6 @@ static struct stored_bitmap *store_bitmap(struct bitmap_index *index, return stored; } -static inline uint32_t read_be32(const unsigned char *buffer, size_t *pos) -{ - uint32_t result = get_be32(buffer + *pos); - (*pos) += sizeof(result); - return result; -} - -static inline uint8_t read_u8(const unsigned char *buffer, size_t *pos) -{ - return buffer[(*pos)++]; -} - #define MAX_XOR_OFFSET 160 static int nth_bitmap_object_oid(struct bitmap_index *index,
-- 2.38.0.rc2.615.g4fac75f9e3