Microsoft.Protocols.TestSuites.Common.BufferReader.ReadUInt32 C# (CSharp) Method

ReadUInt32() public method

Reads a 4-byte unsigned integer from the current position and advances the current position of the buffer by 4 bytes.
public ReadUInt32 ( ) : uint
return uint
        public uint ReadUInt32()
        {
            if (this.position + 3 >= this.length)
            {
                throw new Exception("bufferReader out of bound.");
            }

            int part1 = (int)this.buffer[this.position++];
            int part2 = (int)(this.buffer[this.position++] << 8);
            int part3 = (int)(this.buffer[this.position++] << 16);
            int part4 = (int)(this.buffer[this.position++] << 24);
            return (uint)(part1 + part2 + part3 + part4);
        }

Usage Example

        /// <summary>
        /// Deserialized byte array to a ReplyActionData instance
        /// </summary>
        /// <param name="buffer">Byte array contains data of an ActionData instance.</param>
        /// <returns>Bytes count that deserialized in buffer.</returns>
        public uint Deserialize(byte[] buffer)
        {
            BufferReader bufferReader = new BufferReader(buffer);
            this.messageEIDSize = bufferReader.ReadUInt32();
            this.replyTemplateMessageEID = bufferReader.ReadBytes(this.messageEIDSize);
            uint guidLength = (uint)Guid.NewGuid().ToByteArray().Length;
            this.ReplyTemplateGUID = bufferReader.ReadBytes((uint)guidLength);

            return bufferReader.Position;
        }
All Usage Examples Of Microsoft.Protocols.TestSuites.Common.BufferReader::ReadUInt32