Make tx_id and reply_to nullable

This commit is contained in:
Sapphire committed 2026-10-28 19:57:49 -05:00
1 parent aa1343b49c
commit 0eea8b30cc
3 files changed
+7 -8

No files matched your search

@@ -86,22 +86,22 @@ suspend fun onSolarXRMessage(message: MessageBundle, context: SolarXRBridge) {
message.rpcMsgs?.forEach {
val msg = it.message ?: return
val replyTo = it.replyTo
if (replyTo != 0u) {
if (replyTo != null) {
context.rpcRequests.tryResolve(replyTo, msg)
return@forEach
}
context.rpcReplies.record(msg, it.txId)
it.txId?.let { txId -> context.rpcReplies.record(msg, txId) }
context.rpcDispatcher.emit(msg)
}
message.driverMsgs?.forEach {
val msg = it.message ?: return
val replyTo = it.replyTo
if (replyTo != 0u) {
if (replyTo != null) {
context.driverRequests.tryResolve(replyTo, msg)
return@forEach
}
context.driverReplies.record(msg, it.txId)
it.txId?.let { txId -> context.driverReplies.record(msg, txId) }
context.driverDispatcher.emit(msg)
}
}
@@ -140,8 +140,8 @@ class SolarXRBridge(
return driverDispatcher.on<P> { msg -> action(msg, driverTxIdFor(msg)) }
}
suspend fun sendRpc(message: RpcMessage, replyTo: UInt? = null, txId: UInt? = null) = outbound.emit(MessageBundle(rpcMsgs = listOf(RpcMessageHeader(txId = txId ?: 0u, replyTo = replyTo ?: 0u, message = message))))
suspend fun sendDriverMessage(message: DriverMessage, replyTo: UInt? = null, txId: UInt? = null) = outbound.emit(MessageBundle(driverMsgs = listOf(DriverMessageHeader(txId = txId ?: 0u, replyTo = replyTo ?: 0u, message = message))))
suspend fun sendRpc(message: RpcMessage, replyTo: UInt? = null, txId: UInt? = null) = outbound.emit(MessageBundle(rpcMsgs = listOf(RpcMessageHeader(txId = txId, replyTo = replyTo, message = message))))
suspend fun sendDriverMessage(message: DriverMessage, replyTo: UInt? = null, txId: UInt? = null) = outbound.emit(MessageBundle(driverMsgs = listOf(DriverMessageHeader(txId = txId, replyTo = replyTo, message = message))))
suspend inline fun <reified R : RpcMessage> requestRpc(message: RpcMessage, timeout: Duration = 10.seconds): R = rpcRequests.request(timeout, message) { msg, newTxId -> sendRpc(msg, txId = newTxId) }
suspend inline fun <reified R : DriverMessage> requestDriverMessage(message: DriverMessage, timeout: Duration = 10.seconds): R = driverRequests.request(timeout, message) { msg, newTxId -> sendDriverMessage(msg, txId = newTxId) }
@@ -18,7 +18,6 @@ class PendingReplies<T : Any> {
}
fun record(message: T, txId: UInt) {
if (txId == 0u) return
if (message::class !in consumerTypes) return
pending[message] = txId
}