Skip to content

Suggestion: Add GetRemainingBytesMemory() to NetDataReader #560

@Aman-Anas

Description

@Aman-Anas

Some serializers (specifically MessagePack-CSharp) can't read from a Span, but they have no problem reading from Memory. This is already possible using this code:

Memory<byte> myData = reader.RawData.AsMemory(reader.Position, reader.AvailableBytes);
// "reader" is a NetDataReader

Therefore, adding in GetRemainingBytesMemory() is unnecessary, but it would be a nice addition just for completeness. I guess it would be added somewhere around here:

#if LITENETLIB_SPANS || NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_1 || NETCOREAPP3_1 || NET5_0 || NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ReadOnlySpan<byte> GetRemainingBytesSpan()
{
return new ReadOnlySpan<byte>(_data, _position, _dataSize - _position);
}
#endif

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions