ch-robinson / dotnet-avro

An Avro implementation for .NET
https://engineering.chrobinson.com/dotnet-avro/
MIT License
132 stars 49 forks source link

Expose ReadOnlySpan<byte> from BinaryReader #267

Closed fabianoliver closed 11 months ago

fabianoliver commented 11 months ago

This PR exposes ReadOnlySpan from BinaryReader to offer an allocation-free alternative to the current ReadBytes.

Specific use cases would for example be custom IBinaryDeserializerBuilderCase-implementations that may intern strings directly on deserialization via StringPools, and/or choose to skip deserialization of strings entirely if they're not bound to any DTO property.

If you would like to merge this PR here, I would be tempted to create a separate follow-PR and include a few more optimisations:

To avoid the extra array allocations there as well. Those functions are only available in netstandard2.1+ and .net5+ respectively, so would require addition additional target frameworks to Chr.Avro.Binary etc. in order to use those via conditional compilation. Let me know if you'd be open to / interested in such a change?