transport.ContextMessageSerializer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yass Show documentation
Show all versions of yass Show documentation
Yet Another Service Solution
package ch.softappeal.yass.transport
import ch.softappeal.yass.remote.Message
import ch.softappeal.yass.serialize.Reader
import ch.softappeal.yass.serialize.Serializer
import ch.softappeal.yass.serialize.Writer
class ContextMessageSerializer(private val contextSerializer: Serializer, private val messageSerializer: Serializer) : Serializer {
private val _context = ThreadLocal()
var context: Any?
get() = _context.get()
set(value) = _context.set(value)
override fun read(reader: Reader): Message {
context = contextSerializer.read(reader)
return messageSerializer.read(reader) as Message
}
/** Sets context to null. */
override fun write(writer: Writer, value: Any?) {
try {
contextSerializer.write(writer, context)
} finally {
context = null
}
messageSerializer.write(writer, value)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy