123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760 |
- #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
- #pragma warning disable
- using System;
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- using System.Buffers.Binary;
- #endif
- using System.Diagnostics;
- using System.Runtime.CompilerServices;
- namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities
- {
- internal static class Pack
- {
- internal static void UInt16_To_BE(ushort n, byte[] bs)
- {
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- BinaryPrimitives.WriteUInt16BigEndian(bs, n);
- #else
- bs[0] = (byte)(n >> 8);
- bs[1] = (byte)n;
- #endif
- }
- internal static void UInt16_To_BE(ushort n, byte[] bs, int off)
- {
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- BinaryPrimitives.WriteUInt16BigEndian(bs.AsSpan(off), n);
- #else
- bs[off] = (byte)(n >> 8);
- bs[off + 1] = (byte)n;
- #endif
- }
- internal static void UInt16_To_BE(ushort[] ns, byte[] bs, int off)
- {
- for (int i = 0; i < ns.Length; ++i)
- {
- UInt16_To_BE(ns[i], bs, off);
- off += 2;
- }
- }
- internal static void UInt16_To_BE(ushort[] ns, int nsOff, int nsLen, byte[] bs, int bsOff)
- {
- for (int i = 0; i < nsLen; ++i)
- {
- UInt16_To_BE(ns[nsOff + i], bs, bsOff);
- bsOff += 2;
- }
- }
- internal static byte[] UInt16_To_BE(ushort n)
- {
- byte[] bs = new byte[2];
- UInt16_To_BE(n, bs, 0);
- return bs;
- }
- internal static byte[] UInt16_To_BE(ushort[] ns)
- {
- return UInt16_To_BE(ns, 0, ns.Length);
- }
- internal static byte[] UInt16_To_BE(ushort[] ns, int nsOff, int nsLen)
- {
- byte[] bs = new byte[2 * nsLen];
- UInt16_To_BE(ns, nsOff, nsLen, bs, 0);
- return bs;
- }
- internal static ushort BE_To_UInt16(byte[] bs, int off)
- {
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- return BinaryPrimitives.ReadUInt16BigEndian(bs.AsSpan(off));
- #else
- uint n = (uint)bs[off] << 8
- | bs[off + 1];
- return (ushort)n;
- #endif
- }
- internal static void BE_To_UInt16(byte[] bs, int bsOff, ushort[] ns, int nsOff)
- {
- ns[nsOff] = BE_To_UInt16(bs, bsOff);
- }
- internal static ushort[] BE_To_UInt16(byte[] bs)
- {
- return BE_To_UInt16(bs, 0, bs.Length);
- }
- internal static ushort[] BE_To_UInt16(byte[] bs, int off, int len)
- {
- if ((len & 1) != 0)
- throw new ArgumentException("must be a multiple of 2", "len");
- ushort[] ns = new ushort[len / 2];
- for (int i = 0; i < len; i += 2)
- {
- BE_To_UInt16(bs, off + i, ns, i >> 1);
- }
- return ns;
- }
- internal static void UInt32_To_BE(uint n, byte[] bs)
- {
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- BinaryPrimitives.WriteUInt32BigEndian(bs, n);
- #else
- bs[0] = (byte)(n >> 24);
- bs[1] = (byte)(n >> 16);
- bs[2] = (byte)(n >> 8);
- bs[3] = (byte)n;
- #endif
- }
- internal static void UInt32_To_BE(uint n, byte[] bs, int off)
- {
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- BinaryPrimitives.WriteUInt32BigEndian(bs.AsSpan(off), n);
- #else
- bs[off] = (byte)(n >> 24);
- bs[off + 1] = (byte)(n >> 16);
- bs[off + 2] = (byte)(n >> 8);
- bs[off + 3] = (byte)n;
- #endif
- }
- internal static void UInt32_To_BE(uint[] ns, byte[] bs, int off)
- {
- for (int i = 0; i < ns.Length; ++i)
- {
- UInt32_To_BE(ns[i], bs, off);
- off += 4;
- }
- }
- internal static void UInt32_To_BE(uint[] ns, int nsOff, int nsLen, byte[] bs, int bsOff)
- {
- for (int i = 0; i < nsLen; ++i)
- {
- UInt32_To_BE(ns[nsOff + i], bs, bsOff);
- bsOff += 4;
- }
- }
- internal static byte[] UInt32_To_BE(uint n)
- {
- byte[] bs = new byte[4];
- UInt32_To_BE(n, bs, 0);
- return bs;
- }
- internal static byte[] UInt32_To_BE(uint[] ns)
- {
- byte[] bs = new byte[4 * ns.Length];
- UInt32_To_BE(ns, bs, 0);
- return bs;
- }
- internal static uint BE_To_UInt32(byte[] bs)
- {
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- return BinaryPrimitives.ReadUInt32BigEndian(bs);
- #else
- return (uint)bs[0] << 24
- | (uint)bs[1] << 16
- | (uint)bs[2] << 8
- | bs[3];
- #endif
- }
- internal static uint BE_To_UInt32(byte[] bs, int off)
- {
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- return BinaryPrimitives.ReadUInt32BigEndian(bs.AsSpan(off));
- #else
- return (uint)bs[off] << 24
- | (uint)bs[off + 1] << 16
- | (uint)bs[off + 2] << 8
- | bs[off + 3];
- #endif
- }
- internal static uint BE_To_UInt32_Partial(byte[] bs, int off, int len)
- {
- Debug.Assert(1 <= len && len <= 4);
- uint result = bs[off];
- for (int i = 1; i < len; ++i)
- {
- result <<= 8;
- result |= bs[off + i];
- }
- return result;
- }
- internal static void BE_To_UInt32(byte[] bs, int off, uint[] ns)
- {
- for (int i = 0; i < ns.Length; ++i)
- {
- ns[i] = BE_To_UInt32(bs, off);
- off += 4;
- }
- }
- internal static void BE_To_UInt32(byte[] bs, int bsOff, uint[] ns, int nsOff, int nsLen)
- {
- for (int i = 0; i < nsLen; ++i)
- {
- ns[nsOff + i] = BE_To_UInt32(bs, bsOff);
- bsOff += 4;
- }
- }
- internal static byte[] UInt64_To_BE(ulong n)
- {
- byte[] bs = new byte[8];
- UInt64_To_BE(n, bs, 0);
- return bs;
- }
- internal static void UInt64_To_BE(ulong n, byte[] bs)
- {
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- BinaryPrimitives.WriteUInt64BigEndian(bs, n);
- #else
- UInt32_To_BE((uint)(n >> 32), bs);
- UInt32_To_BE((uint)n, bs, 4);
- #endif
- }
- internal static void UInt64_To_BE(ulong n, byte[] bs, int off)
- {
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- BinaryPrimitives.WriteUInt64BigEndian(bs.AsSpan(off), n);
- #else
- UInt32_To_BE((uint)(n >> 32), bs, off);
- UInt32_To_BE((uint)n, bs, off + 4);
- #endif
- }
- internal static byte[] UInt64_To_BE(ulong[] ns)
- {
- byte[] bs = new byte[8 * ns.Length];
- UInt64_To_BE(ns, bs, 0);
- return bs;
- }
- internal static void UInt64_To_BE(ulong[] ns, byte[] bs, int off)
- {
- for (int i = 0; i < ns.Length; ++i)
- {
- UInt64_To_BE(ns[i], bs, off);
- off += 8;
- }
- }
- internal static void UInt64_To_BE(ulong[] ns, int nsOff, int nsLen, byte[] bs, int bsOff)
- {
- for (int i = 0; i < nsLen; ++i)
- {
- UInt64_To_BE(ns[nsOff + i], bs, bsOff);
- bsOff += 8;
- }
- }
- internal static ulong BE_To_UInt64(byte[] bs)
- {
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- return BinaryPrimitives.ReadUInt64BigEndian(bs);
- #else
- uint hi = BE_To_UInt32(bs);
- uint lo = BE_To_UInt32(bs, 4);
- return ((ulong)hi << 32) | (ulong)lo;
- #endif
- }
- internal static ulong BE_To_UInt64(byte[] bs, int off)
- {
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- return BinaryPrimitives.ReadUInt64BigEndian(bs.AsSpan(off));
- #else
- uint hi = BE_To_UInt32(bs, off);
- uint lo = BE_To_UInt32(bs, off + 4);
- return ((ulong)hi << 32) | (ulong)lo;
- #endif
- }
- internal static ulong BE_To_UInt64_Partial(byte[] bs, int off, int len)
- {
- Debug.Assert(1 <= len && len <= 8);
- ulong result = bs[off];
- for (int i = 1; i < len; ++i)
- {
- result <<= 8;
- result |= bs[off + i];
- }
- return result;
- }
- internal static void BE_To_UInt64(byte[] bs, int off, ulong[] ns)
- {
- for (int i = 0; i < ns.Length; ++i)
- {
- ns[i] = BE_To_UInt64(bs, off);
- off += 8;
- }
- }
- internal static void BE_To_UInt64(byte[] bs, int bsOff, ulong[] ns, int nsOff, int nsLen)
- {
- for (int i = 0; i < nsLen; ++i)
- {
- ns[nsOff + i] = BE_To_UInt64(bs, bsOff);
- bsOff += 8;
- }
- }
- internal static void UInt16_To_LE(ushort n, byte[] bs)
- {
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- BinaryPrimitives.WriteUInt16LittleEndian(bs, n);
- #else
- bs[0] = (byte)n;
- bs[1] = (byte)(n >> 8);
- #endif
- }
- internal static void UInt16_To_LE(ushort n, byte[] bs, int off)
- {
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- BinaryPrimitives.WriteUInt16LittleEndian(bs.AsSpan(off), n);
- #else
- bs[off] = (byte)n;
- bs[off + 1] = (byte)(n >> 8);
- #endif
- }
- internal static byte[] UInt16_To_LE(ushort n)
- {
- byte[] bs = new byte[2];
- UInt16_To_LE(n, bs, 0);
- return bs;
- }
- internal static ushort LE_To_UInt16(byte[] bs)
- {
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- return BinaryPrimitives.ReadUInt16LittleEndian(bs);
- #else
- uint n = bs[0]
- | (uint)bs[1] << 8;
- return (ushort)n;
- #endif
- }
- internal static ushort LE_To_UInt16(byte[] bs, int off)
- {
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- return BinaryPrimitives.ReadUInt16LittleEndian(bs.AsSpan(off));
- #else
- uint n = bs[off]
- | (uint)bs[off + 1] << 8;
- return (ushort)n;
- #endif
- }
- internal static byte[] UInt32_To_LE(uint n)
- {
- byte[] bs = new byte[4];
- UInt32_To_LE(n, bs, 0);
- return bs;
- }
- internal static void UInt32_To_LE(uint n, byte[] bs)
- {
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- BinaryPrimitives.WriteUInt32LittleEndian(bs, n);
- #else
- bs[0] = (byte)n;
- bs[1] = (byte)(n >> 8);
- bs[2] = (byte)(n >> 16);
- bs[3] = (byte)(n >> 24);
- #endif
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static void UInt32_To_LE(uint n, byte[] bs, int off)
- {
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- BinaryPrimitives.WriteUInt32LittleEndian(bs.AsSpan(off), n);
- #else
- bs[off] = (byte)n;
- bs[off + 1] = (byte)(n >> 8);
- bs[off + 2] = (byte)(n >> 16);
- bs[off + 3] = (byte)(n >> 24);
- #endif
- }
- internal static byte[] UInt32_To_LE(uint[] ns)
- {
- byte[] bs = new byte[4 * ns.Length];
- UInt32_To_LE(ns, bs, 0);
- return bs;
- }
- internal static void UInt32_To_LE(uint[] ns, byte[] bs, int off)
- {
- for (int i = 0; i < ns.Length; ++i)
- {
- UInt32_To_LE(ns[i], bs, off);
- off += 4;
- }
- }
- internal static void UInt32_To_LE(uint[] ns, int nsOff, int nsLen, byte[] bs, int bsOff)
- {
- for (int i = 0; i < nsLen; ++i)
- {
- UInt32_To_LE(ns[nsOff + i], bs, bsOff);
- bsOff += 4;
- }
- }
- internal static uint LE_To_UInt24(byte[] bs, int off)
- {
- return bs[off]
- | (uint)bs[off + 1] << 8
- | (uint)bs[off + 2] << 16;
- }
- internal static uint LE_To_UInt32(byte[] bs)
- {
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- return BinaryPrimitives.ReadUInt32LittleEndian(bs);
- #else
- return bs[0]
- | (uint)bs[1] << 8
- | (uint)bs[2] << 16
- | (uint)bs[3] << 24;
- #endif
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static uint LE_To_UInt32(byte[] bs, int off)
- {
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- return BinaryPrimitives.ReadUInt32LittleEndian(bs.AsSpan(off));
- #else
- return bs[off]
- | (uint)bs[off + 1] << 8
- | (uint)bs[off + 2] << 16
- | (uint)bs[off + 3] << 24;
- #endif
- }
- internal static void LE_To_UInt32(byte[] bs, int off, uint[] ns)
- {
- for (int i = 0; i < ns.Length; ++i)
- {
- ns[i] = LE_To_UInt32(bs, off);
- off += 4;
- }
- }
- internal static void LE_To_UInt32(byte[] bs, int bOff, uint[] ns, int nOff, int count)
- {
- for (int i = 0; i < count; ++i)
- {
- ns[nOff + i] = LE_To_UInt32(bs, bOff);
- bOff += 4;
- }
- }
- internal static uint[] LE_To_UInt32(byte[] bs, int off, int count)
- {
- uint[] ns = new uint[count];
- for (int i = 0; i < ns.Length; ++i)
- {
- ns[i] = LE_To_UInt32(bs, off);
- off += 4;
- }
- return ns;
- }
- internal static byte[] UInt64_To_LE(ulong n)
- {
- byte[] bs = new byte[8];
- UInt64_To_LE(n, bs, 0);
- return bs;
- }
- internal static void UInt64_To_LE(ulong n, byte[] bs)
- {
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- BinaryPrimitives.WriteUInt64LittleEndian(bs, n);
- #else
- UInt32_To_LE((uint)n, bs);
- UInt32_To_LE((uint)(n >> 32), bs, 4);
- #endif
- }
- internal static void UInt64_To_LE(ulong n, byte[] bs, int off)
- {
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- BinaryPrimitives.WriteUInt64LittleEndian(bs.AsSpan(off), n);
- #else
- UInt32_To_LE((uint)n, bs, off);
- UInt32_To_LE((uint)(n >> 32), bs, off + 4);
- #endif
- }
- internal static byte[] UInt64_To_LE(ulong[] ns)
- {
- byte[] bs = new byte[8 * ns.Length];
- UInt64_To_LE(ns, bs, 0);
- return bs;
- }
- internal static void UInt64_To_LE(ulong[] ns, byte[] bs, int off)
- {
- for (int i = 0; i < ns.Length; ++i)
- {
- UInt64_To_LE(ns[i], bs, off);
- off += 8;
- }
- }
- internal static void UInt64_To_LE(ulong[] ns, int nsOff, int nsLen, byte[] bs, int bsOff)
- {
- for (int i = 0; i < nsLen; ++i)
- {
- UInt64_To_LE(ns[nsOff + i], bs, bsOff);
- bsOff += 8;
- }
- }
- internal static ulong LE_To_UInt64(byte[] bs)
- {
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- return BinaryPrimitives.ReadUInt64LittleEndian(bs);
- #else
- uint lo = LE_To_UInt32(bs);
- uint hi = LE_To_UInt32(bs, 4);
- return ((ulong)hi << 32) | (ulong)lo;
- #endif
- }
- internal static ulong LE_To_UInt64(byte[] bs, int off)
- {
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- return BinaryPrimitives.ReadUInt64LittleEndian(bs.AsSpan(off));
- #else
- uint lo = LE_To_UInt32(bs, off);
- uint hi = LE_To_UInt32(bs, off + 4);
- return ((ulong)hi << 32) | (ulong)lo;
- #endif
- }
- internal static void LE_To_UInt64(byte[] bs, int off, ulong[] ns)
- {
- for (int i = 0; i < ns.Length; ++i)
- {
- ns[i] = LE_To_UInt64(bs, off);
- off += 8;
- }
- }
- internal static void LE_To_UInt64(byte[] bs, int bsOff, ulong[] ns, int nsOff, int nsLen)
- {
- for (int i = 0; i < nsLen; ++i)
- {
- ns[nsOff + i] = LE_To_UInt64(bs, bsOff);
- bsOff += 8;
- }
- }
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static uint BE_To_UInt32(ReadOnlySpan<byte> bs)
- {
- return BinaryPrimitives.ReadUInt32BigEndian(bs);
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static void BE_To_UInt32(ReadOnlySpan<byte> bs, Span<uint> ns)
- {
- for (int i = 0; i < ns.Length; ++i)
- {
- ns[i] = BE_To_UInt32(bs);
- bs = bs[4..];
- }
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static uint BE_To_UInt32_Partial(ReadOnlySpan<byte> bs)
- {
- int len = bs.Length;
- Debug.Assert(1 <= len && len <= 4);
- uint result = bs[0];
- for (int i = 1; i < len; ++i)
- {
- result <<= 8;
- result |= bs[i];
- }
- return result;
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static ulong BE_To_UInt64(ReadOnlySpan<byte> bs)
- {
- return BinaryPrimitives.ReadUInt64BigEndian(bs);
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static void BE_To_UInt64(ReadOnlySpan<byte> bs, Span<ulong> ns)
- {
- for (int i = 0; i < ns.Length; ++i)
- {
- ns[i] = BE_To_UInt64(bs);
- bs = bs[8..];
- }
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static ulong BE_To_UInt64_Partial(ReadOnlySpan<byte> bs)
- {
- int len = bs.Length;
- Debug.Assert(1 <= len && len <= 8);
- ulong result = bs[0];
- for (int i = 1; i < len; ++i)
- {
- result <<= 8;
- result |= bs[i];
- }
- return result;
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static ushort LE_To_UInt16(ReadOnlySpan<byte> bs)
- {
- return BinaryPrimitives.ReadUInt16LittleEndian(bs);
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static uint LE_To_UInt32(ReadOnlySpan<byte> bs)
- {
- return BinaryPrimitives.ReadUInt32LittleEndian(bs);
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static void LE_To_UInt32(ReadOnlySpan<byte> bs, Span<uint> ns)
- {
- for (int i = 0; i < ns.Length; ++i)
- {
- ns[i] = LE_To_UInt32(bs);
- bs = bs[4..];
- }
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static ulong LE_To_UInt64(ReadOnlySpan<byte> bs)
- {
- return BinaryPrimitives.ReadUInt64LittleEndian(bs);
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static void LE_To_UInt64(ReadOnlySpan<byte> bs, Span<ulong> ns)
- {
- for (int i = 0; i < ns.Length; ++i)
- {
- ns[i] = LE_To_UInt64(bs);
- bs = bs[8..];
- }
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static void UInt16_To_BE(ushort n, Span<byte> bs)
- {
- BinaryPrimitives.WriteUInt16BigEndian(bs, n);
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static void UInt16_To_LE(ushort n, Span<byte> bs)
- {
- BinaryPrimitives.WriteUInt16LittleEndian(bs, n);
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static void UInt32_To_BE(uint n, Span<byte> bs)
- {
- BinaryPrimitives.WriteUInt32BigEndian(bs, n);
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static void UInt32_To_BE(ReadOnlySpan<uint> ns, Span<byte> bs)
- {
- for (int i = 0; i < ns.Length; ++i)
- {
- UInt32_To_BE(ns[i], bs);
- bs = bs[4..];
- }
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static void UInt32_To_LE(uint n, Span<byte> bs)
- {
- BinaryPrimitives.WriteUInt32LittleEndian(bs, n);
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static void UInt32_To_LE(ReadOnlySpan<uint> ns, Span<byte> bs)
- {
- for (int i = 0; i < ns.Length; ++i)
- {
- UInt32_To_LE(ns[i], bs);
- bs = bs[4..];
- }
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static void UInt64_To_BE(ulong n, Span<byte> bs)
- {
- BinaryPrimitives.WriteUInt64BigEndian(bs, n);
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static void UInt64_To_BE(ReadOnlySpan<ulong> ns, Span<byte> bs)
- {
- for (int i = 0; i < ns.Length; ++i)
- {
- UInt64_To_BE(ns[i], bs);
- bs = bs[8..];
- }
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static void UInt64_To_LE(ulong n, Span<byte> bs)
- {
- BinaryPrimitives.WriteUInt64LittleEndian(bs, n);
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static void UInt64_To_LE(ReadOnlySpan<ulong> ns, Span<byte> bs)
- {
- for (int i = 0; i < ns.Length; ++i)
- {
- UInt64_To_LE(ns[i], bs);
- bs = bs[8..];
- }
- }
- #endif
- }
- }
- #pragma warning restore
- #endif
|