ReadUInt16() public static method

Read a ushort value from a stream and advances the position within the stream by 2.
public static ReadUInt16 ( Stream stream ) : ushort
stream Stream The stream.
return ushort
コード例 #1
0
        /// <summary>
        /// Deserialize from a stream.
        /// </summary>
        /// <param name="stream">A stream contains serialize.</param>
        /// <param name="size">Must be -1.</param>
        /// <returns>The number of bytes read from the stream.</returns>
        public override int Deserialize(Stream stream, int size)
        {
            AdapterHelper.Site.Assert.AreEqual(-1, size, "The size value MUST be -1, the actual value is {0}.", size);

            this.globset = new GLOBSET();
            this.repLID  = StreamHelper.ReadUInt16(stream);
            return(this.globset.Deserialize(stream, -1) + 2);
        }
コード例 #2
0
        /// <summary>
        /// Deserialize fields in this class from a stream.
        /// </summary>
        /// <param name="stream">Stream contains a serialized instance of this class.</param>
        /// <param name="size">The number of bytes can read if -1, no limitation.</param>
        /// <returns>Bytes have been read from the stream.</returns>
        public override int Deserialize(Stream stream, int size)
        {
            int bytesRead = 0;

            this.version = StreamHelper.ReadUInt16(stream);
            bytesRead   += 2;
            if (size >= 0 && bytesRead > size)
            {
                AdapterHelper.Site.Assert.Fail("The bytes length to read is larger than stream size, the stream size is {0} and the bytes to read is {1}.", size, bytesRead);
            }

            this.padding1 = StreamHelper.ReadUInt16(stream);
            bytesRead    += 2;
            if (size >= 0 && bytesRead > size)
            {
                AdapterHelper.Site.Assert.Fail("The bytes length to read is larger than stream size, the stream size is {0} and the bytes to read is {1}.", size, bytesRead);
            }

            this.faiMessageCount = StreamHelper.ReadUInt32(stream);
            bytesRead           += 4;
            if (size >= 0 && bytesRead > size)
            {
                AdapterHelper.Site.Assert.Fail("The bytes length to read is larger than stream size, the stream size is {0} and the bytes to read is {1}.", size, bytesRead);
            }

            this.faiMessageTotalSize = StreamHelper.ReadUInt64(stream);
            bytesRead += 8;
            if (size >= 0 && bytesRead > size)
            {
                AdapterHelper.Site.Assert.Fail("The bytes length to read is larger than stream size, the stream size is {0} and the bytes to read is {1}.", size, bytesRead);
            }

            this.normalMessageCount = StreamHelper.ReadUInt32(stream);
            bytesRead += 4;
            if (size >= 0 && bytesRead > size)
            {
                AdapterHelper.Site.Assert.Fail("The bytes length to read is larger than stream size, the stream size is {0} and the bytes to read is {1}.", size, bytesRead);
            }

            this.padding2 = StreamHelper.ReadUInt32(stream);
            bytesRead    += 4;
            if (size >= 0 && bytesRead > size)
            {
                AdapterHelper.Site.Assert.Fail("The bytes length to read is larger than stream size, the stream size is {0} and the bytes to read is {1}.", size, bytesRead);
            }

            this.normalMessageTotalSize = StreamHelper.ReadUInt64(stream);
            bytesRead += 8;
            if (size >= 0 && bytesRead > size)
            {
                AdapterHelper.Site.Assert.Fail("The bytes length to read is larger than stream size, the stream size is {0} and the bytes to read is {1}.", size, bytesRead);
            }

            return(bytesRead);
        }
