summaryrefslogtreecommitdiff
path: root/src/main/kotlin/Connection.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/Connection.kt')
-rw-r--r--src/main/kotlin/Connection.kt22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/main/kotlin/Connection.kt b/src/main/kotlin/Connection.kt
index 203b5e2..e0b7f18 100644
--- a/src/main/kotlin/Connection.kt
+++ b/src/main/kotlin/Connection.kt
@@ -50,6 +50,28 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator {
this.tl.close()
}
+ /**
+ * Handy function to create an [InMessage] instance and check for errors. It uses [tl] and [maxSize] for instancing
+ * the [InMessage] class.
+ *
+ * @return A pair of: (1) a nullable string (which can be: `null` if no error occurred, empty if an error occurred
+ * with no message, or non-empty with the error message) and (2) the optional [InMessage] instance (null if an error
+ * occurred).
+ */
+ private fun checkedInMessage(reqTag: UShort): Pair<String?, InMessage?> {
+ val imsg: InMessage
+ try {
+ imsg = InMessage(this.tl, this.maxSize, reqTag)
+ } catch (ime: InvalidMessageException) {
+ return Pair(ime.message!!, null)
+ }
+ if (imsg.type == NinePMessageType.RERROR) {
+ imsg.applyField(InMessage.Field("ename", InMessage.Field.Type.STRING, 0u))
+ return Pair(imsg.fieldsStr["ename"]!!, null)
+ }
+ return Pair(null, imsg)
+ }
+
override fun version(msize: UInt, version: String): String? {
val omsg = OutMessage(NinePMessageType.TVERSION, this.NOTAG, listOf("msize", "version"),
mapOf(