Esempio n. 1
0
        public void ValueLittleEndianTest()
        {
            int    bufferOffset      = 1;
            UInt64 bufferSourceValue = 0x123456789ABCDEF0;
            var    bufferSource      = new byte[] { 0xFF, 0xF0, 0xDE, 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, 0xFF };

            // Test ToUInt
            UInt64 value = bufferSource.ToUInt64(sizeof(UInt64), bufferOffset, signExtend: false, EndianFormat.Little);

            value.ShouldBe(bufferSourceValue);

            // Test ToBuffer
            var bufferOutput        = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
            var bufferOutputSegment = new ArraySegment <byte>(bufferOutput, bufferOffset, bufferOutput.Length - bufferOffset);

            value.ToBuffer(sizeof(UInt64), bufferOutputSegment, endian: EndianFormat.Little).Array.ShouldBe(bufferSource);
        }
        public void UInt64BigEndianTest()
        {
            int    bufferOffset      = 2;
            UInt64 bufferSourceValue = 0x123456789ABCDEF0;
            var    bufferSource      = new byte[] { 0xFF, 0xFF, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0, 0xFF, 0xFF };

            // Test ToUInt
            UInt64 value = bufferSource.ToUInt64(bufferOffset);

            value.ShouldBe(bufferSourceValue);

            // Test ToBuffer
            var bufferOutput        = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
            var bufferOutputSegment = new ArraySegment <byte>(bufferOutput, bufferOffset, bufferOutput.Length - bufferOffset);

            value.ToBuffer(bufferOutputSegment).Array.ShouldBe(bufferSource);
            value.ToBuffer(bufferOutput.Fill(0xFF), startOffset: bufferOffset).ShouldBe(bufferSource);
            value.ToBufferNew().ShouldBe(new byte[] { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0 });
        }