diff --git a/src/commonMain/kotlin/nl/astraeus/tba/TypedByteArray.kt b/src/commonMain/kotlin/nl/astraeus/tba/TypedByteArray.kt index d382968..2bc2217 100644 --- a/src/commonMain/kotlin/nl/astraeus/tba/TypedByteArray.kt +++ b/src/commonMain/kotlin/nl/astraeus/tba/TypedByteArray.kt @@ -1,12 +1,49 @@ package nl.astraeus.tba +/** + * A class that provides a typed interface to a byte array. + * + * TypedByteArray allows you to define a structured byte array with named fields of specific types and sizes. + * It serves as a base class for creating custom byte array structures with convenient property access. + * + * Example usage: + * ``` + * class PersonData : TypedByteArray( + * Type("name", DataType.STRING, 50), + * Type("age", DataType.BYTE), + * Type("height", DataType.SHORT) + * ) { + * var name by string("name") + * var age by byte("age") + * var height by short("height") + * } + * ``` + * + * @param types The types that define the structure of the byte array. + * Each type has a name, a data type, and optionally a size. + */ open class TypedByteArray( vararg types: Type ) { + /** + * The definition of the byte array structure. + */ val definition: ByteArrayDefinition = ByteArrayDefinition(*types) + + /** + * The handler for the underlying byte array data. + * This can be replaced to point to a different byte array. + */ var data: MutableByteArrayHandler = MutableByteArrayHandler(SlicedByteArray(definition.size)) + /** + * Maps type names to their Type objects. + */ val typeMap = mutableMapOf() + + /** + * Maps type names to their starting indices in the byte array. + */ val indexMap = mutableMapOf() init {