summaryrefslogtreecommitdiff
path: root/src/JSystem/JSupport/JSUMemoryStream.cpp
diff options
context:
space:
mode:
authorLuke Street <luke.street@encounterpc.com>2023-09-10 00:42:26 -0400
committerLuke Street <luke.street@encounterpc.com>2023-09-10 00:48:55 -0400
commitadb95b135c3d7498eba29bbd9728d345eed5a407 (patch)
tree655575b939c12067569263171b68c079b1a232c8 /src/JSystem/JSupport/JSUMemoryStream.cpp
parent81ac53f1317dafb3506ae3ed8b2820d40645c3c8 (diff)
Import project
Original repository: https://github.com/encounter/ww
Diffstat (limited to 'src/JSystem/JSupport/JSUMemoryStream.cpp')
-rw-r--r--src/JSystem/JSupport/JSUMemoryStream.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/JSystem/JSupport/JSUMemoryStream.cpp b/src/JSystem/JSupport/JSUMemoryStream.cpp
new file mode 100644
index 00000000..3981aeba
--- /dev/null
+++ b/src/JSystem/JSupport/JSUMemoryStream.cpp
@@ -0,0 +1,65 @@
+//
+// Generated by dtk
+// Translation Unit: JSUMemoryStream.cpp
+//
+
+#include "JSystem/JSupport/JSUMemoryStream.h"
+#include "MSL_c/string.h"
+
+/* 802BF704-802BF718 .text setBuffer__20JSUMemoryInputStreamFPCvl */
+void JSUMemoryInputStream::setBuffer(void const* pBuffer, s32 length) {
+ mBuffer = pBuffer;
+ mLength = length;
+ mPosition = 0;
+}
+
+/* 802BF718-802BF790 .text readData__20JSUMemoryInputStreamFPvl */
+u32 JSUMemoryInputStream::readData(void* pData, s32 length) {
+ if (mPosition + length > mLength) {
+ length = mLength - mPosition;
+ }
+
+ if (length > 0) {
+ memcpy(pData, (void*)((s32)mBuffer + mPosition), length);
+ mPosition += length;
+ }
+
+ return length;
+}
+
+/* 802BF790-802BF80C .text seekPos__20JSUMemoryInputStreamFl17JSUStreamSeekFrom */
+s32 JSUMemoryInputStream::seekPos(s32 pos, JSUStreamSeekFrom seekFrom) {
+ s32 oldPos = mPosition;
+
+ switch (seekFrom) {
+ case JSUStreamSeekFrom_SET:
+ mPosition = pos;
+ break;
+ case JSUStreamSeekFrom_END:
+ mPosition = mLength - pos;
+ break;
+ case JSUStreamSeekFrom_CUR:
+ mPosition += pos;
+ break;
+ }
+
+ if (mPosition < 0) {
+ mPosition = 0;
+ }
+
+ if (mPosition > mLength) {
+ mPosition = mLength;
+ }
+
+ return mPosition - oldPos;
+}
+
+/* 802BF80C-802BF814 .text getLength__20JSUMemoryInputStreamCFv */
+s32 JSUMemoryInputStream::getLength() const {
+ return mLength;
+}
+
+/* 802BF814-802BF81C .text getPosition__20JSUMemoryInputStreamCFv */
+s32 JSUMemoryInputStream::getPosition() const {
+ return mPosition;
+}