You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have used this exemple CustomMessageCodec to make a codec for a simple object. It works for a simple object so I wanted to use for a list of objects. This didn't work.
Exemple of used Codec class
import fr.convergence.proddoc.common.model.surcharge.SurchargeDocument
import fr.convergence.proddoc.common.util.json
import io.vertx.core.buffer.Buffer
import io.vertx.core.eventbus.MessageCodec
import io.vertx.mutiny.core.Vertx
import kotlinx.serialization.builtins.ListSerializer
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class SurchargeDocumentListCodecRegistering {
@Inject
constructor(vertx: Vertx) {
vertx.eventBus().registerCodec(SurchargeDocumentListCodec())
}
}
class SurchargeDocumentListCodec : MessageCodec<List<SurchargeDocument>, List<SurchargeDocument>> {
override fun encodeToWire(buffer: Buffer, list: List<SurchargeDocument>) {
val encodedList = json.encodeToString(ListSerializer(SurchargeDocument.serializer()), list)
val length = encodedList.toByteArray().size
buffer.appendInt(length)
buffer.appendString(encodedList)
}
override fun decodeFromWire(position: Int, buffer: Buffer): List<SurchargeDocument> {
var _pos = position
val length = buffer.getInt(_pos)
val jsonContent = buffer.getString(4.let { _pos += it; _pos }, length.let { _pos += it; _pos })
return json.decodeFromString(ListSerializer(SurchargeDocument.serializer()), jsonContent)
}
override fun transform(list: List<SurchargeDocument>): List<SurchargeDocument> {
return list.toList() // Transform as needed
}
override fun name(): String {
return this.javaClass.simpleName
}
override fun systemCodecID(): Byte {
return -1
}
}
Extra
OS : ubuntu 22.04
JAVA version : 17
The text was updated successfully, but these errors were encountered:
Context
I have used this exemple CustomMessageCodec to make a codec for a simple object. It works for a simple object so I wanted to use for a list of objects. This didn't work.
Exemple of used Codec class
Extra
The text was updated successfully, but these errors were encountered: