Open whyoleg opened 4 years ago
+1 That's quite nice. Metadata serialization is important, I assume you mean independently from the data.
Metadata serialization is important
If so, we will need to integrate it somehow with future composite metadata support, and also 3 point become harder to design right API.
As first step, serialization to ByteReadPacket
will be good:
format.decodeFromPacket<ModelType>(payload.data)
and format.decodeFromPacket<ModelType>(payload.metadata)
Payload(format.encodeToPacket(dataModel), mayBeAnotherFormat.encodeToPacket(metadataModel))
"future composite metadata support" - that was my point. I'm finding that I'm needing to serialize with the rsocket-java code, and porting that looks like not much fun. Ideally we would have nice kotlin support for routing, tracing etc. But maybe these can't be converged?
Composite metadata support is my next task in todo list (together with extension metadatas like routing, tracing, auth). Will look later if it's possible to combine them in nicer way, than in my previous message.
+1. The API proposal looks good to me as well!
This is the metadata section that's quite awkward for me (but discrete thankfully).
this.route != null -> {
val compositeByteBuf = CompositeByteBuf(ByteBufAllocator.DEFAULT, false, 1)
val routingMetadata = TaggingMetadataCodec.createRoutingMetadata(ByteBufAllocator.DEFAULT, listOf(route))
CompositeMetadataCodec.encodeAndAddMetadata(compositeByteBuf, ByteBufAllocator.DEFAULT,
WellKnownMimeType.MESSAGE_RSOCKET_ROUTING, routingMetadata.content)
ByteBufUtil.getBytes(compositeByteBuf)
}
It would be good to provide out of the box integration with kotlinx.serialization for serializing models into payload
data
(is metadata serialization needed?). kotlinx.serialization supports both binary formats such as CBOR and ProtoBuf, and string JSON format (and other custom community driven formats). Possible implementations:format.decodeFromPayload<ModelType>(payload)
where:ModelType
- resulting type (should be annotated withSerializable
annotation),format
- JSON/ProtoBuf/CBOR format (or any other custom format)format.encodeToPayload(model, [optional metadata])
wheremodel
- entity to serialize,format
- supported formatfun <T, R> requestResponse(data: R, metadata: ???): TypedPayload<R>
where: T - type of request data, R - type of respose data,TypedPayload
- payload, which containsdata
as typeR
and metadata