Blittable<T>
public struct Blittable<T> : IBinaryFormattable<Blittable<T>> where T : ValueType modreq(System.Runtime.InteropServices.UnmanagedType)
Represents a value of blittable type as IBinaryFormattable<T>.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace DotNext.Buffers.Binary
{
[StructLayout(LayoutKind.Auto)]
[RequiredMember]
public struct Blittable<[IsUnmanaged] T> : IBinaryFormattable<Blittable<T>> where T : struct
{
[RequiredMember]
public T Value;
static int IBinaryFormattable<Blittable<T>>.Size {
get {
return Unsafe.SizeOf<T>();
}
}
[IsReadOnly]
void IBinaryFormattable<Blittable<T>>.Format(Span<byte> destination)
{
Span.AsReadOnlyBytes<T>(ref Value).CopyTo(destination);
}
static Blittable<T> IBinaryFormattable<Blittable<T>>.Parse(ReadOnlySpan<byte> source)
{
Blittable<T> result = default(Blittable<T>);
Unsafe.SkipInit<Blittable<T>>(ref result);
Span<byte> destination = Span.AsBytes<T>(ref result.Value);
source = source.Slice(0, destination.Length);
source.CopyTo(destination);
return result;
}
[IsReadOnly]
[NullableContext(2)]
public override string ToString()
{
T value = Value;
return value.ToString();
}
}
}