using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ComputeSharp.D2D1.Shaders.Interop.Buffers; /// /// Helpers for the type. /// internal static class ArrayPoolBinaryWriterExtensions { /// /// Writes the raw value of type into the buffer. /// /// The type of value to write. /// The target instance to write data to. /// The value to write. /// This method will just blit the data of into the target buffer. public static unsafe void WriteRaw(this ref ArrayPoolBufferWriter writer, scoped in T value) where T : unmanaged { Span span = writer.GetSpan(sizeof(T)); Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(span), value); writer.Advance(sizeof(T)); } /// /// Writes the raw data from the input into the buffer. /// /// The type of values in the target writer. /// The target instance to write data to. /// The data to write. public static void WriteRaw(this ref ArrayPoolBufferWriter writer, scoped ReadOnlySpan data) where T : unmanaged { Span span = writer.GetSpan(data.Length); data.CopyTo(span); writer.Advance(data.Length); } }