示例#1
0
        public static TTo[] ConvertArray <TTo>(byte[] mem)
        {
            fixed(byte *ptr = mem)
            {
                Pointer <TTo> memPtr = ptr;

                return(memPtr.Copy(mem.Length / memPtr.ElementSize));
            }
        }
示例#2
0
文件: Writer.cs 项目: reuzel/CqlSharp
        // 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;
        }
示例#3
0
    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 }));
    }
示例#4
0
    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]);
        }
    }
示例#5
0
        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;
        }
示例#6
0
 public void Copy3()
 {
     src1.Copy(dest1, 0, (int)len);
 }