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:
BinaryDeserializer.ReadString use Encoding.GetString(ReadOnlySpan<byte>)
ReadDouble to use BinaryPrimitives.ReadDoubleLittleEndian(ReadOnlySpan<byte>)
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?
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?