git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Victoria Dye <vdye@github.com>
Cc: Junio C Hamano <gitster@pobox.com>,
	git@vger.kernel.org, Phillip Wood <phillip.wood123@gmail.com>
Subject: [PATCH 1/3] pack-bitmap: make read_be32() public
Date: Wed, 28 Sep 2022 00:19:51 -0400	[thread overview]
Message-ID: <YzPLZ3J+FDibgF7o@coredump.intra.peff.net> (raw)
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


  reply	other threads:[~2022-09-28  4:20 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-27 21:11 What's cooking in git.git (Sep 2022, #08; Tue, 27) Junio C Hamano
2022-09-28  1:52 ` Victoria Dye
2022-09-28  4:18   ` vd/fix-unaligned-read-index-v4, was " Jeff King
2022-09-28  4:19     ` Jeff King [this message]
2022-09-28  4:21     ` [PATCH 2/3] read-cache: read on-disk entries in byte order Jeff King
2022-09-29 11:27       ` Jeff King
2022-09-29 15:47         ` Junio C Hamano
2022-09-28  4:23     ` [PATCH 3/3] read-cache: use read_be32() in create_from_disk() Jeff King
2022-09-28 16:41     ` vd/fix-unaligned-read-index-v4, was Re: What's cooking in git.git (Sep 2022, #08; Tue, 27) Junio C Hamano
2022-09-28 17:01       ` Ævar Arnfjörð Bjarmason
2022-09-28 17:41         ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YzPLZ3J+FDibgF7o@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=phillip.wood123@gmail.com \
    --cc=vdye@github.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).