aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Common/Extensions/BinaryWriterExtensions.cs
blob: 9c3e72329f4a5ae96e249214725c4319c74b9b1b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using System;
using System.IO;
using System.Runtime.InteropServices;

namespace Ryujinx.Common
{
    public static class BinaryWriterExtensions
    {
        public static void WriteStruct<T>(this BinaryWriter writer, T value) where T : unmanaged
        {
            ReadOnlySpan<byte> data = MemoryMarshal.Cast<T, byte>(MemoryMarshal.CreateReadOnlySpan(ref value, 1));

            writer.Write(data);
        }

        public static void Write(this BinaryWriter writer, UInt128 value)
        {
            writer.Write((ulong)value);
            writer.Write((ulong)(value >> 64));
        }

        public static void Write(this BinaryWriter writer, MemoryStream stream)
        {
            stream.CopyTo(writer.BaseStream);
        }
    }
}