ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
ota_esphome_inflate.h
Go to the documentation of this file.
1#pragma once
2// Raw deflate decoder cut down from uzlib (https://github.com/pfalcon/uzlib,
3// zlib licence, see the .c file); output goes through a ring window.
4
5#include <stdbool.h>
6#include <stdint.h>
7
8#ifdef __cplusplus
9extern "C" {
10#endif
11
13 OTA_INFLATE_OK = 0, /* more data produced, call again */
14 OTA_INFLATE_DONE = 1, /* end of compressed stream reached */
17};
18
20 uint16_t table[16]; /* table of code length counts */
21 uint16_t *trans; /* code -> symbol translation table, size entries */
22 uint16_t size;
23};
24
26 /* Next byte in the input buffer and one past its end */
27 const unsigned char *source;
28 const unsigned char *source_limit;
29 /* Called when source is exhausted; returns the next byte or -1 at EOF.
30 It may refill source/source_limit for buffered operation. */
32 /* Output cursor and one past the end of the output buffer */
33 unsigned char *dest;
34 unsigned char *dest_limit;
35 /* Ring window holding the last dict_size output bytes for back references */
36 unsigned char *dict_ring;
37
38 unsigned int tag;
39 unsigned int curlen;
40 int lz_off;
41 unsigned int dict_size;
42 unsigned int dict_idx;
43
44 /* One word: btype is -1 between blocks, bitcount never exceeds 7 */
45 int8_t btype;
46 uint8_t bfinal;
47 uint8_t bitcount;
48 bool eof;
49
50 struct OtaInflateTree ltree; /* dynamic length/symbol tree */
51 struct OtaInflateTree dtree; /* dynamic distance tree */
52 uint16_t ltrans[288];
53 uint16_t dtrans[32]; /* the distance alphabet has 30 symbols, so the tree is kept small */
54};
55
56/* dict must cover the encoder's window (its largest back reference) */
57void ota_inflate_init(struct OtaInflateState *d, unsigned char *dict, unsigned int dict_len);
58/* Fills dest up to dest_limit (OK) or to the end of the stream (DONE). dest may
59 alias dict only if dest_limit - dest == dict_len and dest is reset to dict
60 exactly when a call returns OK, so the ring index and dest stay in lockstep */
62
63#ifdef __cplusplus
64}
65#endif
OtaInflateResult
@ OTA_INFLATE_DATA_ERROR
@ OTA_INFLATE_OK
@ OTA_INFLATE_DONE
@ OTA_INFLATE_DICT_ERROR
void ota_inflate_init(struct OtaInflateState *d, unsigned char *dict, unsigned int dict_len)
int ota_inflate(struct OtaInflateState *d)
unsigned char * dest
int(* source_read_cb)(struct OtaInflateState *d)
struct OtaInflateTree dtree
const unsigned char * source_limit
struct OtaInflateTree ltree
const unsigned char * source
unsigned char * dict_ring
unsigned char * dest_limit