Ejemplo n.º 1
0
        /// <summary>
        /// Read a string of the given amount of characters from the buffer. Advances the reader offset.
        /// </summary>
        unsafe public virtual string ReadString(int charCount)
        {
            if (charCount == 0)
            {
                return(string.Empty);
            }

            string value = new string((char *)((byte *)_buffer.DangerousGetHandle() + _byteOffset), startIndex : 0, length : charCount);

            _byteOffset += (ulong)(charCount * sizeof(char));
            return(value);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Read the given struct type at the current offset.
        /// </summary>
        public unsafe virtual T ReadStruct <T>() where T : struct
        {
            ulong sizeOfStruct = (ulong)Marshal.SizeOf <T>();

            T value = Marshal.PtrToStructure <T>(_buffer.DangerousGetHandle() + checked ((int)_byteOffset));

            _byteOffset += sizeOfStruct;
            return(value);
        }