From 0d0749ff0f842f10fea6929dc466e4e1be458234 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Tue, 17 Feb 2015 16:20:30 +0100 Subject: o More tests, more passing tests. --- ByteBuffer.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'ByteBuffer.cpp') diff --git a/ByteBuffer.cpp b/ByteBuffer.cpp index 07672ec..2b2f33b 100644 --- a/ByteBuffer.cpp +++ b/ByteBuffer.cpp @@ -3,23 +3,25 @@ #include #include #include +#include +#include using namespace std; -ByteBuffer::ByteBuffer(uint8_t *bytes, size_t capacity) : - bytes(bytes), capacity(capacity), zero(&bytes[0]), end(&bytes[capacity]) { - ptr = &bytes[0]; +ByteBuffer::ByteBuffer(const uint8_t *bytes, size_t capacity) : + bytes(bytes), capacity(capacity), zero(&bytes[0]), end(&bytes[0]) { + ptr = (uint8_t *) &bytes[0]; } -ByteBuffer::ByteBuffer(uint8_t *bytes, size_t capacity, size_t zero, size_t size) : +ByteBuffer::ByteBuffer(const uint8_t *bytes, size_t capacity, size_t zero, size_t size) : bytes(bytes), capacity(capacity), zero(&bytes[0]), end(&bytes[size]) { assert(zero <= size); assert(size <= capacity); - ptr = &bytes[0]; + ptr = (uint8_t *) &bytes[0]; } -ByteBuffer::ByteBuffer(const uint8_t *bytes, size_t capacity, uint8_t *zero, uint8_t *end) : - bytes(bytes), capacity(capacity), zero(zero), end(end), ptr(zero) { +ByteBuffer::ByteBuffer(const uint8_t *bytes, size_t capacity, const uint8_t *zero, const uint8_t *end) : + bytes(bytes), capacity(capacity), zero(zero), end(end), ptr((uint8_t *) zero) { } ByteBuffer &ByteBuffer::add8(uint8_t value) { @@ -61,15 +63,18 @@ void ByteBuffer::copy(uint8_t *bytes, size_t length) { } ByteBuffer ByteBuffer::view() const { - DF << "cursor=" << getCursor() << ", size=" << getSize(); - return view(end - ptr); +// DF << "cursor=" << getCursor() << ", size=" << getSize() << ", new size=" << end - ptr << ", ptr=" << (uint64_t) ptr << ", zero=" << (uint64_t) zero; + return view(ptr, end); } ByteBuffer ByteBuffer::view(size_t length) const { - assertCanAccessRelative(length); return ByteBuffer(bytes, length, ptr, ptr + length); } +ByteBuffer ByteBuffer::view(uint8_t *ptr, const uint8_t *end) const { + return ByteBuffer(bytes, end - ptr, ptr, end); +} + void ByteBuffer::checkAndUpdateEnd(size_t newBytes) { uint8_t *newPtr = ptr + newBytes; if (newPtr >= end) { -- cgit v1.2.3