PlankResult BinaryFileInternal::dynamicMemoryReadCallback (PlankFileRef p, PlankP ptr, int maximumBytes, int* bytesReadOut) { plonk_assert (p != 0); plonk_assert (ptr != 0); plonk_assert (maximumBytes > 0); PlankResult result; UnsignedChar* src; ByteArray* array = static_cast<ByteArray*> (p->stream); LongLong size = array->length(); int bytesRead; result = PlankResult_OK; bytesRead = int (plonk::min (LongLong (maximumBytes), size - p->position)); if (bytesRead <= 0) { result = PlankResult_FileEOF; goto exit; } src = (UnsignedChar*)array->getArray() + p->position; Memory::copy (ptr, src, bytesRead); p->position += bytesRead; if (bytesReadOut) *bytesReadOut = bytesRead; exit: return result; }
PlankResult BinaryFileInternal::dynamicMemoryWriteCallback (PlankFileRef p, const void* data, const int maximumBytes) { plonk_assert (p != 0); plonk_assert (data != 0); plonk_assert (maximumBytes > 0); PlankResult result; UnsignedChar* dst; ByteArray* array = static_cast<ByteArray*> (p->stream); LongLong sizeNeeded; result = PlankResult_OK; sizeNeeded = p->position + maximumBytes; array->setSize (plonk::max ((int)sizeNeeded, array->length()), true); dst = (UnsignedChar*)array->getArray() + p->position; Memory::copy (dst, data, maximumBytes); p->position += maximumBytes; //exit: return result; }