aboutsummaryrefslogtreecommitdiff
path: root/ByteBuffer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ByteBuffer.cpp')
-rw-r--r--ByteBuffer.cpp25
1 files changed, 15 insertions, 10 deletions
diff --git a/ByteBuffer.cpp b/ByteBuffer.cpp
index 07672ec..2b2f33b 100644
--- a/ByteBuffer.cpp
+++ b/ByteBuffer.cpp
@@ -3,23 +3,25 @@
#include <sstream>
#include <iomanip>
#include <cassert>
+#include <elf.h>
+#include <stdint-gcc.h>
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) {