diff options
author | Edoardo La Greca | 2025-08-08 16:45:52 +0200 |
---|---|---|
committer | Edoardo La Greca | 2025-08-08 16:45:52 +0200 |
commit | bedbcf252d63bcbfc3a4de24a5573667d86ca17d (patch) | |
tree | 4a83e634bb383bd57671743f9ae4ea601eb1ec98 | |
parent | 946e0e2d438f1076ea009901b1a69cb49425865f (diff) |
change write 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 984b345..6630567 100644 --- a/src/main/kotlin/Connection.kt +++ b/src/main/kotlin/Connection.kt @@ -210,7 +210,7 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator { return imsg.fieldsRaw["data"]!! } - override fun write(fid: UInt, offset: ULong, count: UInt, data: Iterable<UByte>): Pair<String?, UInt> { + override fun write(fid: UInt, offset: ULong, count: UInt, data: Iterable<UByte>): UInt { val data = data.take(count.toInt()).toTypedArray() val omsg = OutMessage(NinePMessageType.TWRITE, this.tagGen.generate(), listOf("offset", "count", "data"), mapOf( @@ -224,15 +224,11 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator { this.maxSize ) omsg.write(this.tl) - val checkErr = checkedInMessage(omsg.tag) - if (checkErr.first != null) { - return Pair(checkErr.first, 0u) - } - val imsg = checkErr.second!! + val imsg = checkedInMessage(omsg.tag) imsg.applyField(InMessage.Field("count", InMessage.Field.Type.INTEGER, 4u)) val count = imsg.fieldsInt["count"]!! - return Pair(null, count.toInt().toUInt()) + return count.toInt().toUInt() } override fun clunk(path: String) { diff --git a/src/main/kotlin/ProtocolTranslator.kt b/src/main/kotlin/ProtocolTranslator.kt index b0f02c3..b74eef0 100644 --- a/src/main/kotlin/ProtocolTranslator.kt +++ b/src/main/kotlin/ProtocolTranslator.kt @@ -100,10 +100,11 @@ interface ProtocolTranslator { * @param fid The FID to write to. * @param offset The distance between the beginning of the file and the first written byte. * @param data The raw bytes that are going to be written. - * @return A pair of: (1) an optional error message and (2) the amount of bytes written with the call just made. If - * the string is not null, an error occurred and the amount of written bytes is going to be zero. + * @return The amount of bytes written 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 write(fid: UInt, offset: ULong, count: UInt, data: Iterable<UByte>): Pair<String?, UInt> + fun write(fid: UInt, offset: ULong, count: UInt, data: Iterable<UByte>): UInt /** * Forget about an FID. |