pkt-line: extract set_packet_header()
Extracted set_packet_header() function converts an integer to a 4 byte hex string. Make this function locally available so that other pkt-line functions could use it. Signed-off-by: Lars Schneider <larsxschneider@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
81c634e94f
commit
2f60bdd1a8
19
pkt-line.c
19
pkt-line.c
@ -97,10 +97,20 @@ void packet_buf_flush(struct strbuf *buf)
|
|||||||
strbuf_add(buf, "0000", 4);
|
strbuf_add(buf, "0000", 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define hex(a) (hexchar[(a) & 15])
|
static void set_packet_header(char *buf, const int size)
|
||||||
static void format_packet(struct strbuf *out, const char *fmt, va_list args)
|
|
||||||
{
|
{
|
||||||
static char hexchar[] = "0123456789abcdef";
|
static char hexchar[] = "0123456789abcdef";
|
||||||
|
|
||||||
|
#define hex(a) (hexchar[(a) & 15])
|
||||||
|
buf[0] = hex(size >> 12);
|
||||||
|
buf[1] = hex(size >> 8);
|
||||||
|
buf[2] = hex(size >> 4);
|
||||||
|
buf[3] = hex(size);
|
||||||
|
#undef hex
|
||||||
|
}
|
||||||
|
|
||||||
|
static void format_packet(struct strbuf *out, const char *fmt, va_list args)
|
||||||
|
{
|
||||||
size_t orig_len, n;
|
size_t orig_len, n;
|
||||||
|
|
||||||
orig_len = out->len;
|
orig_len = out->len;
|
||||||
@ -111,10 +121,7 @@ static void format_packet(struct strbuf *out, const char *fmt, va_list args)
|
|||||||
if (n > LARGE_PACKET_MAX)
|
if (n > LARGE_PACKET_MAX)
|
||||||
die("protocol error: impossibly long line");
|
die("protocol error: impossibly long line");
|
||||||
|
|
||||||
out->buf[orig_len + 0] = hex(n >> 12);
|
set_packet_header(&out->buf[orig_len], n);
|
||||||
out->buf[orig_len + 1] = hex(n >> 8);
|
|
||||||
out->buf[orig_len + 2] = hex(n >> 4);
|
|
||||||
out->buf[orig_len + 3] = hex(n);
|
|
||||||
packet_trace(out->buf + orig_len + 4, n - 4, 1);
|
packet_trace(out->buf + orig_len + 4, n - 4, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user