diff options
author | Edoardo La Greca | 2025-08-08 16:43:42 +0200 |
---|---|---|
committer | Edoardo La Greca | 2025-08-08 16:43:42 +0200 |
commit | 946e0e2d438f1076ea009901b1a69cb49425865f (patch) | |
tree | 9132e79d7eb49ee863df2d0093331e6b9ac4be55 | |
parent | 97408589e18ecebef7fa380e019c43f5a24e1be7 (diff) |
change read to use exceptions instead of error strings
-rw-r--r-- | src/main/kotlin/Connection.kt | 10 | ||||
-rw-r--r-- | src/main/kotlin/ProtocolTranslator.kt | 7 |
2 files changed, 7 insertions, 10 deletions
diff --git a/src/main/kotlin/Connection.kt b/src/main/kotlin/Connection.kt index cb93533..984b345 100644 --- a/src/main/kotlin/Connection.kt +++ b/src/main/kotlin/Connection.kt @@ -190,7 +190,7 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator { TODO("Not yet implemented") } - override fun read(fid: UInt, offset: ULong, count: UInt): Pair<String?, Array<UByte>> { + override fun read(fid: UInt, offset: ULong, count: UInt): Array<UByte> { val omsg = OutMessage(NinePMessageType.TREAD, this.tagGen.generate(), listOf("fid", "offset", "count"), mapOf( "fid" to BigInteger(fid.toString()), @@ -202,16 +202,12 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator { this.maxSize ) omsg.write(this.tl) - val checkErr = checkedInMessage(omsg.tag) - if (checkErr.first != null) { - return Pair(checkErr.first, emptyArray()) - } - val imsg = checkErr.second!! + val imsg = checkedInMessage(omsg.tag) imsg.applyField(InMessage.Field("count", InMessage.Field.Type.INTEGER, 4u)) val count = imsg.fieldsInt["count"]!!.toInt().toUInt() imsg.applyField(InMessage.Field("data", InMessage.Field.Type.RAW, count)) - return Pair(null, imsg.fieldsRaw["data"]!!) + return imsg.fieldsRaw["data"]!! } override fun write(fid: UInt, offset: ULong, count: UInt, data: Iterable<UByte>): Pair<String?, UInt> { diff --git a/src/main/kotlin/ProtocolTranslator.kt b/src/main/kotlin/ProtocolTranslator.kt index bf29131..b0f02c3 100644 --- a/src/main/kotlin/ProtocolTranslator.kt +++ b/src/main/kotlin/ProtocolTranslator.kt @@ -87,10 +87,11 @@ interface ProtocolTranslator { * Transfer data from file. Due to the negotiated maximum size of 9P messages, called `msize`, one is supposed to * call this method multiple times, unless the content is smaller than `msize`. * - * @return A pair of: (1) an optional error message and (2) the content read with the call just made. If the string - * is not null, an error occurred and the array is going to be empty. + * @return The content read with the call just made. + * @throws except.InvalidMessageException if the received message is invalid. + * @throws except.RErrorException if the received message is an R-error message. */ - fun read(fid: UInt, offset: ULong, count: UInt): Pair<String?, Array<UByte>> + fun read(fid: UInt, offset: ULong, count: UInt): Array<UByte> /** * Transfer data to file. Due to the negotiated maximum size of 9P messages, called `msize`, one is supposed to |