Package-level declarations

Types

Link copied to clipboard

Builds a ByteArray from primary types

Link copied to clipboard

Byte order used for encoding and decoding primary types into a ByteArray

Link copied to clipboard
object ByteUtils
Link copied to clipboard

Character encoding

Link copied to clipboard
value class Int24(val value: Int) : Comparable<Int24>

A 24-bit representation of a (signed) Integer

Link copied to clipboard
value class Int40(val value: Long) : Comparable<Int40>

A 40-bit representation of a (signed) Integer

Link copied to clipboard
value class Int48(val value: Long) : Comparable<Int48>

A 48-bit representation of a (signed) Integer

Link copied to clipboard

Exception thrown when a character cannot be encoded into UTF-8

Link copied to clipboard
value class MedFloat16(val value: Double) : Comparable<MedFloat16>

A 16-bit representation of a floating point number consisting of a 4 bit exponent and 12 bit mantissa so that 10^exponent * mantissa (IEEE-11073)

Link copied to clipboard
value class MedFloat32(val value: Double) : Comparable<MedFloat32>

A 32-bit representation of a floating point number consisting of a 8 bit exponent and 24 bit mantissa so that 10^exponent * mantissa (IEEE-11073)

Link copied to clipboard
data class StringEncodingSettings(val endMarking: StringEncodingSettings.EndMarking = LengthPrefix.ByteLength, val encoding: Encoding = UTF_8)

Settings to determine how a String should be encoded into a ByteArray.

Link copied to clipboard
value class UInt24(val value: UInt) : Comparable<UInt24>

A 24-bit representation of an (unsigned) Integer

Link copied to clipboard
value class UInt40(val value: ULong) : Comparable<UInt40>

A 40-bit representation of an (unsigned) Integer

Link copied to clipboard
value class UInt48(val value: ULong) : Comparable<UInt48>

A 48-bit representation of an (unsigned) Integer

Properties

Link copied to clipboard

Returns the number of Bytes required to encode a String using ASCII.

Link copied to clipboard

Returns the number of Bytes required to encode a String using UTF-16.

Link copied to clipboard

Returns the number of Bytes required to encode a String using UTF-8.

Functions

Link copied to clipboard
infix fun Int24.and(other: Int24): Int24
infix fun Int40.and(other: Int40): Int40
infix fun Int48.and(other: Int48): Int48

Performs a bitwise AND operation between the two values.

infix fun UInt24.and(other: UInt24): UInt24
infix fun UInt40.and(other: UInt40): UInt40
infix fun UInt48.and(other: UInt48): UInt48
Link copied to clipboard
fun buildByteArray(order: ByteOrder = ByteOrder.LEAST_SIGNIFICANT_FIRST, expectedSize: Int = Long.SIZE_BYTES, block: ByteArrayBuilder.() -> Unit): ByteArray

Builds a ByteArray using a ByteArrayBuilder

Link copied to clipboard

Returns the number of Bytes required to encode a String using the given StringEncodingSettings.

Link copied to clipboard

Returns the number of Bytes required to encode a String using the given Encoding.

Link copied to clipboard
fun bytesOf(vararg bytes: Int): ByteArray

Returns ByteArray for given bytes

Link copied to clipboard
fun String.copyAsciiIntoArray(array: ByteArray, offset: Int = 0, byteOrder: ByteOrder): ByteArray
Link copied to clipboard
fun Encoding.copyCharIntoByteArray(char: Char, array: ByteArray, offset: Int = 0, byteOrder: ByteOrder): ByteArray

Encodes a Char using the given Encoding and ByteOrder and copies it into a ByteArray at a given offset.

Link copied to clipboard
fun Encoding.copyEncodedStringIntoArray(string: String, array: ByteArray, offset: Int = 0, byteOrder: ByteOrder): ByteArray

Encodes a String using the given Encoding and ByteOrder and copies it into a ByteArray at a given offset.

