pkt-line: add packet_buf_write_len function

Add the 'packet_buf_write_len()' function which allows for writing an
arbitrary length buffer into a 'struct strbuf' and formatting it in
packet-line format.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Brandon Williams
2018-03-15 10:31:35 -07:00
committed by Junio C Hamano
parent edc9caf7e2
commit f1f4d8acf4
2 changed files with 17 additions and 0 deletions

View File

@ -215,6 +215,22 @@ void packet_buf_write(struct strbuf *buf, const char *fmt, ...)
va_end(args);
}
void packet_buf_write_len(struct strbuf *buf, const char *data, size_t len)
{
size_t orig_len, n;
orig_len = buf->len;
strbuf_addstr(buf, "0000");
strbuf_add(buf, data, len);
n = buf->len - orig_len;
if (n > LARGE_PACKET_MAX)
die("protocol error: impossibly long line");
set_packet_header(&buf->buf[orig_len], n);
packet_trace(data, len, 1);
}
int write_packetized_from_fd(int fd_in, int fd_out)
{
static char buf[LARGE_PACKET_DATA_MAX];