aboutsummaryrefslogtreecommitdiff
path: root/ble/ByteBuffer.h
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-02-21 23:58:39 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2015-02-21 23:58:39 +0100
commit5926b05afa21eaac36c185e7fc458710efa30b02 (patch)
tree1d835b53fcb3dbc44b07084155a37874ce8325dc /ble/ByteBuffer.h
parenta76e09808905d280282a81958cb4c68f71f18ca4 (diff)
downloadble-toys-5926b05afa21eaac36c185e7fc458710efa30b02.tar.gz
ble-toys-5926b05afa21eaac36c185e7fc458710efa30b02.tar.bz2
ble-toys-5926b05afa21eaac36c185e7fc458710efa30b02.tar.xz
ble-toys-5926b05afa21eaac36c185e7fc458710efa30b02.zip
o Support for reading and writing characteristics.
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();