DotNext by .NET Foundation and Contributors

<PackageReference Include="DotNext" Version="5.11.0" />

 IBinaryFormattable<TSelf>

public interface IBinaryFormattable<TSelf> where TSelf : IBinaryFormattable<TSelf>
Represents an object that can be converted to and restored from the binary representation.
int Size { get; }

Gets size of the object, in bytes.

MemoryOwner<byte> Format(TSelf value, MemoryAllocator<byte> allocator = null)

Formats object as a sequence of bytes.

TSelf Parse(ReadOnlySpan<byte> source)

Restores the object from its binary representation.

TSelf Parse(ref ReadOnlySequence source)

Restores the object from its binary representation.

bool TryFormat(TSelf value, Span<byte> destination)

Attempts to format object as a sequence of bytes.

bool TryParse(ReadOnlySpan<byte> source, out TSelf result)

Attempts to restore the object from its binary representation.

void Format(Span<byte> destination)

Formats object as a sequence of bytes.