+++ /dev/null
-#include "ByteBuffer.h"
-#include <string.h>
-
-ByteBuffer::ByteBuffer(Array<char> *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<char> *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<char> *array) {
- memcpy(array->internalArray(), &buffer->internalArray()[offset], array->length());
- offset += array->length();
-}
-
-void ByteBuffer::position(int32_t newPosition) {
- offset = newPosition;
-}
-
-Array<char> *ByteBuffer::array() {
- return buffer;
-}
-
-ByteBuffer *ByteBuffer_wrap(Array<char> *array) {
- return new ByteBuffer(array);
-}
-
-ByteBuffer *ByteBuffer_allocate(uint size) {
- return new ByteBuffer(new Array<char>(size));
-}