aboutsummaryrefslogtreecommitdiff
path: root/ByteBuffer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ByteBuffer.cpp')
-rw-r--r--ByteBuffer.cpp31
1 files changed, 15 insertions, 16 deletions
diff --git a/ByteBuffer.cpp b/ByteBuffer.cpp
index d60ad6f..820c638 100644
--- a/ByteBuffer.cpp
+++ b/ByteBuffer.cpp
@@ -5,46 +5,46 @@
using namespace std;
-ByteBuffer::ByteBuffer(const uint8_t *bytes, size_t capacity) :
- bytes(bytes), capacity(capacity), zero(&bytes[0]), end(&bytes[capacity]) {
- ptr = (uint8_t *) &bytes[0];
+ByteBuffer::ByteBuffer(const std::shared_ptr<uint8_t> bytes, size_t capacity) :
+ bytes(bytes), capacity(capacity), zero(bytes.get()), end(&bytes.get()[capacity]) {
+ ptr = (uint8_t *) zero;
}
-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]) {
+ByteBuffer::ByteBuffer(const std::shared_ptr<uint8_t> bytes, size_t capacity, size_t zero, size_t size) :
+ bytes(bytes), capacity(capacity), zero(&bytes.get()[zero]), end(&bytes.get()[size]) {
assert(zero <= size);
assert(size <= capacity);
- ptr = (uint8_t *) &bytes[0];
+ ptr = (uint8_t *) zero;
}
-ByteBuffer::ByteBuffer(const uint8_t *bytes, size_t capacity, const uint8_t *zero, const uint8_t *end) :
+ByteBuffer::ByteBuffer(const std::shared_ptr<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) {
+ByteBuffer &ByteBuffer::write8(uint8_t value) {
checkAndUpdateEnd(1);
(*ptr++) = value;
return *this;
}
-ByteBuffer &ByteBuffer::add16le(uint16_t value) {
+ByteBuffer &ByteBuffer::write16le(uint16_t value) {
checkAndUpdateEnd(2);
(*ptr++) = (uint8_t) (value & 0xff);
(*ptr++) = (uint8_t) ((value >> 8) & 0xff);
return *this;
}
-uint8_t ByteBuffer::get8(size_t index) {
+uint8_t ByteBuffer::get8(size_t index) const {
assertCanAccessRelative(index);
- return *ptr++;
+ return ptr[index];
}
-uint8_t ByteBuffer::get8() {
+uint8_t ByteBuffer::read8() {
assertCanAccessRelative(0);
return *ptr++;
}
-uint16_t ByteBuffer::get16le() {
+uint16_t ByteBuffer::read16le() {
assertCanAccessRelative(0);
uint16_t value;
value = *ptr++;
@@ -52,11 +52,10 @@ uint16_t ByteBuffer::get16le() {
return value;
}
-void ByteBuffer::copy(uint8_t *bytes, size_t length) {
- assertCanAccessRelative(length);
+void ByteBuffer::copy(uint8_t *bytes, size_t length) const {
+ assertCanAccessRelative(length - 1);
memcpy(bytes, ptr, length);
- ptr += length;
}
ByteBuffer ByteBuffer::view() const {