Add constructor to SlicedByteArray and update version to 0.2.6

Introduce a new constructor in `SlicedByteArray` for initializing from a ByteArray. Updated `build.gradle.kts` to bump the version to 0.2.6, and made minor adjustments to `readme.md` to improve clarity and consistency.
This commit is contained in:
2024-12-14 11:19:22 +01:00
parent 69fa23a7a9
commit 232d8fe92a
3 changed files with 12 additions and 10 deletions

View File

@@ -6,7 +6,7 @@ plugins {
}
group = "nl.astraeus"
version = "0.2.5"
version = "0.2.6"
repositories {
mavenCentral()

View File

@@ -11,26 +11,26 @@ to convert the bytes to the property and back when the property is accessed. The
This is what a definition could look like:
```kotlin
class Person : TypedByteArray(
class Person() : TypedByteArray(
Type("id", DataType.LONG),
Type("name", DataType.STRING, 100),
Type("age", DataType.INT),
Type("rate", DataType.DOUBLE),
Type("description", DataType.CLOB, 100000)
) {
var id by LongProperty("id")
var name by StringProperty("name")
var age by IntProperty("age")
var rate by DoubleProperty("rate")
var description by ClobProperty("description")
var id by long("id")
var name by string("name")
var age by int("age")
var rate by double("rate")
var description by clob("description")
constructor(name: String, age: Int) : this() {
this.name = name
this.age = age
this.rate = 1.0
this.description = "Nothing here yet."
}
constructor(data: ByteArray): this() {
check(data.size == definition.size) {
"Invalid data size: ${data.size} != ${definition.size}"
@@ -42,7 +42,7 @@ class Person : TypedByteArray(
```
The different between STRING and CLOB is the maximum size (32kb vs 2gb). For any type where the length isn't fixed we need to provide max size.
When such a type is updated, for example we update a string with a shorter string the remaining bytes are zeroed to make compression as efficient as possible.
When such a type is updated, for example we update a string with a shorter string, the remaining bytes are zeroed to make compression as efficient as possible.
Strings are stored as UTF-8 bytes, there is also a CachedStringProperty which will keep a copy of the string so it isn't converted to a
native string every time it's accessed.

View File

@@ -8,6 +8,8 @@ class SlicedByteArray(
val size: Int
get() = length
constructor(array: ByteArray) : this(array, 0, array.size)
constructor(size: Int) : this(ByteArray(size), 0, size)
operator fun get(index: Int): Byte {