aboutsummaryrefslogtreecommitdiff
path: root/ByteBuffer.h
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-02-10 21:29:19 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2015-02-10 21:29:19 +0100
commitb55df0b8e46f46fea4d69f98a729cd237d77a6ed (patch)
tree25e12c22d844bb449dd08d7661d20d42ca8ab0f5 /ByteBuffer.h
parent1c97f6df59c825b26ecb18975fd9f62e14fc46ce (diff)
downloadble-toys-b55df0b8e46f46fea4d69f98a729cd237d77a6ed.tar.gz
ble-toys-b55df0b8e46f46fea4d69f98a729cd237d77a6ed.tar.bz2
ble-toys-b55df0b8e46f46fea4d69f98a729cd237d77a6ed.tar.xz
ble-toys-b55df0b8e46f46fea4d69f98a729cd237d77a6ed.zip
o wip.
Diffstat (limited to 'ByteBuffer.h')
-rw-r--r--ByteBuffer.h38
1 files changed, 31 insertions, 7 deletions
diff --git a/ByteBuffer.h b/ByteBuffer.h
index a7e9f9f..444943d 100644
--- a/ByteBuffer.h
+++ b/ByteBuffer.h
@@ -3,25 +3,49 @@
#include <cstdint>
#include <cstdlib>
+#include <string>
+#include <stdexcept>
+
+class ByteBufferException : public std::runtime_error {
+public:
+ ByteBufferException(std::string const &what) : std::runtime_error(what) {
+ }
+};
class ByteBuffer {
public:
- ByteBuffer(uint8_t *bytes, ssize_t size, ssize_t zero = 0);
+ ByteBuffer(uint8_t *bytes, size_t capacity, size_t size, size_t zero = 0);
+
+ inline size_t getSize() {
+ return size;
+ }
+
+ inline void setCursor(size_t newCursor) {
+ cursor = newCursor;
+ }
ByteBuffer &add8(uint8_t value);
ByteBuffer &add16le(uint16_t value);
- uint8_t get8(ssize_t index);
+ uint8_t get8(size_t index);
+
+ uint8_t get8();
+
+ uint16_t get16le();
+
+ void copy(uint8_t *bytes, size_t length);
private:
- void canAccessNextBytes(ssize_t count);
- void canAccessIndex(ssize_t count);
+ void checkAndUpdateSize(size_t count);
+
+ void canAccessIndex(size_t count);
uint8_t *bytes;
- ssize_t zero;
- ssize_t size;
- ssize_t ptr;
+ size_t zero;
+ size_t size;
+ size_t capacity;
+ size_t cursor;
};
#endif