|
@ -21,34 +21,35 @@ |
|
|
#include "DataBuffer.h" |
|
|
#include "DataBuffer.h" |
|
|
#include "Reference_String.h" |
|
|
#include "Reference_String.h" |
|
|
|
|
|
|
|
|
Jupiter::DataBuffer::DataBuffer() |
|
|
Jupiter::DataBuffer::DataBuffer() { |
|
|
{ |
|
|
|
|
|
Jupiter::DataBuffer::base = nullptr; |
|
|
Jupiter::DataBuffer::base = nullptr; |
|
|
Jupiter::DataBuffer::head = Jupiter::DataBuffer::base; |
|
|
Jupiter::DataBuffer::head = Jupiter::DataBuffer::base; |
|
|
Jupiter::DataBuffer::end = Jupiter::DataBuffer::head; |
|
|
Jupiter::DataBuffer::end = Jupiter::DataBuffer::head; |
|
|
Jupiter::DataBuffer::bufferSize = 0U; |
|
|
Jupiter::DataBuffer::bufferSize = 0U; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Jupiter::DataBuffer::DataBuffer(size_t size_) |
|
|
Jupiter::DataBuffer::DataBuffer(size_t size_) { |
|
|
{ |
|
|
Jupiter::DataBuffer::base = new uint8_t[size_]; |
|
|
Jupiter::DataBuffer::base = reinterpret_cast<uint8_t *>(malloc(size_)); |
|
|
|
|
|
Jupiter::DataBuffer::head = Jupiter::DataBuffer::base; |
|
|
Jupiter::DataBuffer::head = Jupiter::DataBuffer::base; |
|
|
Jupiter::DataBuffer::end = Jupiter::DataBuffer::head; |
|
|
Jupiter::DataBuffer::end = Jupiter::DataBuffer::head; |
|
|
Jupiter::DataBuffer::bufferSize = size_; |
|
|
Jupiter::DataBuffer::bufferSize = size_; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Jupiter::DataBuffer::DataBuffer(FILE *file) |
|
|
Jupiter::DataBuffer::DataBuffer(FILE *file) { |
|
|
{ |
|
|
if (fread(std::addressof(Jupiter::DataBuffer::bufferSize), sizeof(size_t), 1, file) != 1) { |
|
|
fread(std::addressof(Jupiter::DataBuffer::bufferSize), sizeof(size_t), 1, file); |
|
|
Jupiter::DataBuffer::base = nullptr; |
|
|
Jupiter::DataBuffer::base = reinterpret_cast<uint8_t *>(malloc(Jupiter::DataBuffer::bufferSize * sizeof(uint8_t))); |
|
|
Jupiter::DataBuffer::head = Jupiter::DataBuffer::base; |
|
|
|
|
|
Jupiter::DataBuffer::end = Jupiter::DataBuffer::head; |
|
|
|
|
|
Jupiter::DataBuffer::bufferSize = 0U; |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
Jupiter::DataBuffer::base = new uint8_t[Jupiter::DataBuffer::bufferSize * sizeof(uint8_t)]; |
|
|
Jupiter::DataBuffer::head = Jupiter::DataBuffer::base; |
|
|
Jupiter::DataBuffer::head = Jupiter::DataBuffer::base; |
|
|
Jupiter::DataBuffer::end = Jupiter::DataBuffer::head + Jupiter::DataBuffer::bufferSize; |
|
|
Jupiter::DataBuffer::end = Jupiter::DataBuffer::head + Jupiter::DataBuffer::bufferSize; |
|
|
int chr; |
|
|
int chr; |
|
|
while (Jupiter::DataBuffer::head != Jupiter::DataBuffer::end) |
|
|
while (Jupiter::DataBuffer::head != Jupiter::DataBuffer::end) { |
|
|
{ |
|
|
|
|
|
chr = fgetc(file); |
|
|
chr = fgetc(file); |
|
|
if (chr == EOF) |
|
|
if (chr == EOF) { |
|
|
{ |
|
|
|
|
|
Jupiter::DataBuffer::end = Jupiter::DataBuffer::head + 1; |
|
|
Jupiter::DataBuffer::end = Jupiter::DataBuffer::head + 1; |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
@ -57,18 +58,15 @@ Jupiter::DataBuffer::DataBuffer(FILE *file) |
|
|
Jupiter::DataBuffer::head = Jupiter::DataBuffer::base; |
|
|
Jupiter::DataBuffer::head = Jupiter::DataBuffer::base; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Jupiter::DataBuffer::DataBuffer(FILE *file, size_t size_) |
|
|
Jupiter::DataBuffer::DataBuffer(FILE *file, size_t size_) { |
|
|
{ |
|
|
|
|
|
Jupiter::DataBuffer::bufferSize = size_; |
|
|
Jupiter::DataBuffer::bufferSize = size_; |
|
|
Jupiter::DataBuffer::base = reinterpret_cast<uint8_t *>(malloc(Jupiter::DataBuffer::bufferSize * sizeof(uint8_t))); |
|
|
Jupiter::DataBuffer::base = new uint8_t[Jupiter::DataBuffer::bufferSize * sizeof(uint8_t)]; |
|
|
Jupiter::DataBuffer::head = Jupiter::DataBuffer::base; |
|
|
Jupiter::DataBuffer::head = Jupiter::DataBuffer::base; |
|
|
Jupiter::DataBuffer::end = Jupiter::DataBuffer::head + Jupiter::DataBuffer::bufferSize; |
|
|
Jupiter::DataBuffer::end = Jupiter::DataBuffer::head + Jupiter::DataBuffer::bufferSize; |
|
|
int chr; |
|
|
int chr; |
|
|
while (Jupiter::DataBuffer::head != Jupiter::DataBuffer::end) |
|
|
while (Jupiter::DataBuffer::head != Jupiter::DataBuffer::end) { |
|
|
{ |
|
|
|
|
|
chr = fgetc(file); |
|
|
chr = fgetc(file); |
|
|
if (chr == EOF) |
|
|
if (chr == EOF) { |
|
|
{ |
|
|
|
|
|
Jupiter::DataBuffer::end = Jupiter::DataBuffer::head + 1; |
|
|
Jupiter::DataBuffer::end = Jupiter::DataBuffer::head + 1; |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
@ -77,43 +75,37 @@ Jupiter::DataBuffer::DataBuffer(FILE *file, size_t size_) |
|
|
Jupiter::DataBuffer::head = Jupiter::DataBuffer::base; |
|
|
Jupiter::DataBuffer::head = Jupiter::DataBuffer::base; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Jupiter::DataBuffer::~DataBuffer() |
|
|
Jupiter::DataBuffer::~DataBuffer() { |
|
|
{ |
|
|
delete[] Jupiter::DataBuffer::base; // TODO: replace with std::unique_ptr
|
|
|
free(Jupiter::DataBuffer::base); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Jupiter::DataBuffer::push(const uint8_t *data, size_t size_) |
|
|
void Jupiter::DataBuffer::push(const uint8_t *data, size_t size_) { |
|
|
{ |
|
|
|
|
|
Jupiter::DataBuffer::secure(size_); |
|
|
Jupiter::DataBuffer::secure(size_); |
|
|
while (size_-- != 0) |
|
|
while (size_-- != 0) |
|
|
*Jupiter::DataBuffer::end++ = *data++; |
|
|
*Jupiter::DataBuffer::end++ = *data++; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Jupiter::DataBuffer::peek_from(FILE *file) |
|
|
void Jupiter::DataBuffer::peek_from(FILE *file) { |
|
|
{ |
|
|
|
|
|
fpos_t pos; |
|
|
fpos_t pos; |
|
|
fgetpos(file, &pos); |
|
|
fgetpos(file, &pos); |
|
|
Jupiter::DataBuffer::pop_from(file); |
|
|
Jupiter::DataBuffer::pop_from(file); |
|
|
fsetpos(file, &pos); |
|
|
fsetpos(file, &pos); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Jupiter::DataBuffer::peek_from(FILE *file, size_t size_) |
|
|
void Jupiter::DataBuffer::peek_from(FILE *file, size_t size_) { |
|
|
{ |
|
|
|
|
|
fpos_t pos; |
|
|
fpos_t pos; |
|
|
fgetpos(file, &pos); |
|
|
fgetpos(file, &pos); |
|
|
Jupiter::DataBuffer::pop_from(file, size_); |
|
|
Jupiter::DataBuffer::pop_from(file, size_); |
|
|
fsetpos(file, &pos); |
|
|
fsetpos(file, &pos); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Jupiter::DataBuffer::pop_from(FILE *file) |
|
|
void Jupiter::DataBuffer::pop_from(FILE *file) { |
|
|
{ |
|
|
|
|
|
size_t size_; |
|
|
size_t size_; |
|
|
fread(&size_, sizeof(size_t), 1, file); |
|
|
fread(&size_, sizeof(size_t), 1, file); |
|
|
Jupiter::DataBuffer::pop_from(file, size_); |
|
|
Jupiter::DataBuffer::pop_from(file, size_); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Jupiter::DataBuffer::pop_from(FILE *file, size_t size_) |
|
|
void Jupiter::DataBuffer::pop_from(FILE *file, size_t size_) { |
|
|
{ |
|
|
|
|
|
Jupiter::DataBuffer::secure(size_); |
|
|
Jupiter::DataBuffer::secure(size_); |
|
|
int chr; |
|
|
int chr; |
|
|
while (size_-- != 0) |
|
|
while (size_-- != 0) |
|
@ -125,38 +117,32 @@ void Jupiter::DataBuffer::pop_from(FILE *file, size_t size_) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Jupiter::DataBuffer::copy_to(FILE *file) |
|
|
void Jupiter::DataBuffer::copy_to(FILE *file) { |
|
|
{ |
|
|
|
|
|
size_t data_size = Jupiter::DataBuffer::size(); |
|
|
size_t data_size = Jupiter::DataBuffer::size(); |
|
|
fwrite(&data_size, sizeof(size_t), 1, file); |
|
|
fwrite(&data_size, sizeof(size_t), 1, file); |
|
|
Jupiter::DataBuffer::copy_to(file, Jupiter::DataBuffer::size()); |
|
|
Jupiter::DataBuffer::copy_to(file, Jupiter::DataBuffer::size()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Jupiter::DataBuffer::copy_to(FILE *file, size_t size_) |
|
|
void Jupiter::DataBuffer::copy_to(FILE *file, size_t size_) { |
|
|
{ |
|
|
|
|
|
fwrite(Jupiter::DataBuffer::head, sizeof(uint8_t), size_, file); |
|
|
fwrite(Jupiter::DataBuffer::head, sizeof(uint8_t), size_, file); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Jupiter::DataBuffer::copy_to(FILE *file, size_t index, size_t size_) |
|
|
void Jupiter::DataBuffer::copy_to(FILE *file, size_t index, size_t size_) { |
|
|
{ |
|
|
|
|
|
fwrite(Jupiter::DataBuffer::head + index, sizeof(uint8_t), size_, file); |
|
|
fwrite(Jupiter::DataBuffer::head + index, sizeof(uint8_t), size_, file); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Jupiter::DataBuffer::push_to(FILE *file) |
|
|
void Jupiter::DataBuffer::push_to(FILE *file) { |
|
|
{ |
|
|
|
|
|
Jupiter::DataBuffer::copy_to(file); |
|
|
Jupiter::DataBuffer::copy_to(file); |
|
|
Jupiter::DataBuffer::head = Jupiter::DataBuffer::base; |
|
|
Jupiter::DataBuffer::head = Jupiter::DataBuffer::base; |
|
|
Jupiter::DataBuffer::end = Jupiter::DataBuffer::head; |
|
|
Jupiter::DataBuffer::end = Jupiter::DataBuffer::head; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Jupiter::DataBuffer::push_to(FILE *file, size_t size_) |
|
|
void Jupiter::DataBuffer::push_to(FILE *file, size_t size_) { |
|
|
{ |
|
|
|
|
|
Jupiter::DataBuffer::copy_to(file, size_); |
|
|
Jupiter::DataBuffer::copy_to(file, size_); |
|
|
Jupiter::DataBuffer::head += size_; |
|
|
Jupiter::DataBuffer::head += size_; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
size_t Jupiter::DataBuffer::shrink() |
|
|
size_t Jupiter::DataBuffer::shrink() { |
|
|
{ |
|
|
|
|
|
Jupiter::DataBuffer::bufferSize = Jupiter::DataBuffer::size(); |
|
|
Jupiter::DataBuffer::bufferSize = Jupiter::DataBuffer::size(); |
|
|
|
|
|
|
|
|
if (Jupiter::DataBuffer::base != Jupiter::DataBuffer::head) |
|
|
if (Jupiter::DataBuffer::base != Jupiter::DataBuffer::head) |
|
@ -168,8 +154,7 @@ size_t Jupiter::DataBuffer::shrink() |
|
|
return Jupiter::DataBuffer::bufferSize; |
|
|
return Jupiter::DataBuffer::bufferSize; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
size_t Jupiter::DataBuffer::expandBuffer(size_t size_) |
|
|
size_t Jupiter::DataBuffer::expandBuffer(size_t size_) { |
|
|
{ |
|
|
|
|
|
Jupiter::DataBuffer::bufferSize += size_; |
|
|
Jupiter::DataBuffer::bufferSize += size_; |
|
|
size_ = Jupiter::DataBuffer::end - Jupiter::DataBuffer::head; |
|
|
size_ = Jupiter::DataBuffer::end - Jupiter::DataBuffer::head; |
|
|
|
|
|
|
|
@ -182,8 +167,7 @@ size_t Jupiter::DataBuffer::expandBuffer(size_t size_) |
|
|
return Jupiter::DataBuffer::bufferSize; |
|
|
return Jupiter::DataBuffer::bufferSize; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Jupiter::DataBuffer::secure(size_t size_) |
|
|
void Jupiter::DataBuffer::secure(size_t size_) { |
|
|
{ |
|
|
|
|
|
size_t data_size = Jupiter::DataBuffer::end - Jupiter::DataBuffer::head; |
|
|
size_t data_size = Jupiter::DataBuffer::end - Jupiter::DataBuffer::head; |
|
|
size_ += data_size; |
|
|
size_ += data_size; |
|
|
if (Jupiter::DataBuffer::bufferSize < size_) |
|
|
if (Jupiter::DataBuffer::bufferSize < size_) |
|
@ -198,8 +182,7 @@ void Jupiter::DataBuffer::secure(size_t size_) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Jupiter::DataBuffer::setBufferSize(size_t size_) |
|
|
void Jupiter::DataBuffer::setBufferSize(size_t size_) { |
|
|
{ |
|
|
|
|
|
Jupiter::DataBuffer::bufferSize = size_; |
|
|
Jupiter::DataBuffer::bufferSize = size_; |
|
|
size_ = Jupiter::DataBuffer::end - Jupiter::DataBuffer::head; |
|
|
size_ = Jupiter::DataBuffer::end - Jupiter::DataBuffer::head; |
|
|
|
|
|
|
|
@ -211,23 +194,19 @@ void Jupiter::DataBuffer::setBufferSize(size_t size_) |
|
|
Jupiter::DataBuffer::end = Jupiter::DataBuffer::head + size_; |
|
|
Jupiter::DataBuffer::end = Jupiter::DataBuffer::head + size_; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
size_t Jupiter::DataBuffer::size() const |
|
|
size_t Jupiter::DataBuffer::size() const { |
|
|
{ |
|
|
|
|
|
return Jupiter::DataBuffer::end - Jupiter::DataBuffer::head; |
|
|
return Jupiter::DataBuffer::end - Jupiter::DataBuffer::head; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
size_t Jupiter::DataBuffer::getBufferSize() const |
|
|
size_t Jupiter::DataBuffer::getBufferSize() const { |
|
|
{ |
|
|
|
|
|
return Jupiter::DataBuffer::bufferSize; |
|
|
return Jupiter::DataBuffer::bufferSize; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
uint8_t *Jupiter::DataBuffer::getHead() const |
|
|
uint8_t *Jupiter::DataBuffer::getHead() const { |
|
|
{ |
|
|
|
|
|
return Jupiter::DataBuffer::head; |
|
|
return Jupiter::DataBuffer::head; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Jupiter::DataBuffer::empty() |
|
|
void Jupiter::DataBuffer::empty() { |
|
|
{ |
|
|
|
|
|
Jupiter::DataBuffer::head = Jupiter::DataBuffer::base; |
|
|
Jupiter::DataBuffer::head = Jupiter::DataBuffer::base; |
|
|
Jupiter::DataBuffer::end = Jupiter::DataBuffer::head; |
|
|
Jupiter::DataBuffer::end = Jupiter::DataBuffer::head; |
|
|
} |
|
|
} |