WIP serialization cleanup

This commit is contained in:
nathan 2020-08-18 22:38:00 +02:00
parent 345de4d734
commit 1232ea0d8b
2 changed files with 9 additions and 17 deletions

View File

@ -34,24 +34,22 @@
*/
package dorkbox.network.rmi.messages
import dorkbox.network.rmi.RmiUtils
/**
* Internal message to return the result of a remotely invoked method.
*/
class MethodResponse : RmiMessage {
// if this object was a global or connection specific object
var isGlobal: Boolean = false
// the registered kryo ID for the object
var objectId: Int = 0
// ID to match requests <-> responses
var responseId: Int = 0
// this is packed
// LEFT -> rmiObjectId (the registered rmi ID)
// RIGHT -> rmiId (ID to match requests <-> responses)
var packedId: Int = 0
// this is the result of the invoked method
var result: Any? = null
override fun toString(): String {
return "MethodResponse(isGlobal=$isGlobal, objectId=$objectId, responseId=$responseId, result=$result)"
return "MethodResponse(rmiObjectId=${RmiUtils.unpackLeft(packedId)}, rmiId=${RmiUtils.unpackRight(packedId)}, result=$result)"
}
}

View File

@ -19,22 +19,16 @@ import com.esotericsoftware.kryo.Kryo
import com.esotericsoftware.kryo.Serializer
import com.esotericsoftware.kryo.io.Input
import com.esotericsoftware.kryo.io.Output
import dorkbox.network.rmi.RmiUtils
class MethodResponseSerializer() : Serializer<MethodResponse>() {
override fun write(kryo: Kryo, output: Output, response: MethodResponse) {
output.writeInt(RmiUtils.packShorts(response.objectId, response.responseId), true)
output.writeBoolean(response.isGlobal)
output.writeInt(response.packedId)
kryo.writeClassAndObject(output, response.result)
}
override fun read(kryo: Kryo, input: Input, type: Class<out MethodResponse>): MethodResponse {
val packedInfo = input.readInt(true)
val response = MethodResponse()
response.objectId = RmiUtils.unpackLeft(packedInfo)
response.responseId = RmiUtils.unpackRight(packedInfo)
response.isGlobal = input.readBoolean()
response.packedId = input.readInt()
response.result = kryo.readClassAndObject(input)
return response