aboutsummaryrefslogtreecommitdiff
path: root/ble/ByteBuffer.h
diff options
context:
space:
mode:
Diffstat (limited to 'ble/ByteBuffer.h')
-rw-r--r--ble/ByteBuffer.h20
1 files changed, 13 insertions, 7 deletions
diff --git a/ble/ByteBuffer.h b/ble/ByteBuffer.h
index 3836966..f884d6e 100644
--- a/ble/ByteBuffer.h
+++ b/ble/ByteBuffer.h
@@ -5,9 +5,7 @@
#include <cstdlib>
#include <string>
#include <stdexcept>
-
-// For now
-#include "log.h"
+#include <memory>
class ByteBufferException : public std::runtime_error {
public:
@@ -17,12 +15,15 @@ public:
class ByteBuffer {
public:
+ static ByteBuffer alloc(std::size_t capacity);
+
ByteBuffer(const std::shared_ptr<uint8_t> bytes, size_t capacity);
- ByteBuffer(const std::shared_ptr<uint8_t> bytes, size_t capacity, size_t zero, size_t size);
+ ByteBuffer(const std::shared_ptr<uint8_t> bytes, size_t capacity, size_t size);
+
+ ByteBuffer(const std::shared_ptr<uint8_t> bytes, size_t capacity, size_t size, size_t zero);
inline size_t getSize() const {
-// DF << "end=" << (uint64_t)end << ", zero=" << (uint64_t)zero << ", size=" << (end - zero);
return end - zero;
}
@@ -39,12 +40,10 @@ public:
}
inline void setCursor(size_t newCursor) {
-// assertCanAccessRelative(newCursor);
ptr = (uint8_t *) &zero[newCursor];
}
inline void skip(size_t length) {
-// checkAndUpdateEnd(length);
ptr += length;
}
@@ -52,6 +51,13 @@ public:
ByteBuffer &write16le(uint16_t value);
+ /**
+ * Appends the entire buffer. Make a view if you want to write a part of it.
+ */
+ ByteBuffer &write(const ByteBuffer &value);
+
+ ByteBuffer &write(const uint8_t *bytes, size_t len);
+
uint8_t get8(size_t index) const;
uint8_t read8();