From aa40ce28f6001947208d308c9fcb96940788a243 Mon Sep 17 00:00:00 2001 From: Edoardo La Greca Date: Thu, 7 Aug 2025 14:46:37 +0200 Subject: move convInteger and convString to InMessage companion object --- src/main/kotlin/InMessage.kt | 68 +++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/src/main/kotlin/InMessage.kt b/src/main/kotlin/InMessage.kt index c111d62..03f3428 100644 --- a/src/main/kotlin/InMessage.kt +++ b/src/main/kotlin/InMessage.kt @@ -81,39 +81,6 @@ class InMessage(val tl: TransportLayer, maxSize: UInt, val reqTag: UShort) { } } - /** - * Convert an [len] bytes long unsigned integer number from raw bytes. - * - * In 9P, binary numbers (non-textual) are specified in little-endian order (least significant byte first). - * - * @param len The length of the integer number in bytes. If zero, nothing is read. - * @return the number's value. - * @throws IllegalArgumentException if either [offset] or [len] are negative. - */ - fun convInteger(bytes: Iterable, offset: Int, len: Int): BigInteger { - val bytes = bytes.drop(offset).take(len) - var value = 0.toBigInteger() - for (i in 0.., offset: Int): String { - val length = convInteger(bytes, 0, 2).toInt() - val bytes = bytes.drop(offset).take(length) - return String(ByteArray(bytes.size) { i -> bytes[i].toByte() }) - } - /** * Apply the given field to the raw data and put it in one of [fieldsInt], [fieldsStr], or [fieldsRaw]. Fields must * be applied strictly in order, as their application is not commutative. @@ -158,4 +125,39 @@ class InMessage(val tl: TransportLayer, maxSize: UInt, val reqTag: UShort) { applyField(field) } } + + companion object { + /** + * Convert an [len] bytes long unsigned integer number from raw bytes. + * + * In 9P, binary numbers (non-textual) are specified in little-endian order (least significant byte first). + * + * @param len The length of the integer number in bytes. If zero, nothing is read. + * @return the number's value. + * @throws IllegalArgumentException if either [offset] or [len] are negative. + */ + fun convInteger(bytes: Iterable, offset: Int, len: Int): BigInteger { + val bytes = bytes.drop(offset).take(len) + var value = 0.toBigInteger() + for (i in 0.., offset: Int): String { + val length = convInteger(bytes, 0, 2).toInt() + val bytes = bytes.drop(offset).take(length) + return String(ByteArray(bytes.size) { i -> bytes[i].toByte() }) + } + } } \ No newline at end of file -- cgit v1.2.3