Link copied to clipboard
fun String.copyIntoArray(array: ByteArray, settings: StringEncodingSettings, offset: Int = 0, order: ByteOrder): ByteArray

Encodes a String using the given StringEncodingSettings and ByteOrder and copies it into a ByteArray

Link copied to clipboard

Encodes this MedFloat16 and copies it into a ByteArray at a given offset.

Encodes this MedFloat32 and copies it into a ByteArray at a given offset.

fun Int24.copyIntoByteArray(array: ByteArray, offset: Int = 0, byteOrder: ByteOrder): ByteArray

Encodes this Int24 and copies it into a ByteArray at a given offset.

fun Int40.copyIntoByteArray(array: ByteArray, offset: Int = 0, byteOrder: ByteOrder): ByteArray

Encodes this Int40 and copies it into a ByteArray at a given offset.

fun Int48.copyIntoByteArray(array: ByteArray, offset: Int = 0, byteOrder: ByteOrder): ByteArray

Encodes this Int48 and copies it into a ByteArray at a given offset.

fun UInt24.copyIntoByteArray(array: ByteArray, offset: Int = 0, byteOrder: ByteOrder): ByteArray

Encodes this UInt24 and copies it into a ByteArray at a given offset.

fun UInt40.copyIntoByteArray(array: ByteArray, offset: Int = 0, byteOrder: ByteOrder): ByteArray

Encodes this UInt40 and copies it into a ByteArray at a given offset.

fun UInt48.copyIntoByteArray(array: ByteArray, offset: Int = 0, byteOrder: ByteOrder): ByteArray

Encodes this UInt48 and copies it into a ByteArray at a given offset.

fun Double.copyIntoByteArray(array: ByteArray, offset: Int = 0, byteOrder: ByteOrder): ByteArray

Encodes this Double and copies it into a ByteArray at a given offset.

fun Float.copyIntoByteArray(array: ByteArray, offset: Int = 0, byteOrder: ByteOrder): ByteArray

Encodes this Float and copies it into a ByteArray at a given offset.

fun Int.copyIntoByteArray(array: ByteArray, offset: Int = 0, byteOrder: ByteOrder): ByteArray

Encodes this Int and copies it into a ByteArray at a given offset.

fun Long.copyIntoByteArray(array: ByteArray, offset: Int = 0, byteOrder: ByteOrder): ByteArray

Encodes this Long and copies it into a ByteArray at a given offset.

fun Short.copyIntoByteArray(array: ByteArray, offset: Int = 0, byteOrder: ByteOrder): ByteArray

Encodes this Short and copies it into a ByteArray at a given offset.

fun UInt.copyIntoByteArray(array: ByteArray, offset: Int = 0, byteOrder: ByteOrder): ByteArray

Encodes this UInt and copies it into a ByteArray at a given offset.

fun ULong.copyIntoByteArray(array: ByteArray, offset: Int = 0, byteOrder: ByteOrder): ByteArray

Encodes this ULong and copies it into a ByteArray at a given offset.

fun UShort.copyIntoByteArray(array: ByteArray, offset: Int = 0, byteOrder: ByteOrder): ByteArray

Encodes this UShort and copies it into a ByteArray at a given offset.

Link copied to clipboard
fun String.copyUTF16IntoArray(array: ByteArray, offset: Int = 0, byteOrder: ByteOrder): ByteArray

Encodes a String using UTF-16 and copies it into a ByteArray at a given offset.

Link copied to clipboard
fun Char.copyUTF16IntoByteArray(array: ByteArray, offset: Int = 0, byteOrder: ByteOrder): ByteArray

Encodes a Char and copies it into a ByteArray at a given offset in UTF-16 using the given ByteOrder.

Link copied to clipboard
fun String.copyUTF8IntoArray(array: ByteArray, offset: Int = 0, byteOrder: ByteOrder, throwOnMalformed: Boolean = false): ByteArray

