From 41bfe65ddabeb3bb52ca90f31c3b7320f1235e27 Mon Sep 17 00:00:00 2001 From: fhgffy <102001626+fhgffy@users.noreply.github.com> Date: Mon, 12 Oct 2026 12:42:06 -0500 Subject: [PATCH] Fix callbacks for Boolean byte-stream writes (#1615) * Add docs and tutorial for etl::intrusive_avl_tree (#1608) * Add docs and tutorial for etl::intrusive_avl_tree Documents the intrusive AVL tree added in PR #1425: a full API reference page under Containers/Trees, and a tutorial demonstrating ordered access to intrusively-linked objects with unpredictable lifetimes, including move support and destructor-driven automatic removal from the tree. Co-Authored-By: Claude Sonnet 5 * Add complexity shortcode and document its usage Introduces a {{< complexity >}} Hugo shortcode (with light/dark styling for constant/logarithmic/linear/linearithmic/polynomial/exponential classes) for rendering Big-O complexity inline, applies it throughout the intrusive_avl_tree API reference in place of raw "O(...)" text, and documents the Description/Complexity structure and supported classes in DOCUMENTATION.md. Co-Authored-By: Claude Sonnet 5 * Fix issues found by @CodeRabbit * Put complexity notes on their own lines in intrusive_avl_tree docs Move the complexity shortcode from the inline "**Complexity:**" label to its own line under a "**Complexity**" label. Notes that give several alternatives (e.g. amortized vs. worst-case) now show each one on a separate line. Update the guideline in DOCUMENTATION.md to match. * Update complexity examples in DOCUMENTATION.md Add the hard line break after the "**Complexity**" label in the example, and rewrite the list of supported complexity classes in the new two-line format, including an example with several alternatives. * Add logarithmic complexity example to DOCUMENTATION.md --------- Co-authored-by: Claude Sonnet 5 Co-authored-by: John Wellbelove * Updated sponsors pages * Refactor the documentation css to group styles for light and dark themes * Update Codacy badge in README.md Updated Codacy badge link to reflect new project status. * Fix Codacy badge display * Fix callbacks for Boolean byte-stream writes Advance Boolean writes through the existing callback path and test checked and unchecked writes, including rejected writes at full capacity. --------- Co-authored-by: Sergei Co-authored-by: Claude Sonnet 5 Co-authored-by: John Wellbelove Co-authored-by: John Wellbelove --- docs/utilities/byte-stream-writer.md | 1 + include/etl/byte_stream.h | 3 +- test/test_byte_stream.cpp | 55 ++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/docs/utilities/byte-stream-writer.md b/docs/utilities/byte-stream-writer.md index db3c8a62..2ce8a8fb 100644 --- a/docs/utilities/byte-stream-writer.md +++ b/docs/utilities/byte-stream-writer.md @@ -92,6 +92,7 @@ bool write(bool value) **Description** Write a boolean value to the stream. Returns `true` if successful, otherwise `false`. +If a callback is set, it receives the one-byte boolean value after a successful write. --- diff --git a/include/etl/byte_stream.h b/include/etl/byte_stream.h index 76a4bf04..4a89c5d4 100644 --- a/include/etl/byte_stream.h +++ b/include/etl/byte_stream.h @@ -126,7 +126,8 @@ namespace etl //*************************************************************************** void write_unchecked(bool value) { - *pcurrent++ = value ? 1 : 0; + *pcurrent = value ? 1 : 0; + step(1U); } //*************************************************************************** diff --git a/test/test_byte_stream.cpp b/test/test_byte_stream.cpp index 514dbd81..576de482 100644 --- a/test/test_byte_stream.cpp +++ b/test/test_byte_stream.cpp @@ -1374,6 +1374,61 @@ namespace } } + //************************************************************************* + TEST(write_bool_callback) + { + std::array storage = {}; + std::vector received; + std::vector lengths; + std::vector positions; + auto lambda = [&](etl::byte_stream_writer::callback_parameter_type sp) + { + received.insert(received.end(), sp.begin(), sp.end()); + lengths.push_back(sp.size()); + positions.push_back(sp.data()); + }; + etl::byte_stream_writer::callback_type callback(lambda); + etl::byte_stream_writer writer(storage.data(), storage.size(), etl::endian::big, callback); + + CHECK_TRUE(writer.write(char(7))); + CHECK_TRUE(writer.write(true)); + CHECK_TRUE(writer.write(false)); + CHECK_TRUE(writer.full()); + CHECK_EQUAL(size_t(3), writer.size_bytes()); + CHECK_EQUAL(size_t(3), received.size()); + CHECK(received == std::vector({char(7), char(1), char(0)})); + CHECK(lengths == std::vector({1U, 1U, 1U})); + CHECK(positions == std::vector({storage.data(), storage.data() + 1, storage.data() + 2})); + CHECK_ARRAY_EQUAL(storage.data(), received.data(), received.size()); + + CHECK_FALSE(writer.write(true)); + CHECK_EQUAL(size_t(3), received.size()); + CHECK_EQUAL(size_t(3), writer.size_bytes()); + } + + //************************************************************************* + TEST(write_bool_unchecked_callback) + { + std::array storage = {}; + std::vector received; + auto lambda = [&](etl::byte_stream_writer::callback_parameter_type sp) + { + CHECK_EQUAL(size_t(1), sp.size()); + received.insert(received.end(), sp.begin(), sp.end()); + }; + etl::byte_stream_writer::callback_type callback(lambda); + etl::byte_stream_writer writer(storage.data(), storage.size(), etl::endian::little); + writer.set_callback(callback); + + writer.write_unchecked(false); + etl::write_unchecked(writer, true); + CHECK_TRUE(writer.full()); + CHECK_EQUAL(size_t(2), writer.size_bytes()); + CHECK(received == std::vector({char(0), char(1)})); + CHECK_EQUAL(char(0), storage[0]); + CHECK_EQUAL(char(1), storage[1]); + } + //************************************************************************* TEST(write_byte_stream_callback) {