OpenStory.Common.IO.LittleEndianBitConverter.FromBytes C# (CSharp) Method

FromBytes() private static method

Returns an integer by reading bytes in little-endian byte order.
/// Thrown if is . /// /// Thrown if falls outside the bounds of , /// OR, /// if is such that the segment's end falls outside the bounds of . ///
private static FromBytes ( byte buffer, int offset, int count ) : long
buffer byte The buffer to read bytes from.
offset int The index of the start of the segment.
count int The number of bytes to read.
return long
        private static long FromBytes(byte[] buffer, int offset, int count)
        {
            Guard.NotNull(() => buffer, buffer);

            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset", offset, CommonStrings.OffsetMustBeNonNegative);
            }

            if (offset > buffer.Length || offset + count > buffer.Length)
            {
                throw ArraySegmentException.GetByStartAndLength(offset, count);
            }

            long result = 0;
            int end = offset + count;
            for (int position = end - 1; position >= offset; position--)
            {
                result = unchecked((result << 8) | buffer[position]);
            }

            return result;
        }