From 092d902620779041feddf796d16f471f96c2edb8 Mon Sep 17 00:00:00 2001 From: NP v/d Spek Date: Mon, 23 Sep 2024 15:28:26 +0200 Subject: [PATCH] extend the ByteBuffer with [] operator to set the position. --- esphome/core/bytebuffer.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/esphome/core/bytebuffer.h b/esphome/core/bytebuffer.h index 462da4c1f1..4662195fb4 100644 --- a/esphome/core/bytebuffer.h +++ b/esphome/core/bytebuffer.h @@ -30,6 +30,8 @@ enum Endian { LITTLE, BIG }; * data from a buffer after it has been written. * */ + +class ByteBuffer; class ByteBuffer { public: // Default constructor (compatibility with TEMPLATABLE_VALUE) @@ -143,6 +145,11 @@ class ByteBuffer { return changed; } + ByteBuffer &operator[](size_t idx) { + this->set_position(idx); + return *this; + } + protected: ByteBuffer(std::vector const &data) : data_(data), limit_(data.size()) {} void update_() {