Add KDoc documentation for TypedByteArray
Enhanced `TypedByteArray` with detailed KDoc comments to clarify its purpose, structure, and usage. Included example usage and descriptions for key properties.
This commit is contained in:
@@ -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<String, Type>()
|
||||
|
||||
/**
|
||||
* Maps type names to their starting indices in the byte array.
|
||||
*/
|
||||
val indexMap = mutableMapOf<String, Int>()
|
||||
|
||||
init {
|
||||
|
||||
Reference in New Issue
Block a user