Cleanup old bytes after update

This commit is contained in:
2024-09-14 11:50:04 +02:00
parent 19f6aa9b15
commit da52a66de1

View File

@@ -1,5 +1,7 @@
package nl.astraeus.tba
import kotlin.math.min
class SlicedByteArray(
val data: ByteArray,
val offset: Int,
@@ -129,6 +131,11 @@ class SlicedByteArray(
}
this.setShort(offset + index, bytes.size.toShort())
bytes.copyInto(data, offset + index + 2)
data.fill(
0,
offset + index + 2 + bytes.size,
offset + index + maxLength
)
}
fun setClob(index: Int, value: String, maxLength: Int) {
@@ -138,6 +145,11 @@ class SlicedByteArray(
}
this.setInt(offset + index, bytes.size)
bytes.copyInto(data, offset + index + 4)
data.fill(
0,
offset + index + 4 + bytes.size,
offset + index + maxLength
)
}
fun setBlob(index: Int, bytes: SlicedByteArray, maxLength: Int) {
@@ -145,7 +157,12 @@ class SlicedByteArray(
throw IllegalArgumentException("Blob is too long")
}
this.setInt(offset + index, bytes.size)
bytes.copyInto(data, offset + index + 4, maxLength)
bytes.copyInto(data, offset + index + 4, bytes.size)
data.fill(
0,
offset + index + 4 + bytes.size,
offset + index + maxLength
)
}
companion object {