diff options
author | Edoardo La Greca | 2025-08-06 19:52:53 +0200 |
---|---|---|
committer | Edoardo La Greca | 2025-08-06 19:53:29 +0200 |
commit | 309b9eac8bf62e53d8efefb15852105218026bf9 (patch) | |
tree | 432214b3d62c00aa08270958bef9c58f9c6a39ed /src/main/kotlin | |
parent | 19d61faff42beeda25af615151d9c54232d4ff01 (diff) |
implement write
Diffstat (limited to 'src/main/kotlin')
-rw-r--r-- | src/main/kotlin/Connection.kt | 21 | ||||
-rw-r--r-- | src/main/kotlin/ProtocolTranslator.kt | 2 |
2 files changed, 21 insertions, 2 deletions
diff --git a/src/main/kotlin/Connection.kt b/src/main/kotlin/Connection.kt index 6247620..564e8a7 100644 --- a/src/main/kotlin/Connection.kt +++ b/src/main/kotlin/Connection.kt @@ -152,8 +152,27 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator { return Pair(null, imsg.fieldsRaw["data"]!!) } - override fun write(fid: UInt, offset: ULong, count: UInt, data: Iterable<UByte>): String? { + override fun write(fid: UInt, offset: ULong, count: UInt, data: Iterable<UByte>): Pair<String?, UInt> { + val omsg = OutMessage(NinePMessageType.TWRITE, this.tagGen.generate(), listOf("offset", "count", "data"), + mapOf( + "offset" to BigInteger(offset.toString()), + "count" to BigInteger(count.toString()), + ), + emptyMap(), + mapOf( + "data" to data.toList().toTypedArray() + ), + this.maxSize + ) + val checkErr = checkedInMessage(omsg.tag) + if (checkErr.first != null) { + return Pair(checkErr.first, 0u) + } + val imsg = checkErr.second!! + imsg.applyField(InMessage.Field("count", InMessage.Field.Type.INTEGER, 4u)) + val count = imsg.fieldsInt["count"]!! + return Pair(null, count.toInt().toUInt()) } override fun clunk(path: String) { diff --git a/src/main/kotlin/ProtocolTranslator.kt b/src/main/kotlin/ProtocolTranslator.kt index 3838b9a..e24d60c 100644 --- a/src/main/kotlin/ProtocolTranslator.kt +++ b/src/main/kotlin/ProtocolTranslator.kt @@ -68,7 +68,7 @@ interface ProtocolTranslator { /** * Transfer data to file. */ - fun write(fid: UInt, offset: ULong, count: UInt, data: Iterable<UByte>): String? + fun write(fid: UInt, offset: ULong, count: UInt, data: Iterable<UByte>): Pair<String?, UInt> /** * Forget about an FID. |