Exemplo n.º 1
0
        /// <summary>
        ///     Reads a single unsigned 64bit integer from the reader.
        /// </summary>
        /// <returns>The unsigned 64bit integer read.</returns>
        public ulong ReadUInt64()
        {
            if (Position + 8 > Length)
            {
                throw new EndOfStreamException($"Failed to read data from reader as the reader does not have enough data remaining. Expected 8 bytes but reader only has {Length - Position} bytes remaining.");
            }

            ulong v = BigEndianHelper.ReadUInt64(buffer.Buffer, buffer.Offset + Position);

            Position += 8;

            return(v);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Reads an array unsigned 64bit integers from the reader.
        /// </summary>
        /// <param name="destination">The array to read strings into.</param>
        /// <param name="offset">The offset at which to write bytes into the array.</param>
        public void ReadUInt64sInto(ulong[] destination, int offset)
        {
            if (Position + 4 > Length)
            {
                throw new EndOfStreamException($"Failed to read as the reader does not have enough data remaining. Expected 4 byte array length header but reader only has {Length - Position} bytes remaining.");
            }

            int length = BigEndianHelper.ReadInt32(buffer.Buffer, buffer.Offset + Position);

            if (Position + 4 + length * 8 > Length)
            {
                throw new EndOfStreamException($"Failed to read data from reader as the reader does not have enough data remaining. Expected {length * 8} bytes but reader only has {Length - Position - 4} bytes remaining.");
            }

            for (int i = 0, j = buffer.Offset + Position + 4; i < length; i++, j += 8)
            {
                destination[i + offset] = BigEndianHelper.ReadUInt64(buffer.Buffer, j);
            }

            Position += 4 + length * 8;
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Reads an array unsigned 64bit integers from the reader.
        /// </summary>
        /// <returns>The array of unsigned 64bit integers read.</returns>
        public ulong[] ReadUInt64s()
        {
            if (Position + 4 > Length)
            {
                throw new EndOfStreamException($"Failed to read as the reader does not have enough data remaining. Expected 4 byte array length header but reader only has {Length - Position} bytes remaining.");
            }

            int length = BigEndianHelper.ReadInt32(buffer.Buffer, buffer.Offset + Position);

            if (Position + 4 + length * 8 > Length)
            {
                throw new EndOfStreamException($"Failed to read data from reader as the reader does not have enough data remaining. Expected {length * 8} bytes but reader only has {Length - Position - 4} bytes remaining.");
            }

            ulong[] array = new ulong[length];
            for (int i = 0, j = buffer.Offset + Position + 4; i < length; i++, j += 8)
            {
                array[i] = BigEndianHelper.ReadUInt64(buffer.Buffer, j);
            }

            Position += 4 + length * 8;

            return(array);
        }