public static TTo[] ConvertArray <TTo>(byte[] mem) { fixed(byte *ptr = mem) { Pointer <TTo> memPtr = ptr; return(memPtr.Copy(mem.Length / memPtr.ElementSize)); } }
// ReSharper restore UnusedMember.Local public bool Append(Pointer ip, int len) { int spaceLeft = _length - _index; if(spaceLeft < len) return false; var op = new Pointer(_buffer, _index); op.Copy(ip, len); _index += len; return true; }
public void Test4() { Pointer <int> p1 = stackalloc int[4]; var rg2 = new[] { 1, 2, 3, 4 }; var rg4 = new int[4]; p1.WriteAll(rg2); p1.Copy(rg4); Assert.True(rg2.SequenceEqual(rg4)); var rg3 = p1.ToArray(1, rg4.Length - 1); Assert.True(rg3.SequenceEqual(new[] { 2, 3, 4 })); }
public void Test3() { Pointer <int> p1 = stackalloc int[4]; Pointer <int> p2 = stackalloc int[4]; var rg2 = new[] { 1, 2, 3, 4 }; p1.WriteAll(rg2); p1.Copy(p2, rg2.Length); for (int i = 0; i < rg2.Length; i++) { Assert.True(p1[i] == p2[i]); } p2.Clear(rg2.Length); p1.Copy(p2, 1, rg2.Length - 1); var rg1 = new[] { 2, 3, 4 }; for (int i = 1; i < rg1.Length - 1; i++) { Assert.True(p2[i] == p1[i + 1]); } }
private static Pointer EmitLiteral(Pointer dest, Pointer literal, int length, bool allowFastPath) { int n = length - 1; if(n < 60) { var value = CompressorTag.Literal | (n << 2); dest[0] = (byte)value; dest += 1; if(allowFastPath && length <= 16) { dest.Copy64(literal); dest.Copy64(literal + 8, 8); return dest + length; } } else { var tmp = new Pointer(dest); dest += 1; int count = 0; while(n > 0) { dest[count] = (byte)(n & 0xff); n >>= 8; count++; } Debug.Assert(count >= 1); Debug.Assert(count <= 4); tmp[0] = (byte)(CompressorTag.Literal | (59 + count) << 2); dest += count; } dest.Copy(literal, length); return dest + length; }
public void Copy3() { src1.Copy(dest1, 0, (int)len); }