WIP serialization cleanup
This commit is contained in:
parent
345de4d734
commit
1232ea0d8b
@ -34,24 +34,22 @@
|
|||||||
*/
|
*/
|
||||||
package dorkbox.network.rmi.messages
|
package dorkbox.network.rmi.messages
|
||||||
|
|
||||||
|
import dorkbox.network.rmi.RmiUtils
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal message to return the result of a remotely invoked method.
|
* Internal message to return the result of a remotely invoked method.
|
||||||
*/
|
*/
|
||||||
class MethodResponse : RmiMessage {
|
class MethodResponse : RmiMessage {
|
||||||
// if this object was a global or connection specific object
|
// this is packed
|
||||||
var isGlobal: Boolean = false
|
// LEFT -> rmiObjectId (the registered rmi ID)
|
||||||
|
// RIGHT -> rmiId (ID to match requests <-> responses)
|
||||||
// the registered kryo ID for the object
|
var packedId: Int = 0
|
||||||
var objectId: Int = 0
|
|
||||||
|
|
||||||
// ID to match requests <-> responses
|
|
||||||
var responseId: Int = 0
|
|
||||||
|
|
||||||
// this is the result of the invoked method
|
// this is the result of the invoked method
|
||||||
var result: Any? = null
|
var result: Any? = null
|
||||||
|
|
||||||
|
|
||||||
override fun toString(): String {
|
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)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,22 +19,16 @@ import com.esotericsoftware.kryo.Kryo
|
|||||||
import com.esotericsoftware.kryo.Serializer
|
import com.esotericsoftware.kryo.Serializer
|
||||||
import com.esotericsoftware.kryo.io.Input
|
import com.esotericsoftware.kryo.io.Input
|
||||||
import com.esotericsoftware.kryo.io.Output
|
import com.esotericsoftware.kryo.io.Output
|
||||||
import dorkbox.network.rmi.RmiUtils
|
|
||||||
|
|
||||||
class MethodResponseSerializer() : Serializer<MethodResponse>() {
|
class MethodResponseSerializer() : Serializer<MethodResponse>() {
|
||||||
override fun write(kryo: Kryo, output: Output, response: MethodResponse) {
|
override fun write(kryo: Kryo, output: Output, response: MethodResponse) {
|
||||||
output.writeInt(RmiUtils.packShorts(response.objectId, response.responseId), true)
|
output.writeInt(response.packedId)
|
||||||
output.writeBoolean(response.isGlobal)
|
|
||||||
kryo.writeClassAndObject(output, response.result)
|
kryo.writeClassAndObject(output, response.result)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun read(kryo: Kryo, input: Input, type: Class<out MethodResponse>): MethodResponse {
|
override fun read(kryo: Kryo, input: Input, type: Class<out MethodResponse>): MethodResponse {
|
||||||
val packedInfo = input.readInt(true)
|
|
||||||
|
|
||||||
val response = MethodResponse()
|
val response = MethodResponse()
|
||||||
response.objectId = RmiUtils.unpackLeft(packedInfo)
|
response.packedId = input.readInt()
|
||||||
response.responseId = RmiUtils.unpackRight(packedInfo)
|
|
||||||
response.isGlobal = input.readBoolean()
|
|
||||||
response.result = kryo.readClassAndObject(input)
|
response.result = kryo.readClassAndObject(input)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
Loading…
Reference in New Issue
Block a user