summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEdoardo La Greca2025-08-06 18:52:47 +0200
committerEdoardo La Greca2025-08-06 19:00:14 +0200
commite6340665df6da8737b90e4d8446fa11aadde3826 (patch)
treecbce7b495af28b046107385ae5a872a335f41bb9 /src
parent50593356e1725a6c123beb28c67eec2269a47ab1 (diff)
rewrite read with InMessage
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/Connection.kt21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/main/kotlin/Connection.kt b/src/main/kotlin/Connection.kt
index 6233407..203b5e2 100644
--- a/src/main/kotlin/Connection.kt
+++ b/src/main/kotlin/Connection.kt
@@ -106,8 +106,8 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator {
TODO("Not yet implemented")
}
- override fun read(fid: UInt, offset: ULong, count: UInt): String? {
- val msg = Message(NinePMessageType.TREAD, tagGen.generate(), listOf("fid", "offset", "count"),
+ override fun read(fid: UInt, offset: ULong, count: UInt): Pair<String?, Array<UByte>> {
+ val omsg = OutMessage(NinePMessageType.TREAD, this.tagGen.generate(), listOf("fid", "offset", "count"),
mapOf(
"fid" to BigInteger(fid.toString()),
"offset" to BigInteger(offset.toString()),
@@ -116,12 +116,21 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator {
emptyMap(),
this.maxSize
)
- val error = responseError(msg)
- if (error != null) {
- return error
+ val imsg: InMessage
+ try {
+ imsg = InMessage(this.tl, this.maxSize, omsg.tag)
+ } catch (ime: InvalidMessageException) {
+ return Pair(ime.message, emptyArray())
}
+ if (imsg.type == NinePMessageType.RERROR) {
+ imsg.applyField(InMessage.Field("ename", InMessage.Field.Type.STRING, 0u))
+ return Pair(imsg.fieldsStr["ename"], emptyArray())
+ }
+ 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 null
+ return Pair(null, imsg.fieldsRaw["data"]!!)
}
override fun write(fid: UInt, offset: ULong, count: UInt, data: Iterable<UByte>): String? {