Encodes a String using UTF-8 and copies it into a ByteArray at a given offset.

Link copied to clipboard

Decodes a Char from a Byte assuming ASCII encoding.

fun ByteArray.decodeAsciiChar(octetIndex: Int): Char

Decodes a Char at octetIndex from a ByteArray assuming ASCII encoding.

Link copied to clipboard
fun ByteArray.decodeDouble(octetIndex: Int, byteOrder: ByteOrder): Double

Converts ByteArray to Double

Link copied to clipboard
fun ByteArray.decodeFloat(octetIndex: Int, byteOrder: ByteOrder): Float

Converts ByteArray to Float

Link copied to clipboard

Converts a hex String to ByteArray

Link copied to clipboard
fun ByteArray.decodeInt(octetIndex: Int, byteOrder: ByteOrder): Int

Converts ByteArray to Int

Link copied to clipboard
fun ByteArray.decodeInt24(octetIndex: Int, byteOrder: ByteOrder): Int24

Decodes a ByteArray into an Int24 using the 3 bytes starting from octetIndex

Link copied to clipboard
fun ByteArray.decodeInt40(octetIndex: Int, byteOrder: ByteOrder): Int40

Decodes a ByteArray into an Int40 using the 5 bytes starting from octetIndex

Link copied to clipboard
fun ByteArray.decodeInt48(octetIndex: Int, byteOrder: ByteOrder): Int48

Decodes a ByteArray into an Int48 using the 6 bytes starting from octetIndex

Link copied to clipboard
fun ByteArray.decodeLong(octetIndex: Int, byteOrder: ByteOrder): Long

Converts ByteArray to Long

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun ByteArray.decodeShort(octetIndex: Int, byteOrder: ByteOrder): Short

Converts ByteArray to Short

Link copied to clipboard

Decodes a Sequence of Byte ordered Least Significant first into a String using StringEncodingSettings

Decodes a ByteArray ordered Least Significant first into a String using StringEncodingSettings

Link copied to clipboard
fun ByteArray.decodeUByte(octetIndex: Int): UByte

Decodes a UByte from the given ByteArray at the given octetIndex.

Link copied to clipboard
fun ByteArray.decodeUInt(octetIndex: Int, byteOrder: ByteOrder): UInt

Converts ByteArray to UInt

Link copied to clipboard
fun ByteArray.decodeUInt24(octetIndex: Int, byteOrder: ByteOrder): UInt24

Decodes a ByteArray into an UInt24 using the 3 bytes starting from octetIndex

Link copied to clipboard
fun ByteArray.decodeUInt40(octetIndex: Int, byteOrder: ByteOrder): UInt40

Decodes a ByteArray into an UInt40 using the 5 bytes starting from octetIndex

Link copied to clipboard
fun ByteArray.decodeUInt48(octetIndex: Int, byteOrder: ByteOrder): UInt48

Decodes a ByteArray into an UInt48 using the 6 bytes starting from octetIndex

Link copied to clipboard
fun ByteArray.decodeULong(octetIndex: Int, byteOrder: ByteOrder): ULong

Converts ByteArray to ULong

Link copied to clipboard
fun ByteArray.decodeUShort(octetIndex: Int, byteOrder: ByteOrder): UShort

Converts ByteArray to UShort

Link copied to clipboard
fun ByteArray.decodeUTF16Char(octetIndex: Int, order: ByteOrder): Char

Decodes a Char at octetIndex from a ByteArray assuming UTF-16 encoding.

Link copied to clipboard

Decodes a Char from a Byte assuming UTF-8 encoding.

fun ByteArray.decodeUTF8Char(octetIndex: Int): Char

Decodes a Char at octetIndex from a ByteArray assuming UTF-8 encoding.

Link copied to clipboard
fun Encoding.encodeChar(char: Char, byteOrder: ByteOrder): ByteArray

Encodes a Char into a ByteArray using the given Encoding and ByteOrder.

