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()); }
public static ushort ReadLShort(ref MemorySpan span) { byte[] bytes = span.ReadBytes(2); if (!BitConverter.IsLittleEndian) { Array.Reverse(bytes); } return(BitConverter.ToUInt16(bytes, 0)); }
public static double ReadLDouble(ref MemorySpan span) { byte[] bytes = span.ReadBytes(8); if (!BitConverter.IsLittleEndian) { Array.Reverse(bytes); } return(BitConverter.ToDouble(bytes, 0)); }
public static float ReadLFloat(ref MemorySpan span) { byte[] bytes = span.ReadBytes(4); if (!BitConverter.IsLittleEndian) { Array.Reverse(bytes); } return(BitConverter.ToSingle(bytes, 0)); }
public static ulong ReadLLong(ref MemorySpan span) { byte[] bytes = span.ReadBytes(8); if (!BitConverter.IsLittleEndian) { Array.Reverse(bytes); } return(BitConverter.ToUInt64(bytes, 0)); }
public static uint ReadLInt(ref MemorySpan span) { byte[] bytes = span.ReadBytes(4); if (!BitConverter.IsLittleEndian) { Array.Reverse(bytes); } return(BitConverter.ToUInt32(bytes, 0)); }
public static byte[] ReadBytes(ref MemorySpan span) { return(span.ReadBytes()); }
public static byte[] ReadBytes(ref MemorySpan span, int length) { return(span.ReadBytes(length)); }
public static int ReadLTriad(ref MemorySpan span) { byte[] bytes = span.ReadBytes(3); return(bytes[0] | bytes[1] << 8 | bytes[2] << 16); }
public static bool ReadBool(ref MemorySpan span) { byte[] bytes = span.ReadBytes(1); return(BitConverter.ToBoolean(bytes, 0)); }