Update to LCEMP's ByteArrayIO version

Fixes compilation since ours was missing some revisions from LCEMP
This commit is contained in:
Loki Rautio
2026-03-09 04:49:47 -05:00
parent 164f034b0a
commit b1277c0e1b
2 changed files with 131 additions and 115 deletions

View File

@@ -23,6 +23,7 @@ ByteArrayInputStream::ByteArrayInputStream(byteArray buf, unsigned int offset, u
else
{
count = offset + length;
}
this->buf = buf;
}
@@ -44,10 +45,14 @@ ByteArrayInputStream::ByteArrayInputStream(byteArray buf)
int ByteArrayInputStream::read()
{
if (pos >= count)
{
return -1;
}
else
{
return buf[pos++];
}
}
// Reads some number of bytes from the input stream and stores them into the buffer array b.
// The number of bytes actually read is returned as an integer. This method blocks until input data is available,
@@ -86,7 +91,9 @@ int ByteArrayInputStream::read(byteArray b)
int ByteArrayInputStream::read(byteArray b, unsigned int offset, unsigned int length)
{
if (pos == count)
{
return -1;
}
int k = min(length, count - pos);
XMemCpy(&b[offset], &buf[pos], k);
@@ -111,11 +118,14 @@ void ByteArrayInputStream::close()
// n - the number of bytes to be skipped.
// Returns:
// the actual number of bytes skipped.
int64_t ByteArrayInputStream::skip(int64_t n)
__int64 ByteArrayInputStream::skip(__int64 n)
{
int newPos = pos + n;
if(newPos > count) newPos = count;
if (newPos > count)
{
newPos = count;
}
int k = newPos - pos;
pos = newPos;
@@ -125,5 +135,8 @@ int64_t ByteArrayInputStream::skip(int64_t n)
ByteArrayInputStream::~ByteArrayInputStream()
{
if(buf.data != nullptr) delete [] buf.data;
if (buf.data != NULL)
{
delete[] buf.data;
}
}

View File

@@ -20,9 +20,11 @@ ByteArrayOutputStream::ByteArrayOutputStream(unsigned int size)
ByteArrayOutputStream::~ByteArrayOutputStream()
{
if (buf.data != nullptr)
if (buf.data != NULL)
{
delete[] buf.data;
}
}
// Writes the specified byte to this byte array output stream.
// Parameters:
@@ -31,9 +33,11 @@ void ByteArrayOutputStream::write(unsigned int b)
{
// If we will fill the buffer we need to make it bigger
if (count + 1 >= buf.length)
{
buf.resize(buf.length * 2);
}
buf[count] = static_cast<byte>(b);
buf[count] = (byte)b;
count++;
}
@@ -51,7 +55,6 @@ void ByteArrayOutputStream::write(byteArray b)
// len - the number of bytes to write.
void ByteArrayOutputStream::write(byteArray b, unsigned int offset, unsigned int length)
{
assert( b.length >= offset + length );
if (offset > b.length || length > b.length - offset)
{
@@ -61,6 +64,7 @@ void ByteArrayOutputStream::write(byteArray b, unsigned int offset, unsigned int
if (length > 0xFFFFFFFF - count)
{
return;
}
// If we will fill the buffer we need to make it bigger
if (count + length >= buf.length)
@@ -74,7 +78,6 @@ void ByteArrayOutputStream::write(byteArray b, unsigned int offset, unsigned int
}
XMemCpy(&buf[count], &b[offset], length);
//std::copy( b->data+offset, b->data+offset+length, buf->data + count ); // Or this instead?
count += length;
}