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

ReadBytes() public method

Reads the specified number of bytes from the current position into a byte array and advances the current position by that number of bytes.
public ReadBytes ( uint length ) : byte[]
length uint The number of bytes to read.
return byte[]
        public byte[] ReadBytes(uint length)
        {
            if (length <= 0)
            {
                return null;
            }

            if (this.position + length > this.length)
            {
                throw new Exception("bufferReader out of bound.");
            }

            byte[] bytes = new byte[length];
            for (int i = 0; i < length; i++)
            {
                bytes[i] = this.buffer[this.position++];
            }

            return bytes;
        }

Same methods

BufferReader::ReadBytes ( uint index, uint length ) : byte[]

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::ReadBytes