Skip to content

Use ReadOnlySpan<T> instead of byte[]  #9

@bruno-garcia

Description

@bruno-garcia

I'd like to propose changing the contract of ISerializer to useReadOnlySpan<T> instead of byte[].

Since System.Memory is not out yet (RTM's expected with .NET Core 2.1), obviously none of the current implementations (JSON, Xml, ProtoBuf) will actually take advantage of that. It would be great though to already use ReadOnlySpan<T> on the contract to avoid any breaking changes related to this.

When support comes from underlying libraries, we'd only change the implementations to avoid the span.ToArray() calls.

It seems to me that it doesn't make sense to expose ReadOnlySpan<T> and also byte[] so I suggest we go ahead and change the current ISerializer.

I've changed the contract to get an idea of the change: https://github.com/Greentube/serialization/tree/system.memory
Some tests break though, with:

typeof(System.InvalidProgramException): Common Language Runtime detected an invalid program.

I haven't investigated or filed a bug yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions