ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
download_buffer.h
Go to the documentation of this file.
1#pragma once
2
5#include <cstddef>
6#include <cstdint>
7
8namespace esphome::online_image {
9
17 public:
18 DownloadBuffer(size_t size);
20 RAMAllocator<uint8_t> allocator;
21 allocator.deallocate(this->buffer_, this->size_);
22 }
23
24 uint8_t *data(size_t offset = 0);
25 uint8_t *append() { return this->data(this->unread_); }
26
27 size_t unread() const { return this->unread_; }
28 size_t size() const { return this->size_; }
29 size_t free_capacity() const { return this->size_ - this->unread_; }
30
31 size_t read(size_t len);
32 size_t write(size_t len) {
33 this->unread_ += len;
34 return this->unread_;
35 }
36
37 void reset() { this->unread_ = 0; }
38 size_t resize(size_t size);
40 bool grow(size_t size);
41
42 protected:
43 uint8_t *buffer_;
44 size_t size_;
46 size_t unread_;
47};
48
57 public:
59
61 void reset() {
62 this->start_ = 0;
63 this->pos_ = 0;
64 this->keep_read_ = true;
65 }
66 void set_keep_read(bool keep) { this->keep_read_ = keep; }
68 void compact();
69
70 int32_t read(uint8_t *buf, uint32_t len) override;
71 bool seek(uint32_t position) override;
72
73 protected:
75 size_t start_{0}; // Position in the download of the first byte in the buffer
76 size_t pos_{0}; // Position in the download the decoder reads next
77 bool keep_read_{true};
78};
79
80} // namespace esphome::online_image
An STL allocator that uses SPI or internal RAM.
Definition helpers.h:2396
void deallocate(T *p, size_t n)
Definition helpers.h:2453
Buffer for managing downloaded data.
size_t unread_
Total number of downloaded bytes not yet read.
bool grow(size_t size)
Make the buffer at least size bytes, keeping the unread data. Returns false if the allocation failed.
Lets a decoder read a download as it arrives, from the download buffer.
void compact()
Drop the bytes the decoder has read, to make room for more of the download.
DownloadSource(DownloadBuffer &buffer)
int32_t read(uint8_t *buf, uint32_t len) override
bool seek(uint32_t position) override
void reset()
Start again at the beginning of a new download, keeping what is read.
Input that a decoder reads itself as it goes, so the whole image never has to be in memory at once.
float position
Definition cover.h:0
uint32_t buffer
Definition gif.cpp:50
const void size_t len
Definition hal.h:68
static void uint32_t