From 68e78fd4b86f7db2e27be4cc1c1e3d5ffe8f2b93 Mon Sep 17 00:00:00 2001 From: Dan Hirsch <thequux@thequux.com> Date: Fri, 27 Jul 2012 15:28:55 -0700 Subject: [PATCH] Finished bitwriter implementation --- src/bitwriter.c | 15 ++++++++++++++- src/hammer.h | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/bitwriter.c b/src/bitwriter.c index f307caa2..a3d6c15b 100644 --- a/src/bitwriter.c +++ b/src/bitwriter.c @@ -88,6 +88,19 @@ void h_bit_writer_put(HBitWriter* w, unsigned long long data, size_t nbits) { } -uint8_t *h_bit_writer_get_buffer(HBitWriter* w, size_t *len); +const uint8_t *h_bit_writer_get_buffer(HBitWriter* w, size_t *len) { + assert (len != NULL); + assert (w != NULL); + // Not entirely sure how to handle a non-integral number of bytes... make it an error for now + assert (w->bit_offset == 0); // BUG: change this to some sane behaviour + + *len = w->index; + return w->buf +} + +void h_bit_writer_free(HBitWriter* w) { + g_free(w->buf); + g_free(w); +} // TESTS BELOW HERE diff --git a/src/hammer.h b/src/hammer.h index 8df48a8c..26367f30 100644 --- a/src/hammer.h +++ b/src/hammer.h @@ -470,7 +470,7 @@ void h_bit_writer_put(HBitWriter* w, unsigned long long data, size_t nbits); * Must not free [w] until you're done with the result. * [len] is in bytes. */ -uint8_t *h_bit_writer_get_buffer(HBitWriter* w, size_t *len); +const uint8_t *h_bit_writer_get_buffer(HBitWriter* w, size_t *len); /** * TODO: Document me -- GitLab