extend the ByteBuffer with [] operator to set the position.

This commit is contained in:
NP v/d Spek 2024-09-23 15:28:26 +02:00
parent c237e1fcd7
commit 092d902620

View file

@ -30,6 +30,8 @@ enum Endian { LITTLE, BIG };
* data from a buffer after it has been written. * data from a buffer after it has been written.
* *
*/ */
class ByteBuffer;
class ByteBuffer { class ByteBuffer {
public: public:
// Default constructor (compatibility with TEMPLATABLE_VALUE) // Default constructor (compatibility with TEMPLATABLE_VALUE)
@ -143,6 +145,11 @@ class ByteBuffer {
return changed; return changed;
} }
ByteBuffer &operator[](size_t idx) {
this->set_position(idx);
return *this;
}
protected: protected:
ByteBuffer(std::vector<uint8_t> const &data) : data_(data), limit_(data.size()) {} ByteBuffer(std::vector<uint8_t> const &data) : data_(data), limit_(data.size()) {}
void update_() { void update_() {