DotNext by .NET Foundation and Contributors

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

 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.

void Format(TSelf value, Span<byte> output)

Formats object as a sequence of bytes.

TSelf Parse(ref SpanReader input)

Restores the object from its binary representation.

TSelf Parse(ReadOnlySpan<byte> input)

Restores the object from its binary representation.

TSelf Parse(ref ReadOnlySequence input)

Restores the object from its binary representation.

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

Attempts to format object as a sequence of bytes.

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

Attempts to restore the object from its binary representation.

void Format(ref SpanWriter output)

Formats object as a sequence of bytes.