diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/ble/Bluetooth.h | 2 | ||||
-rw-r--r-- | include/ble/ByteBuffer.h | 29 |
2 files changed, 19 insertions, 12 deletions
diff --git a/include/ble/Bluetooth.h b/include/ble/Bluetooth.h index 477bd29..d95d843 100644 --- a/include/ble/Bluetooth.h +++ b/include/ble/Bluetooth.h @@ -129,7 +129,7 @@ public: virtual void writeValue(const BluetoothGattCharacteristicPtr &c, const ByteBuffer &bytes) = 0; - virtual ByteBuffer readValue(const BluetoothGattCharacteristicPtr &c) = 0; + virtual ByteBuffer readValue(const BluetoothGattCharacteristicPtr &c, ByteBuffer& response) = 0; virtual void discoverServices() = 0; diff --git a/include/ble/ByteBuffer.h b/include/ble/ByteBuffer.h index 5e904c2..09deca5 100644 --- a/include/ble/ByteBuffer.h +++ b/include/ble/ByteBuffer.h @@ -1,13 +1,9 @@ #ifndef BYTE_STREAM_WRAPPER_H #define BYTE_STREAM_WRAPPER_H -#include <cstddef> #include <cstdint> -#include <cstdlib> -#include <iosfwd> #include <memory> #include <stdexcept> -#include <math.h> namespace FLOAT { static const uint32_t positive_infinity = 0x007FFFFE; @@ -38,8 +34,6 @@ public: class ByteBuffer { public: - static ByteBuffer alloc(std::size_t capacity); - template<size_t N> explicit ByteBuffer(uint8_t (&bytes)[N]) : zero(bytes), end_(&bytes[N]), cursor(bytes) {} @@ -58,7 +52,9 @@ public: } inline ByteBuffer &setCursor(size_t newCursor) { - cursor = (uint8_t *) &zero[newCursor]; + auto tmp = (uint8_t *) &zero[newCursor]; + assertCanAccessIndex(tmp); + cursor = tmp; return *this; } @@ -66,19 +62,19 @@ public: cursor += length; } - inline const uint8_t *cbegin() { + inline const uint8_t *cbegin() const { return zero; } - inline const uint8_t *cend() { + inline const uint8_t *cend() const { return end_; } - inline uint8_t *begin() { + inline uint8_t *begin() const { return const_cast<uint8_t *>(zero); } - inline uint8_t *end() { + inline uint8_t *end() const { return const_cast<uint8_t *>(end_); } @@ -120,6 +116,8 @@ public: void copy(uint8_t *bytes, size_t length) const; + void copy(ByteBuffer& other) const; + void reset(); /** @@ -147,4 +145,13 @@ private: uint8_t *cursor; }; +template<size_t N> +class StaticByteBuffer : public ByteBuffer { +public: + StaticByteBuffer() : ByteBuffer(raw) {} + +private: + uint8_t raw[N] = {}; +}; + #endif |