From ce4620413b42e93db4c58449691eec113f0723b1 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Sat, 26 Feb 2022 20:02:14 +0000 Subject: inflate: Add helpers for using in-memory buffers Using an in-memory buffer for the input or output data for 'inflate' is likely to be extremely common and there's really only one way to do it, so predefined helpers should be provided. Change-Id: Ifd22e7b140a08e0e7dc05aec6b340dff5e2d9d0a --- firmware/include/inflate.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'firmware/include') diff --git a/firmware/include/inflate.h b/firmware/include/inflate.h index b56ccf181a..7dae0448e3 100644 --- a/firmware/include/inflate.h +++ b/firmware/include/inflate.h @@ -23,6 +23,7 @@ #define _INFLATE_H_ #include +#include enum { INFLATE_RAW, @@ -43,4 +44,18 @@ extern const uint32_t inflate_align; // see above enum for possible options. int inflate(struct inflate* it, int st, inflate_reader read, void* rctx, inflate_writer write, void* wctx); +struct inflate_bufferctx { + // initialize this with your input/output buffer. + // the pointer is updated as data is read or written. + void* buf; + + // buffer end marker (= buf + buf_size). + void* end; +}; + +// reader and writer for using an in-memory buffer. +// Use 'inflate_bufferctx' as the context argument. +uint32_t inflate_buffer_reader(void* block, uint32_t block_size, void* ctx); +uint32_t inflate_buffer_writer(const void* block, uint32_t block_size, void* ctx); + #endif -- cgit v1.2.3