--- a/src/lib/TransactionalBuffer.h Sun Jun 20 20:16:46 2021 +0200
+++ b/src/lib/TransactionalBuffer.h Sun Jun 20 21:06:02 2021 +0200
@@ -37,6 +37,9 @@
size_t readPosition = 0;
size_t readPositionCommited = 0;
+ size_t bytesRead = 0;
+ size_t bytesReadCommited = 0;
+
size_t availableForReading() {
if (readPosition < writePosition) return writePosition - readPosition;
else if (readPosition > writePosition) return bufferSize - readPosition + writePosition;
@@ -99,6 +102,7 @@
peek(outputBuffer, length);
readPosition = (readPosition + length) % bufferSize;
hasData = readPosition != writePosition;
+ bytesRead += length;
}
void peek(uint8_t* outputBuffer, const size_t length) {
@@ -114,11 +118,18 @@
void commitRead() {
readPositionCommited = readPosition;
+ bytesReadCommited = bytesRead;
}
void rollbackRead() {
readPosition = readPositionCommited;
+ bytesRead = bytesReadCommited;
}
+
+ size_t getBytesRead() {
+ return bytesRead;
+ }
+
};