Link copied to clipboard
fun Encoding.encodeString(string: String, byteOrder: ByteOrder): ByteArray

Encodes a String into a ByteArray using the given Encoding and ByteOrder.

Link copied to clipboard

Checks whether the bit at index is set in this Int24

Checks whether the bit at index is set in this Int40

Checks whether the bit at index is set in this Int48

Checks whether the bit at index is set in this UInt24

Checks whether the bit at index is set in this UInt40

Checks whether the bit at index is set in this UInt48

Checks whether the bit at index is set in this Byte

Checks whether the bit at index is set in this ByteArray

fun Int.isBitSet(index: Number): Boolean

Checks whether the bit at index is set in this Int

Checks whether the bit at index is set in this Long

Checks whether the bit at index is set in this Short

Checks whether the bit at index is set in this UByte

Checks whether the bit at index is set in this UInt

Checks whether the bit at index is set in this ULong

Checks whether the bit at index is set in this UShort

Link copied to clipboard
fun Int.length(): Int

Determines the number of digits in an Integer

Link copied to clipboard
infix fun Int24.or(other: Int24): Int24
infix fun Int40.or(other: Int40): Int40
infix fun Int48.or(other: Int48): Int48

Performs a bitwise OR operation between the two values.

infix fun UInt24.or(other: UInt24): UInt24
infix fun UInt40.or(other: UInt40): UInt40
infix fun UInt48.or(other: UInt48): UInt48
Link copied to clipboard
fun Int24.setBit(index: Number): Int24

Creates a Int24 that is equal to this Int24 except the bit at index is set

fun Int40.setBit(index: Number): Int40

Creates a Int40 that is equal to this Int40 except the bit at index is set

fun Int48.setBit(index: Number): Int48

Creates a Int48 that is equal to this Int48 except the bit at index is set

fun UInt24.setBit(index: Number): UInt24

Creates a UInt24 that is equal to this UInt24 except the bit at index is set

fun UInt40.setBit(index: Number): UInt40

Creates a UInt40 that is equal to this UInt40 except the bit at index is set

fun UInt48.setBit(index: Number): UInt48

Creates a UInt48 that is equal to this UInt48 except the bit at index is set

fun Byte.setBit(index: Number): Byte

Creates a Byte that is equal to this Byte except the bit at index is set

Creates a ByteArray that is equal to this array except the bit at index is set

fun Int.setBit(index: Number): Int

Creates a Int that is equal to this Int except the bit at index is set

fun Long.setBit(index: Number): Long

Creates a Long that is equal to this Long except the bit at index is set

fun Short.setBit(index: Number): Short

Creates a Short that is equal to this Short except the bit at index is set

fun UByte.setBit(index: Number): UByte

Creates a UByte that is equal to this UByte except the bit at index is set

fun UInt.setBit(index: Number): UInt

Creates a UInt that is equal to this UInt except the bit at index is set

fun ULong.setBit(index: Number): ULong

Creates a ULong that is equal to this ULong except the bit at index is set

fun UShort.setBit(index: Number): UShort

Creates a UShort that is equal to this UShort except the bit at index is set

Link copied to clipboard
infix fun Int24.shl(bitCount: Int): Int24
infix fun Int40.shl(bitCount: Int): Int40
infix fun Int48.shl(bitCount: Int): Int48
infix fun Byte.shl(bitCount: Int): Byte
infix fun Short.shl(bitCount: Int): Short
infix fun UByte.shl(bitCount: Int): UByte
infix fun UShort.shl(bitCount: Int): UShort

Shifts this value left by the bitCount number of bits.

infix fun UInt24.shl(bitCount: Int): UInt24
infix fun UInt40.shl(bitCount: Int): UInt40
infix fun UInt48.shl(bitCount: Int): UInt48
Link copied to clipboard
infix fun Int24.shr(bitCount: Int): Int24
infix fun Int40.shr(bitCount: Int): Int40
infix fun Int48.shr(bitCount: Int): Int48
infix fun Byte.shr(bitCount: Int): Byte
infix fun Short.shr(bitCount: Int): Short
infix fun UByte.shr(bitCount: Int): UByte
infix fun UShort.shr(bitCount: Int): UShort

