Exemplo n.º 1
0
        protected long[] constructLongArrayFromInt64(int machinecode, byte[] data)
        {
            var result = new long[data.Length / 8];

            if (machinecode == 12)
            {
                for (int i = 0; i < result.Length; i++)
                {
                    result[i] = PickleUtils.bytes_to_long(data, i * 8);
                }
            }
            else
            {
                var bigendian = new byte[8];
                for (int i = 0; i < result.Length; i++)
                {
                    // 13=big endian, swap
                    bigendian[0] = data[7 + i * 8];
                    bigendian[1] = data[6 + i * 8];
                    bigendian[2] = data[5 + i * 8];
                    bigendian[3] = data[4 + i * 8];
                    bigendian[4] = data[3 + i * 8];
                    bigendian[5] = data[2 + i * 8];
                    bigendian[6] = data[1 + i * 8];
                    bigendian[7] = data[0 + i * 8];
                    result[i]    = PickleUtils.bytes_to_long(bigendian, 0);
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        public void TestBytes_to_long()
        {
            try {
                PickleUtils.bytes_to_long(new byte[] {}, 0);
                Assert.True(false, "expected PickleException");
            } catch (PickleException) {}
            try {
                PickleUtils.bytes_to_long(new byte[] { 0 }, 0);
                Assert.True(false, "expected PickleException");
            } catch (PickleException) {}

            Assert.Equal(0x00000000L, PickleUtils.bytes_to_long(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0));
            Assert.Equal(0x00003412L, PickleUtils.bytes_to_long(new byte[] { 0x12, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0));
            Assert.Equal(-0xffffffffffff01L, PickleUtils.bytes_to_long(new byte[] { 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff }, 0));
            Assert.Equal(0L, PickleUtils.bytes_to_long(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }, 0));
            Assert.Equal(-0x778899aabbccddefL, PickleUtils.bytes_to_long(new byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88 }, 0));
            Assert.Equal(0x1122334455667788L, PickleUtils.bytes_to_long(new byte[] { 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11 }, 0));
            Assert.Equal(-1L, PickleUtils.bytes_to_long(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, 0));
            Assert.Equal(-2L, PickleUtils.bytes_to_long(new byte[] { 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, 0));
        }