-
Notifications
You must be signed in to change notification settings - Fork 52
Description
Hi,
This is an idea for a potential improvement.
A common use case for chr.avro is of course to deserialise avro encoded data into some DTO or model type.
Now, I'm not quite sure how common this is among the wider user base, but personally I tend to create the DTOs by hand, mapping out only the properties I am interested in.
To give a simple real world example, imagine you are publishing a change stream from some database to kafka, and then have a .NET service consume that. One message represents the change of one row of the table, and its avro schema has fields for every column. Oftentimes, my consuming service does not care about all colums; often, I just need to load up a subset. So, I would model the DTO to only have whatever columns I care for, and then deserialise via chr.avro.
At the moment, deserialisation is a bit wasteful in those circumstances; the generated binary deserialiser would fully deserialise every single field, and then just bind whatever is mapped out to my DTO.
In theory, this could be improved a bit if deserialisers supported skipping fields. Of course due to avro's binary representation, skipping a field isn't a no-op either, but it could be a fair bit cheaper. Say for example the schema has a string field that I haven't bound to my object; instead of converting the data to utf16 and allocating a string for it, just to throw it away quite immediately, the string deserialiser would be able to just read in the length, and then skip over those bytes in the message. And similarly for other primitive types.
The biggest problem is arguably that it might hard to fit this into the existing contract in order for eg BinaryRecordDeserialiser to convey to the other serialisers whether it would like to read or skip some field, possibly in a way so third party deserialisers aren't broken.
From the top of mind, maybe new ISkippableBinaryDeserializerBuilder/ISkippableBinaryDeserializerBuilderCase could be introduced, and BinaryRecordDeserializerBuilderCase etc could check whether these are implemented, and use skip methods if appropriate it so.
Alternatively, if supporting something like this only in newer .NET versions, it might also be a decent option to add Skip() as default interface methods which by default just forward to the regular read methods, but can then be specialised.
Anyways - not sure if there is any wider interest in this, but thought it might be good to open up a discussion as I somewhat often run into cases where this would be useful.