X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=version2%2Fsrc%2FC%2FByteBuffer.cc;fp=version2%2Fsrc%2FC%2FByteBuffer.cc;h=0000000000000000000000000000000000000000;hb=786e40250f31eff04eec25bbcaae3cd916fedb14;hp=22e28cd1a543f3c9ac86283502e05e0da350c061;hpb=3f24bffc82ebfe2730308b63100af08645316577;p=iotcloud.git diff --git a/version2/src/C/ByteBuffer.cc b/version2/src/C/ByteBuffer.cc deleted file mode 100644 index 22e28cd..0000000 --- a/version2/src/C/ByteBuffer.cc +++ /dev/null @@ -1,81 +0,0 @@ -#include "ByteBuffer.h" -#include - -ByteBuffer::ByteBuffer(Array *array) : - buffer(array), - offset(0) { -} - -void ByteBuffer::put(char c) { - buffer->set(offset++, c); -} - -void ByteBuffer::putInt(int32_t l) { - buffer->set(offset++, (char)(l >> 24)); - buffer->set(offset++, (char)((l >> 16) & 0xff)); - buffer->set(offset++, (char)((l >> 8) & 0xff)); - buffer->set(offset++, (char)(l & 0xff)); -} - -void ByteBuffer::putLong(int64_t l) { - buffer->set(offset++, (char)(l >> 56)); - buffer->set(offset++, (char)((l >> 48) & 0xff)); - buffer->set(offset++, (char)((l >> 40) & 0xff)); - buffer->set(offset++, (char)((l >> 32) & 0xff)); - buffer->set(offset++, (char)((l >> 24) & 0xff)); - buffer->set(offset++, (char)((l >> 16) & 0xff)); - buffer->set(offset++, (char)((l >> 8) & 0xff)); - buffer->set(offset++, (char)(l & 0xff)); -} - -void ByteBuffer::put(Array *array) { - memcpy(&buffer->internalArray()[offset], array->internalArray(), array->length()); - offset += array->length(); -} - -int64_t ByteBuffer::getLong() { - char *array = &buffer->internalArray()[offset]; - offset += 8; - return (((int64_t)(unsigned char)array[0]) << 56) | - (((int64_t)(unsigned char)array[1]) << 48) | - (((int64_t)(unsigned char)array[2]) << 40) | - (((int64_t)(unsigned char)array[3]) << 32) | - (((int64_t)(unsigned char)array[4]) << 24) | - (((int64_t)(unsigned char)array[5]) << 16) | - (((int64_t)(unsigned char)array[6]) << 8) | - (((int64_t)(unsigned char)array[7])); -} - -int32_t ByteBuffer::getInt() { - char *array = &buffer->internalArray()[offset]; - offset += 4; - return (((int32_t)(unsigned char)array[0]) << 24) | - (((int32_t)(unsigned char)array[1]) << 16) | - (((int32_t)(unsigned char)array[2]) << 8) | - (((int32_t)(unsigned char)array[3])); -} - -char ByteBuffer::get() { - return buffer->get(offset++); -} - -void ByteBuffer::get(Array *array) { - memcpy(array->internalArray(), &buffer->internalArray()[offset], array->length()); - offset += array->length(); -} - -void ByteBuffer::position(int32_t newPosition) { - offset = newPosition; -} - -Array *ByteBuffer::array() { - return buffer; -} - -ByteBuffer *ByteBuffer_wrap(Array *array) { - return new ByteBuffer(array); -} - -ByteBuffer *ByteBuffer_allocate(uint size) { - return new ByteBuffer(new Array(size)); -}