ESPHome
2026.11.0-dev
Loading...
Searching...
No Matches
esphome
components
esphome
ota
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
9
extern
"C"
{
10
#endif
11
12
enum
OtaInflateResult
{
13
OTA_INFLATE_OK
= 0,
/* more data produced, call again */
14
OTA_INFLATE_DONE
= 1,
/* end of compressed stream reached */
15
OTA_INFLATE_DATA_ERROR
= -3,
16
OTA_INFLATE_DICT_ERROR
= -5,
17
};
18
19
struct
OtaInflateTree
{
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
25
struct
OtaInflateState
{
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. */
31
int (*
source_read_cb
)(
struct
OtaInflateState
*d);
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) */
57
void
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 */
61
int
ota_inflate
(
struct
OtaInflateState
*d);
62
63
#ifdef __cplusplus
64
}
65
#endif
OtaInflateResult
OtaInflateResult
Definition
ota_esphome_inflate.h:12
OTA_INFLATE_DATA_ERROR
@ OTA_INFLATE_DATA_ERROR
Definition
ota_esphome_inflate.h:15
OTA_INFLATE_OK
@ OTA_INFLATE_OK
Definition
ota_esphome_inflate.h:13
OTA_INFLATE_DONE
@ OTA_INFLATE_DONE
Definition
ota_esphome_inflate.h:14
OTA_INFLATE_DICT_ERROR
@ OTA_INFLATE_DICT_ERROR
Definition
ota_esphome_inflate.h:16
ota_inflate_init
void ota_inflate_init(struct OtaInflateState *d, unsigned char *dict, unsigned int dict_len)
ota_inflate
int ota_inflate(struct OtaInflateState *d)
OtaInflateState
Definition
ota_esphome_inflate.h:25
OtaInflateState::bitcount
uint8_t bitcount
Definition
ota_esphome_inflate.h:47
OtaInflateState::bfinal
uint8_t bfinal
Definition
ota_esphome_inflate.h:46
OtaInflateState::dest
unsigned char * dest
Definition
ota_esphome_inflate.h:33
OtaInflateState::dict_size
unsigned int dict_size
Definition
ota_esphome_inflate.h:41
OtaInflateState::source_read_cb
int(* source_read_cb)(struct OtaInflateState *d)
Definition
ota_esphome_inflate.h:31
OtaInflateState::dtree
struct OtaInflateTree dtree
Definition
ota_esphome_inflate.h:51
OtaInflateState::ltrans
uint16_t ltrans[288]
Definition
ota_esphome_inflate.h:52
OtaInflateState::source_limit
const unsigned char * source_limit
Definition
ota_esphome_inflate.h:28
OtaInflateState::ltree
struct OtaInflateTree ltree
Definition
ota_esphome_inflate.h:50
OtaInflateState::dtrans
uint16_t dtrans[32]
Definition
ota_esphome_inflate.h:53
OtaInflateState::dict_idx
unsigned int dict_idx
Definition
ota_esphome_inflate.h:42
OtaInflateState::curlen
unsigned int curlen
Definition
ota_esphome_inflate.h:39
OtaInflateState::source
const unsigned char * source
Definition
ota_esphome_inflate.h:27
OtaInflateState::tag
unsigned int tag
Definition
ota_esphome_inflate.h:38
OtaInflateState::eof
bool eof
Definition
ota_esphome_inflate.h:48
OtaInflateState::lz_off
int lz_off
Definition
ota_esphome_inflate.h:40
OtaInflateState::dict_ring
unsigned char * dict_ring
Definition
ota_esphome_inflate.h:36
OtaInflateState::btype
int8_t btype
Definition
ota_esphome_inflate.h:45
OtaInflateState::dest_limit
unsigned char * dest_limit
Definition
ota_esphome_inflate.h:34
OtaInflateTree
Definition
ota_esphome_inflate.h:19
OtaInflateTree::size
uint16_t size
Definition
ota_esphome_inflate.h:22
OtaInflateTree::trans
uint16_t * trans
Definition
ota_esphome_inflate.h:21
OtaInflateTree::table
uint16_t table[16]
Definition
ota_esphome_inflate.h:20
Generated by
1.12.0