コード例 #3
0
        /// <summary>
        /// Deserialize from a stream.
        /// </summary>
        /// <param name="stream">A stream contains serialize.</param>
        /// <param name="size">Must be -1.</param>
        /// <returns>The number of bytes read from the stream.</returns>
        public override int Deserialize(Stream stream, int size)
        {
            int previousPosition = (int)stream.Position;
            int bytesRead        = 0;

            this.version   = StreamHelper.ReadUInt16(stream);
            bytesRead     += 2;
            this.padding1  = StreamHelper.ReadUInt16(stream);
            bytesRead     += 2;
            this.errorCode = StreamHelper.ReadUInt32(stream);
            bytesRead     += 4;
            byte[] buffer = new byte[22];
            stream.Read(buffer, 0, 22);
            this.folderGID = StructureSerializer.Deserialize <GID>(buffer);
            bytesRead     += 22;
            this.padding2  = StreamHelper.ReadUInt16(stream);
            bytesRead     += 2;
            buffer         = new byte[22];
            stream.Read(buffer, 0, 22);
            this.messageGID = StructureSerializer.Deserialize <GID>(buffer);
            bytesRead      += 22;
            this.padding3   = StreamHelper.ReadUInt16(stream);
            bytesRead      += 2;
            this.reserved1  = new byte[24];
            stream.Read(this.reserved1, 0, 24);
            bytesRead          += 24;
            this.auxBytesCount  = StreamHelper.ReadUInt32(stream);
            bytesRead          += 4;
            this.auxBytesOffset = StreamHelper.ReadUInt32(stream);
            bytesRead          += 4;
            int reservedBytesCount = (int)this.auxBytesOffset - previousPosition - bytesRead;

            if (reservedBytesCount > 0)
            {
                this.reserved2 = new byte[reservedBytesCount];
                bytesRead     += stream.Read(this.reserved2, 0, reservedBytesCount);
            }
            else if (reservedBytesCount == 0)
            {
                this.reserved2 = null;
            }
            else
            {
                AdapterHelper.Site.Assert.Fail("The deserialization operation should be successful.");
            }

            this.auxBytes = new byte[this.auxBytesCount];
            bytesRead    += stream.Read(this.auxBytes, 0, (int)this.auxBytesCount);
            AdapterHelper.Site.Assert.AreEqual(size, bytesRead, "The stream size is not equal to the bytes to read. The stream size is {0} and the read bytes is {1}.", size, bytesRead);

            return(bytesRead);
        }
コード例 #4
0
ファイル: CN.cs プロジェクト: v-zhonmi/Interop-TestSuites
        /// <summary>
        /// Deserialize an object from a stream
        /// </summary>
        /// <param name="stream">A stream contains object fields.</param>
        /// <param name="size">Max length can used by this deserialization
        /// if -1 no limitation except stream length.
        /// </param>
        /// <returns>The number of bytes read from the stream.</returns>
        public override int Deserialize(System.IO.Stream stream, int size)
        {
            int bytesRead = 0;

            this.replicaId = StreamHelper.ReadUInt16(stream);
            bytesRead     += 2;
            if (size >= 0 && bytesRead > size)
            {
                AdapterHelper.Site.Assert.Fail("The bytes length to read is larger than stream size, the stream size is {0} and the bytes to read is {1}.", size, bytesRead);
            }

            byte[] globalCounterByte = new byte[8];
            stream.Read(globalCounterByte, 0, 6);
            this.globalCounter = BitConverter.ToUInt64(globalCounterByte, 0);
            bytesRead         += 6;
            if (size >= 0 && bytesRead > size)
            {
                AdapterHelper.Site.Assert.Fail("The bytes length to read is larger than stream size, the stream size is {0} and the bytes to read is {1}.", size, bytesRead);
            }

            return(bytesRead);
        }
コード例 #5
0
        /// <summary>
        /// Deserialize an object from a stream.
        /// </summary>
        /// <param name="stream">A stream contains object fields.</param>
        /// <param name="size">Max length can used by this deserialization
        /// if -1 no limitation except stream length.
        /// </param>
        /// <returns>The number of bytes read from the stream.</returns>
        public override int Deserialize(Stream stream, int size)
        {
            AdapterHelper.Site.Assert.AreEqual(-1, size, "The size value MUST be -1, the actual value is {0}.", size);

            int bytesRead = 0;
            int i;

            this.propertyTagCount = StreamHelper.ReadUInt32(stream);
            bytesRead            += 4;
            this.propertyTags     = new Tuple <PropertyTag, GroupPropertyName> [this.propertyTagCount];
            for (i = 0; i < this.propertyTagCount; i++)
            {
                PropertyTag tag = new PropertyTag
                {
                    PropertyType = StreamHelper.ReadUInt16(stream)
                };
                bytesRead     += 2;
                tag.PropertyId = StreamHelper.ReadUInt16(stream);
                bytesRead     += 2;
                GroupPropertyName name = null;
                if (this.IsNamedProperty(tag))
                {
                    name       = new GroupPropertyName();
                    bytesRead += name.Deserialize(stream, -1);
                }

                this.propertyTags[i] = new Tuple <PropertyTag, GroupPropertyName>(tag, name);
            }

            if (size >= 0 && bytesRead > size)
            {
                AdapterHelper.Site.Assert.Fail("The bytes length to read is larger than stream size, the stream size is {0} and the bytes to read is {1}.", size, bytesRead);
            }

            return(bytesRead);
        }