Пример #1
0
        public static byte[][] SplitBytes(MemorySpan span, int length)
        {
            List <byte[]> splits = new List <byte[]>();

            while (span.Offset < span.Length)
            {
                if ((span.Length - span.Offset) >= length)
                {
                    splits.Add(span.ReadBytes(length));
                }
                else
                {
                    splits.Add(span.ReadBytes());
                }
            }

            return(splits.ToArray());
        }
Пример #2
0
        public static ushort ReadLShort(ref MemorySpan span)
        {
            byte[] bytes = span.ReadBytes(2);

            if (!BitConverter.IsLittleEndian)
            {
                Array.Reverse(bytes);
            }

            return(BitConverter.ToUInt16(bytes, 0));
        }
Пример #3
0
        public static double ReadLDouble(ref MemorySpan span)
        {
            byte[] bytes = span.ReadBytes(8);

            if (!BitConverter.IsLittleEndian)
            {
                Array.Reverse(bytes);
            }

            return(BitConverter.ToDouble(bytes, 0));
        }
Пример #4
0
        public static float ReadLFloat(ref MemorySpan span)
        {
            byte[] bytes = span.ReadBytes(4);

            if (!BitConverter.IsLittleEndian)
            {
                Array.Reverse(bytes);
            }

            return(BitConverter.ToSingle(bytes, 0));
        }
Пример #5
0
        public static ulong ReadLLong(ref MemorySpan span)
        {
            byte[] bytes = span.ReadBytes(8);

            if (!BitConverter.IsLittleEndian)
            {
                Array.Reverse(bytes);
            }

            return(BitConverter.ToUInt64(bytes, 0));
        }
Пример #6
0
        public static uint ReadLInt(ref MemorySpan span)
        {
            byte[] bytes = span.ReadBytes(4);

            if (!BitConverter.IsLittleEndian)
            {
                Array.Reverse(bytes);
            }

            return(BitConverter.ToUInt32(bytes, 0));
        }
Пример #7
0
 public static byte[] ReadBytes(ref MemorySpan span)
 {
     return(span.ReadBytes());
 }
Пример #8
0
 public static byte[] ReadBytes(ref MemorySpan span, int length)
 {
     return(span.ReadBytes(length));
 }
Пример #9
0
        public static int ReadLTriad(ref MemorySpan span)
        {
            byte[] bytes = span.ReadBytes(3);

            return(bytes[0] | bytes[1] << 8 | bytes[2] << 16);
        }
Пример #10
0
        public static bool ReadBool(ref MemorySpan span)
        {
            byte[] bytes = span.ReadBytes(1);

            return(BitConverter.ToBoolean(bytes, 0));
        }