CTS-SAT-1-OBC-Firmware
Loading...
Searching...
No Matches
heatshrink_encoder.h
Go to the documentation of this file.
1#ifndef HEATSHRINK_ENCODER_H
2#define HEATSHRINK_ENCODER_H
3
4#include <stdint.h>
5#include <stddef.h>
6#include "heatshrink_common.h"
7#include "heatshrink_config.h"
8
9typedef enum {
10 HSER_SINK_OK, /* data sunk into input buffer */
11 HSER_SINK_ERROR_NULL=-1, /* NULL argument */
12 HSER_SINK_ERROR_MISUSE=-2, /* API misuse */
14
15typedef enum {
16 HSER_POLL_EMPTY, /* input exhausted */
17 HSER_POLL_MORE, /* poll again for more output */
18 HSER_POLL_ERROR_NULL=-1, /* NULL argument */
19 HSER_POLL_ERROR_MISUSE=-2, /* API misuse */
21
22typedef enum {
23 HSER_FINISH_DONE, /* encoding is complete */
24 HSER_FINISH_MORE, /* more output remaining; use poll */
25 HSER_FINISH_ERROR_NULL=-1, /* NULL argument */
27
28#if HEATSHRINK_DYNAMIC_ALLOC
29#define HEATSHRINK_ENCODER_WINDOW_BITS(HSE) \
30 ((HSE)->window_sz2)
31#define HEATSHRINK_ENCODER_LOOKAHEAD_BITS(HSE) \
32 ((HSE)->lookahead_sz2)
33#define HEATSHRINK_ENCODER_INDEX(HSE) \
34 ((HSE)->search_index)
35struct hs_index {
36 uint16_t size;
37 int16_t index[];
38};
39#else
40#define HEATSHRINK_ENCODER_WINDOW_BITS(_) \
41 (HEATSHRINK_STATIC_WINDOW_BITS)
42#define HEATSHRINK_ENCODER_LOOKAHEAD_BITS(_) \
43 (HEATSHRINK_STATIC_LOOKAHEAD_BITS)
44#define HEATSHRINK_ENCODER_INDEX(HSE) \
45 (&(HSE)->search_index)
46struct hs_index {
47 uint16_t size;
48 int16_t index[2 << HEATSHRINK_STATIC_WINDOW_BITS];
49};
50#endif
51
52typedef struct {
53 uint16_t input_size; /* bytes in input buffer */
55 uint16_t match_length;
56 uint16_t match_pos;
57 uint16_t outgoing_bits; /* enqueued outgoing bits */
59 uint8_t flags;
60 uint8_t state; /* current state machine node */
61 uint8_t current_byte; /* current byte of output */
62 uint8_t bit_index; /* current bit index */
63#if HEATSHRINK_DYNAMIC_ALLOC
64 uint8_t window_sz2; /* 2^n size of window */
65 uint8_t lookahead_sz2; /* 2^n size of lookahead */
66#if HEATSHRINK_USE_INDEX
68#endif
69 /* input buffer and / sliding window for expansion */
70 uint8_t buffer[];
71#else
72 #if HEATSHRINK_USE_INDEX
74 #endif
75 /* input buffer and / sliding window for expansion */
77#endif
79
80#if HEATSHRINK_DYNAMIC_ALLOC
81/* Allocate a new encoder struct and its buffers.
82 * Returns NULL on error. */
84 uint8_t lookahead_sz2);
85
86/* Free an encoder. */
88#endif
89
90/* Reset an encoder. */
92
93/* Sink up to SIZE bytes from IN_BUF into the encoder.
94 * INPUT_SIZE is set to the number of bytes actually sunk (in case a
95 * buffer was filled.). */
97 uint8_t *in_buf, size_t size, size_t *input_size);
98
99/* Poll for output from the encoder, copying at most OUT_BUF_SIZE bytes into
100 * OUT_BUF (setting *OUTPUT_SIZE to the actual amount copied). */
102 uint8_t *out_buf, size_t out_buf_size, size_t *output_size);
103
104/* Notify the encoder that the input stream is finished.
105 * If the return value is HSER_FINISH_MORE, there is still more output, so
106 * call heatshrink_encoder_poll and repeat. */
108
109#endif
HSE_sink_res
Definition heatshrink_encoder.h:9
@ HSER_SINK_ERROR_NULL
Definition heatshrink_encoder.h:11
@ HSER_SINK_OK
Definition heatshrink_encoder.h:10
@ HSER_SINK_ERROR_MISUSE
Definition heatshrink_encoder.h:12
HSE_finish_res heatshrink_encoder_finish(heatshrink_encoder *hse)
Definition heatshrink_encoder.c:253
void heatshrink_encoder_reset(heatshrink_encoder *hse)
Definition heatshrink_encoder.c:118
void heatshrink_encoder_free(heatshrink_encoder *hse)
HSE_poll_res heatshrink_encoder_poll(heatshrink_encoder *hse, uint8_t *out_buf, size_t out_buf_size, size_t *output_size)
Definition heatshrink_encoder.c:190
heatshrink_encoder * heatshrink_encoder_alloc(uint8_t window_sz2, uint8_t lookahead_sz2)
HSE_sink_res heatshrink_encoder_sink(heatshrink_encoder *hse, uint8_t *in_buf, size_t size, size_t *input_size)
Definition heatshrink_encoder.c:137
HSE_finish_res
Definition heatshrink_encoder.h:22
@ HSER_FINISH_ERROR_NULL
Definition heatshrink_encoder.h:25
@ HSER_FINISH_DONE
Definition heatshrink_encoder.h:23
@ HSER_FINISH_MORE
Definition heatshrink_encoder.h:24
#define HEATSHRINK_ENCODER_WINDOW_BITS(HSE)
Definition heatshrink_encoder.h:29
HSE_poll_res
Definition heatshrink_encoder.h:15
@ HSER_POLL_EMPTY
Definition heatshrink_encoder.h:16
@ HSER_POLL_ERROR_MISUSE
Definition heatshrink_encoder.h:19
@ HSER_POLL_ERROR_NULL
Definition heatshrink_encoder.h:18
@ HSER_POLL_MORE
Definition heatshrink_encoder.h:17
Definition heatshrink_encoder.h:52
uint8_t bit_index
Definition heatshrink_encoder.h:62
uint16_t outgoing_bits
Definition heatshrink_encoder.h:57
uint8_t state
Definition heatshrink_encoder.h:60
uint8_t window_sz2
Definition heatshrink_encoder.h:64
uint8_t current_byte
Definition heatshrink_encoder.h:61
uint16_t match_scan_index
Definition heatshrink_encoder.h:54
uint8_t lookahead_sz2
Definition heatshrink_encoder.h:65
uint8_t outgoing_bits_count
Definition heatshrink_encoder.h:58
uint8_t buffer[]
Definition heatshrink_encoder.h:70
uint16_t match_pos
Definition heatshrink_encoder.h:56
struct hs_index * search_index
Definition heatshrink_encoder.h:67
uint8_t flags
Definition heatshrink_encoder.h:59
uint16_t input_size
Definition heatshrink_encoder.h:53
uint16_t match_length
Definition heatshrink_encoder.h:55
Definition heatshrink_encoder.h:35
int16_t index[]
Definition heatshrink_encoder.h:37
uint16_t size
Definition heatshrink_encoder.h:36