diff options
| author | jacqueline <me@jacqueline.id.au> | 2022-12-03 11:10:06 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2022-12-03 11:10:06 +1100 |
| commit | 16d5d29049c08e21f57f7928ceedf40586a2d294 (patch) | |
| tree | a4647f951f90b036c58c879ae186fa7e452ed950 /src/audio/include/chunk.hpp | |
| parent | 00d4883d3a683eaf9cfaefacdd81434e0974ad13 (diff) | |
| download | tangara-fw-16d5d29049c08e21f57f7928ceedf40586a2d294.tar.gz | |
Use std::span (backported) and std::byte to make our buffers safer
Diffstat (limited to 'src/audio/include/chunk.hpp')
| -rw-r--r-- | src/audio/include/chunk.hpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/audio/include/chunk.hpp b/src/audio/include/chunk.hpp index 365c83d0..0cbe8d5c 100644 --- a/src/audio/include/chunk.hpp +++ b/src/audio/include/chunk.hpp @@ -12,6 +12,7 @@ #include "freertos/portmacro.h" #include "freertos/queue.h" #include "result.hpp" +#include "span.hpp" namespace audio { @@ -37,9 +38,8 @@ enum ChunkWriteResult { * more input to read. */ auto WriteChunksToStream(MessageBufferHandle_t* stream, - uint8_t* working_buffer, - size_t working_buffer_length, - std::function<size_t(uint8_t*, size_t)> callback, + cpp::span<std::byte> working_buffer, + std::function<size_t(cpp::span<std::byte>)> callback, TickType_t max_wait) -> ChunkWriteResult; enum ChunkReadResult { @@ -64,7 +64,7 @@ class ChunkReader { auto Reset() -> void; - auto GetLastMessage() -> std::pair<uint8_t*, size_t>; + auto GetLastMessage() -> cpp::span<std::byte>; /* * Reads chunks of data from the given input stream, and invokes the given @@ -79,12 +79,13 @@ class ChunkReader { * will place the message at the start of the working_buffer and then return. */ auto ReadChunkFromStream( - std::function<std::optional<size_t>(uint8_t*, size_t)> callback, + std::function<std::optional<size_t>(cpp::span<std::byte>)> callback, TickType_t max_wait) -> ChunkReadResult; private: MessageBufferHandle_t* stream_; - uint8_t* working_buffer_; + std::byte* raw_working_buffer_; + cpp::span<std::byte> working_buffer_; std::size_t leftover_bytes_ = 0; std::size_t last_message_size_ = 0; |
