From e0b0f08a52f922fb5d18ee5de3f4c020dc8a6f80 Mon Sep 17 00:00:00 2001 From: Edoardo La Greca Date: Fri, 20 Jun 2025 16:56:14 +0200 Subject: add readInteger and readString to NinePConnection --- src/main/kotlin/NinePConnection.kt | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/main/kotlin/NinePConnection.kt b/src/main/kotlin/NinePConnection.kt index 8514ffd..73ab5fa 100644 --- a/src/main/kotlin/NinePConnection.kt +++ b/src/main/kotlin/NinePConnection.kt @@ -1,4 +1,5 @@ import java.io.IOException +import java.math.BigInteger /** * This class represents a 9P connection. It provides a practical implementation with networking to the 9P methods @@ -28,5 +29,39 @@ class NinePConnection(netPackTrans: NetworkPacketTransporter) : NinePTranslator this.npt.close() } + /** + * Read an [nBytes]-long unsigned integer number from the connection. + * + * In 9P, binary numbers (non-textual) are specified in little-endian order (least significant byte first). + * + * @param nBytes The length of the integer number in bytes. It only works with unsigned numbers strictly greater + * than zero (zero is excluded). + * @return The number's value. + * @throws IllegalArgumentException if [nBytes] is zero or negative. + */ + private fun readInteger(nBytes: Int): BigInteger { + require(nBytes > 0) + val bytes = this.npt.receiveFixed(nBytes.toULong()) + var number: BigInteger = BigInteger.valueOf(0) + for (i in 0..