-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Korge memory split #2170
Korge memory split #2170
Changes from all commits
eca22d0
5f888ad
9713143
8d07e95
42e9d88
17aabd5
78fdbfe
1441d0a
bde1518
efb14a9
f28972a
d088a50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package korlibs.memory | ||
|
||
import korlibs.number.* | ||
|
||
/** | ||
* Analogous to [StringBuilder] but for [ByteArray]. Allows to [append] values to end calling [toByteArray]. | ||
* Provides some methods like [s16LE] or [f32BE] to append specific bit representations easily. | ||
*/ | ||
fun ByteArrayBuilder.f16(v: Half, little: Boolean): ByteArrayBuilder = s16(v.rawBits.toInt(), little) | ||
fun ByteArrayBuilder.f16LE(v: Half): ByteArrayBuilder = s16LE(v.rawBits.toInt()) | ||
fun ByteArrayBuilder.f16BE(v: Half): ByteArrayBuilder = s16BE(v.rawBits.toInt()) | ||
|
||
fun ByteArrayBuilderLE.f16(v: Half): ByteArrayBuilder = bab.f16LE(v) | ||
fun ByteArrayBuilderBE.f16(v: Half): ByteArrayBuilder = bab.f16BE(v) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package korlibs.memory | ||
|
||
import korlibs.number.Half | ||
|
||
private fun ByteArray.u8(offset: Int): Int = this[offset].toInt() and 0xFF | ||
private inline fun ByteArray.get16LE(offset: Int): Int = (u8(offset + 0) shl 0) or (u8(offset + 1) shl 8) | ||
private inline fun ByteArray.get16BE(offset: Int): Int = (u8(offset + 1) shl 0) or (u8(offset + 0) shl 8) | ||
|
||
// Signed | ||
fun ByteArray.getF16LE(offset: Int): Half = Half.fromBits(get16LE(offset)) | ||
fun ByteArray.getF16BE(offset: Int): Half = Half.fromBits(get16BE(offset)) | ||
|
||
// Custom Endian | ||
fun ByteArray.getF16(offset: Int, littleEndian: Boolean): Half = if (littleEndian) getF16LE(offset) else getF16BE(offset) | ||
fun ByteArray.setF16(offset: Int, value: Half, littleEndian: Boolean) { if (littleEndian) setF16LE(offset, value) else setF16BE(offset, value) } | ||
fun ByteArray.setF16LE(offset: Int, value: Half) { set16LE(offset + 0, value.toRawBits().toInt()) } | ||
fun ByteArray.setF16BE(offset: Int, value: Half) { set16BE(offset + 0, value.toRawBits().toInt()) } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package korlibs.memory | ||
|
||
import korlibs.number.Half | ||
|
||
@Deprecated("", ReplaceWith("getF16LE(o)")) | ||
fun ByteArray.readF16LE(o: Int): Half = getF16LE(o) | ||
@Deprecated("", ReplaceWith("getF16BE(o)")) | ||
fun ByteArray.readF16BE(o: Int): Half = getF16BE(o) | ||
@Deprecated("", ReplaceWith("getF16(o, little)")) | ||
fun ByteArray.readF16(o: Int, little: Boolean): Half = getF16(o, little) | ||
@Deprecated("", ReplaceWith("setF16(o, v, little)")) | ||
fun ByteArray.writeF16(o: Int, v: Half, little: Boolean) = setF16(o, v, little) | ||
@Deprecated("", ReplaceWith("setF16LE(o, v)")) | ||
fun ByteArray.writeF16LE(o: Int, v: Half) = setF16LE(o, v) | ||
@Deprecated("", ReplaceWith("setF16BE(o, v)")) | ||
fun ByteArray.writeF16BE(o: Int, v: Half) = setF16BE(o, v) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package korlibs.memory | ||
|
||
import korlibs.number.* | ||
|
||
|
||
fun ByteArrayReader.f16(little: Boolean): Half = Half.fromBits(s16(little)) | ||
fun ByteArrayReader.f16LE(): Half = Half.fromBits(s16LE()) | ||
fun ByteArrayReader.f16BE(): Half = Half.fromBits(s16BE()) | ||
fun ByteArrayReaderLE.f16(): Half = bar.f16LE() | ||
fun ByteArrayReaderBE.f16(): Half = bar.f16BE() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import korlibs.* | ||
|
||
description = "Korlibs Memory" | ||
|
||
project.extensions.extraProperties.properties.apply { | ||
applyProjectProperties( | ||
"https://raw.githubusercontent.com/korlibs/korge/main/korlibs-memory", | ||
"Public Domain", | ||
"https://raw.githubusercontent.com/korlibs/korge/main/korlibs-memory/LICENSE" | ||
) | ||
} | ||
|
||
dependencies { | ||
commonMainApi(libs.kotlinx.coroutines.core) | ||
commonMainApi(libs.kotlinx.atomicfu) | ||
commonTestApi(libs.kotlinx.coroutines.test) | ||
commonMainApi(project(":korlibs-math-core")) | ||
commonMainApi(project(":korlibs-platform")) | ||
commonMainApi(project(":korlibs-util")) | ||
commonMainApi(project(":korlibs-crypto")) | ||
} | ||
Comment on lines
+14
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should evaluate those.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. util and math-core are used. We should avoid copiing stuff to private. I check the other two There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, let's keep it as it is for now. We can optimize dependencies later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could not remove any of them |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't these exposed publicly already in other file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont know about that. They were private in the original class