git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[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
Previous: Jeff KingNext: Jeff King
Message 4 of 11 in “What's cooking in git.git (Sep 2022, #08; Tue, 27)”
  1. Junio C HamanoSep 27, 2022
  2. Victoria DyeSep 28, 2022
  3. vd/fix-unaligned-read-index-v4, was Re: What's cooking in git.git (Sep 2022, #08; Tue, 27)Jeff King, Sep 28, 2022
  4. 1/3 pack-bitmap: make read_be32() publicJeff King, Sep 28, 2022
  5. 2/3 read-cache: read on-disk entries in byte orderJeff King, Sep 28, 2022
  6. Jeff KingSep 29, 2022
  7. Junio C HamanoSep 29, 2022
  8. 3/3 read-cache: use read_be32() in create_from_disk()Jeff King, Sep 28, 2022
  9. Junio C HamanoSep 28, 2022
  10. Ævar Arnfjörð BjarmasonSep 28, 2022
  11. Junio C HamanoSep 28, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.