64 this->buffer_.clear();
71 if (this->getMaxBufferSize() >= byte_size)
73 LOG_COMM(
"Initializing buffer to size: %d", byte_size);
74 this->load((
void*)buffer, byte_size);
79 LOG_ERROR(
"Failed to initialize byte array, buffer size: %u greater than max: %u",
80 byte_size, this->getMaxBufferSize());
94 LOG_WARN(
"Byte array copy not performed, buffer to copy is empty");
100 out.assign(buffer_.begin(), buffer_.end());
105 void ByteArray::swap(
void *value,
shared_int byteSize)
107 LOG_COMM(
"Executing byte swapping");
109 LOG_COMM(
"Value (swapping-input): %u", (
unsigned int)(*(
unsigned int*)value));
110 for (
unsigned int i = 0; i < byteSize / 2; i++)
112 unsigned int endIndex = byteSize - i - 1;
113 char endByte = ((
char*)value)[endIndex];
114 unsigned int endInt = endByte;
116 unsigned int beginIndex = i;
117 char beginByte = ((
char*)value)[beginIndex];
118 unsigned int beginInt = beginByte;
120 LOG_COMM(
"Swap beginIndex i: %u, endIndex: %u, begin[]: %u, end[]: %u",
121 beginIndex, endIndex, beginInt, endInt);
122 ((
char*)value)[endIndex] = beginByte;
123 ((
char*)value)[beginIndex] = endByte;
125 LOG_COMM(
"Value (swapping-output): %u", (
unsigned int)(*(
unsigned int*)value));
130 char* ByteArray::getRawDataPtr()
132 this->copyTo( this->getRawDataPtr_buffer_ );
133 return &getRawDataPtr_buffer_[0];
150 LOG_COMM(
"Value (loading-input): %f", value);
152 LOG_COMM(
"Value (loading-output): %f", value);
161 LOG_COMM(
"Value (loading-input): %d", value);
163 LOG_COMM(
"Value (loading-output): %d", value);
166 return this->load(&value,
sizeof(
shared_int));
171 LOG_COMM(
"Executing byte array load through simple serialize");
172 return value.
load(
this);
177 LOG_COMM(
"Executing byte array load through byte array");
178 std::deque<char>& src = value.
buffer_;
179 std::deque<char>& dest = this->buffer_;
181 if (this->getBufferSize()+value.
getBufferSize() > this->getMaxBufferSize())
183 LOG_ERROR(
"Additional data would exceed buffer size");
187 dest.insert(dest.end(), src.begin(), src.end());
196 LOG_COMM(
"Executing byte array load through void*, size: %d", byte_size);
200 LOG_ERROR(
"NULL point passed into load method");
203 if (this->getBufferSize()+byte_size > this->getMaxBufferSize())
205 LOG_ERROR(
"Additional data would exceed buffer size");
211 char* bytePtr = (
char*)value;
212 this->buffer_.insert(this->buffer_.end(), bytePtr, bytePtr + byte_size);
216 catch (std::exception)
242 bool rtn = this->unload(&value,
sizeof(
shared_real));
245 LOG_COMM(
"Value (unloading-input): %f", value);
247 LOG_COMM(
"Value (unloading-output): %f", value);
255 bool rtn = this->unload(&value,
sizeof(
shared_int));
258 LOG_COMM(
"Value (unloading-input): %d", value);
260 LOG_COMM(
"Value (unloading-output): %d", value);
267 LOG_COMM(
"Executing byte array unload through simple serialize");
268 return value.
unload(
this);
274 LOG_COMM(
"Executing byte array unload through byte array");
277 if (byte_size <= this->getBufferSize())
279 std::deque<char>& src = this->buffer_;
280 std::deque<char>& dest = value.
buffer_;
282 dest.insert(dest.end(), src.end()-byte_size, src.end());
283 src.erase(src.end()-byte_size, src.end());
288 LOG_ERROR(
"Buffer smaller than requested size.");
299 LOG_COMM(
"Executing byte array unload through void*, size: %d", byteSize);
303 LOG_ERROR(
"NULL point passed into unload method");
307 if (byteSize <= this->getBufferSize())
309 std::deque<char>& src = this->buffer_;
311 std::copy(src.end()-byteSize, src.end(), (
char*)value);
312 src.erase(src.end()-byteSize, src.end());
317 LOG_ERROR(
"Buffer is smaller than requested byteSize.");
336 bool rtn = this->unloadFront(&value,
sizeof(
shared_real));
339 LOG_COMM(
"Value (unloading-input): %f", value);
341 LOG_COMM(
"Value (unloading-output): %f", value);
348 bool rtn = this->unloadFront(&value,
sizeof(
shared_int));
351 LOG_COMM(
"Value (unloading-input): %d", value);
353 LOG_COMM(
"Value (unloading-output): %d", value);
362 LOG_COMM(
"Executing byte array unloadFront through void*, size: %d", byteSize);
366 LOG_ERROR(
"NULL point passed into unloadFront method");
370 if (byteSize <= this->getBufferSize())
372 std::deque<char>& src = this->buffer_;
374 std::copy(src.begin(), src.begin()+byteSize, (
char*)value);
375 src.erase(src.begin(), src.begin()+byteSize);
380 LOG_ERROR(
"Buffer is smaller than requested byteSize.");
389 return this->buffer_.size();
394 return this->buffer_.max_size();