Shifts this value right by the bitCount number of bits.

infix fun UInt24.shr(bitCount: Int): UInt24
infix fun UInt40.shr(bitCount: Int): UInt40
infix fun UInt48.shr(bitCount: Int): UInt48
Link copied to clipboard

Encodes a Char to a Byte in ASCII.

Encodes a String to a ByteArray using ASCII.

Link copied to clipboard

Encodes a Char to a Byte in ASCII or null if the character cannot be represented in ASCII.

Encodes a String to a ByteArray using ASCII or null if the string contains a non-ASCII character.

Link copied to clipboard

Encodes this MedFloat16 into a ByteArray.

Encodes this MedFloat32 into a ByteArray.

Encodes this UByte into a ByteArray.

Encodes this Int24 into a ByteArray.

Encodes this Int40 into a ByteArray.

Encodes this Int48 into a ByteArray.

Encodes this UInt24 into a ByteArray.

Encodes this UInt40 into a ByteArray.

Encodes this UInt48 into a ByteArray.

Encodes a Double into a ByteArray

Encodes a Float into a ByteArray

Encodes this Int into a ByteArray.

Encodes this Long into a ByteArray.

Encodes this Short into a ByteArray.

Encodes this UInt into a ByteArray.

Encodes this ULong into a ByteArray.

Encodes a String to a ByteArray using the given StringEncodingSettings and ByteOrder.

Link copied to clipboard

Converts a ByteArray to a String representing the bytes as their hexadecimal value

Link copied to clipboard

Converts this UInt24 value to Int24. If this value is positive, the resulting Int24 value represents the same numerical value as this UInt24. The resulting Int24 value has the same binary representation as this UInt24 value.

Converts this Number value to Int24.

Link copied to clipboard

Converts this UInt40 value to Int40. If this value is positive, the resulting Int40 value represents the same numerical value as this UInt40. The resulting Int40 value has the same binary representation as this UInt40 value.

Converts this Number value to Int40.

Link copied to clipboard

Converts this UInt48 value to Int48. If this value is positive, the resulting Int48 value represents the same numerical value as this UInt48. The resulting Int48 value has the same binary representation as this UInt48 value.

Converts this Number value to Int48.

Link copied to clipboard

Converts this Int24 value to UInt24. If this value is positive, the resulting UInt24 value represents the same numerical value as this Int24. The resulting UInt24 value has the same binary representation as this Int24 value.

Converts this UInt value to UInt24.

Link copied to clipboard

Converts this Int40 value to UInt40. If this value is positive, the resulting UInt40 value represents the same numerical value as this Int40. The resulting UInt40 value has the same binary representation as this Int40 value.

Converts this ULong value to UInt40. The resulting value retains only the lowest 40 bits.

Link copied to clipboard

Converts this Int48 value to UInt48. If this value is positive, the resulting UInt48 value represents the same numerical value as this Int48. The resulting UInt48 value has the same binary representation as this Int48 value.

Converts this ULong value to UInt48. The resulting value retains only the lowest 48 bits.

Link copied to clipboard
fun Char.toUTF16(byteOrder: ByteOrder): ByteArray

Encodes a Char to a ByteArray in UTF-16 using the given ByteOrder.

Encodes a String to a ByteArray using UTF-16.

Link copied to clipboard
fun String.toUTF8(byteOrder: ByteOrder, throwOnMalformed: Boolean = false): ByteArray

Encodes a String to a ByteArray using UTF-8.

Link copied to clipboard
fun String.utf8Size(throwOnMalformed: Boolean): Int

Returns the number of Bytes required to encode a String using UTF-8.