ESPHome 2026.12.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
19/* Code bits each lookup table resolves; longer codes take the canonical decode.
20 The distance alphabet has 30 symbols, so its table is kept small */
22
24 uint16_t table[16]; /* table of code length counts */
25 uint16_t *fast; /* (len << 9) | symbol by the next input bits, 0 = longer code */
26 uint16_t *trans; /* code -> symbol translation table */
27};
28
30 /* Next byte in the input buffer and one past its end */
31 const unsigned char *source;
32 const unsigned char *source_limit;
33 /* Called when source is exhausted; returns the next byte or -1 at EOF.
34 It may refill source/source_limit for buffered operation. */
36 /* Output cursor in dict_ring: each call fills the ring from here */
37 unsigned char *dest;
38 /* Ring window holding the last dict_size output bytes for back references */
39 unsigned char *dict_ring;
40
41 unsigned int tag;
42 unsigned int curlen;
43 int lz_off;
44 unsigned int dict_size;
45
46 /* btype is -1 between blocks; bitcount is the number of valid bits in tag (<= 32) */
47 int8_t btype;
48 uint8_t bfinal;
49 uint8_t bitcount;
50 bool eof;
51
52 struct OtaInflateTree ltree; /* dynamic length/symbol tree */
53 struct OtaInflateTree dtree; /* dynamic distance tree */
54 uint16_t ltrans[288];
55 uint16_t dtrans[32]; /* the distance alphabet has 30 symbols, so the tree is kept small */
58};
59
60/* dict must cover the encoder's window (its largest back reference) */
61void ota_inflate_init(struct OtaInflateState *d, unsigned char *dict, unsigned int dict_len);
62/* Inflates into dict until it is full (OK) or the stream ends (DONE); the output
63 is dict up to dest. The next call after OK starts dict over, so take its
64 contents first */
66
67#ifdef __cplusplus
68}
69#endif
OtaInflateResult
@ OTA_INFLATE_DATA_ERROR
@ OTA_INFLATE_OK
@ OTA_INFLATE_DONE
@ OTA_INFLATE_DICT_ERROR
@ OTA_INFLATE_LIT_FAST_BITS
@ OTA_INFLATE_DIST_FAST_BITS
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
uint16_t lfast[1<< OTA_INFLATE_LIT_FAST_BITS]
struct OtaInflateTree ltree
const unsigned char * source
uint16_t dfast[1<< OTA_INFLATE_DIST_FAST_BITS]
unsigned char * dict_ring