CTS-SAT-1-OBC-Firmware
Loading...
Searching...
No Matches
heatshrink_decoder.h
Go to the documentation of this file.
1#ifndef HEATSHRINK_DECODER_H
2#define HEATSHRINK_DECODER_H
3
4#include <stdint.h>
5#include <stddef.h>
6#include "heatshrink_common.h"
7#include "heatshrink_config.h"
8
9typedef enum {
10 HSDR_SINK_OK, /* data sunk, ready to poll */
11 HSDR_SINK_FULL, /* out of space in internal buffer */
12 HSDR_SINK_ERROR_NULL=-1, /* NULL argument */
14
15typedef enum {
16 HSDR_POLL_EMPTY, /* input exhausted */
17 HSDR_POLL_MORE, /* more data remaining, call again w/ fresh output buffer */
18 HSDR_POLL_ERROR_NULL=-1, /* NULL arguments */
21
22typedef enum {
23 HSDR_FINISH_DONE, /* output is done */
24 HSDR_FINISH_MORE, /* more output remains */
25 HSDR_FINISH_ERROR_NULL=-1, /* NULL arguments */
27
28#if HEATSHRINK_DYNAMIC_ALLOC
29#define HEATSHRINK_DECODER_INPUT_BUFFER_SIZE(BUF) \
30 ((BUF)->input_buffer_size)
31#define HEATSHRINK_DECODER_WINDOW_BITS(BUF) \
32 ((BUF)->window_sz2)
33#define HEATSHRINK_DECODER_LOOKAHEAD_BITS(BUF) \
34 ((BUF)->lookahead_sz2)
35#else
36#define HEATSHRINK_DECODER_INPUT_BUFFER_SIZE(_) \
37 HEATSHRINK_STATIC_INPUT_BUFFER_SIZE
38#define HEATSHRINK_DECODER_WINDOW_BITS(_) \
39 (HEATSHRINK_STATIC_WINDOW_BITS)
40#define HEATSHRINK_DECODER_LOOKAHEAD_BITS(BUF) \
41 (HEATSHRINK_STATIC_LOOKAHEAD_BITS)
42#endif
43
44typedef struct {
45 uint16_t input_size; /* bytes in input buffer */
46 uint16_t input_index; /* offset to next unprocessed input byte */
47 uint16_t output_count; /* how many bytes to output */
48 uint16_t output_index; /* index for bytes to output */
49 uint16_t head_index; /* head of window buffer */
50 uint8_t state; /* current state machine node */
51 uint8_t current_byte; /* current byte of input */
52 uint8_t bit_index; /* current bit index */
53
54#if HEATSHRINK_DYNAMIC_ALLOC
55 /* Fields that are only used if dynamically allocated. */
56 uint8_t window_sz2; /* window buffer bits */
57 uint8_t lookahead_sz2; /* lookahead bits */
58 uint16_t input_buffer_size; /* input buffer size */
59
60 /* Input buffer, then expansion window buffer */
61 uint8_t buffers[];
62#else
63 /* Input buffer, then expansion window buffer */
66#endif
68
69#if HEATSHRINK_DYNAMIC_ALLOC
70/* Allocate a decoder with an input buffer of INPUT_BUFFER_SIZE bytes,
71 * an expansion buffer size of 2^WINDOW_SZ2, and a lookahead
72 * size of 2^lookahead_sz2. (The window buffer and lookahead sizes
73 * must match the settings used when the data was compressed.)
74 * Returns NULL on error. */
75heatshrink_decoder *heatshrink_decoder_alloc(uint16_t input_buffer_size,
76 uint8_t expansion_buffer_sz2, uint8_t lookahead_sz2);
77
78/* Free a decoder. */
80#endif
81
82/* Reset a decoder. */
84
85/* Sink at most SIZE bytes from IN_BUF into the decoder. *INPUT_SIZE is set to
86 * indicate how many bytes were actually sunk (in case a buffer was filled). */
88 uint8_t *in_buf, size_t size, size_t *input_size);
89
90/* Poll for output from the decoder, copying at most OUT_BUF_SIZE bytes into
91 * OUT_BUF (setting *OUTPUT_SIZE to the actual amount copied). */
93 uint8_t *out_buf, size_t out_buf_size, size_t *output_size);
94
95/* Notify the dencoder that the input stream is finished.
96 * If the return value is HSDR_FINISH_MORE, there is still more output, so
97 * call heatshrink_decoder_poll and repeat. */
99
100#endif
HSD_finish_res
Definition heatshrink_decoder.h:22
@ HSDR_FINISH_DONE
Definition heatshrink_decoder.h:23
@ HSDR_FINISH_ERROR_NULL
Definition heatshrink_decoder.h:25
@ HSDR_FINISH_MORE
Definition heatshrink_decoder.h:24
HSD_sink_res
Definition heatshrink_decoder.h:9
@ HSDR_SINK_ERROR_NULL
Definition heatshrink_decoder.h:12
@ HSDR_SINK_OK
Definition heatshrink_decoder.h:10
@ HSDR_SINK_FULL
Definition heatshrink_decoder.h:11
HSD_poll_res heatshrink_decoder_poll(heatshrink_decoder *hsd, uint8_t *out_buf, size_t out_buf_size, size_t *output_size)
Definition heatshrink_decoder.c:135
#define HEATSHRINK_DECODER_INPUT_BUFFER_SIZE(BUF)
Definition heatshrink_decoder.h:29
#define HEATSHRINK_DECODER_WINDOW_BITS(BUF)
Definition heatshrink_decoder.h:31
void heatshrink_decoder_reset(heatshrink_decoder *hsd)
Definition heatshrink_decoder.c:80
HSD_sink_res heatshrink_decoder_sink(heatshrink_decoder *hsd, uint8_t *in_buf, size_t size, size_t *input_size)
Definition heatshrink_decoder.c:95
heatshrink_decoder * heatshrink_decoder_alloc(uint16_t input_buffer_size, uint8_t expansion_buffer_sz2, uint8_t lookahead_sz2)
Definition heatshrink_decoder.c:49
HSD_finish_res heatshrink_decoder_finish(heatshrink_decoder *hsd)
Definition heatshrink_decoder.c:337
HSD_poll_res
Definition heatshrink_decoder.h:15
@ HSDR_POLL_MORE
Definition heatshrink_decoder.h:17
@ HSDR_POLL_EMPTY
Definition heatshrink_decoder.h:16
@ HSDR_POLL_ERROR_NULL
Definition heatshrink_decoder.h:18
@ HSDR_POLL_ERROR_UNKNOWN
Definition heatshrink_decoder.h:19
void heatshrink_decoder_free(heatshrink_decoder *hsd)
Definition heatshrink_decoder.c:72
Definition heatshrink_decoder.h:44
uint8_t current_byte
Definition heatshrink_decoder.h:51
uint16_t input_buffer_size
Definition heatshrink_decoder.h:58
uint8_t buffers[]
Definition heatshrink_decoder.h:61
uint16_t output_count
Definition heatshrink_decoder.h:47
uint8_t window_sz2
Definition heatshrink_decoder.h:56
uint8_t bit_index
Definition heatshrink_decoder.h:52
uint8_t lookahead_sz2
Definition heatshrink_decoder.h:57
uint16_t head_index
Definition heatshrink_decoder.h:49
uint16_t output_index
Definition heatshrink_decoder.h:48
uint16_t input_index
Definition heatshrink_decoder.h:46
uint16_t input_size
Definition heatshrink_decoder.h:45
uint8_t state
Definition heatshrink_decoder.h:50