WriteUInt32() публичный статический Метод

Write a uint value to a stream and advances the position within the stream by 4.
public static WriteUInt32 ( Stream stream, uint value ) : int
stream Stream The stream.
value uint A uint value.
Результат int
        /// <summary>
        /// Serialize this instance to a stream.
        /// </summary>
        /// <param name="stream">A data stream contains serialized object.</param>
        /// <returns>The number of bytes written to the stream.</returns>
        public int Serialize(System.IO.Stream stream)
        {
            int    bytesWriten = 0;
            string serverDns   = string.Empty;

            for (int i = 0; i < this.ServerDNArray.Length; i++)
            {
                serverDns += this.ServerDNArray[i];
            }

            byte[] serverDnBytes = System.Text.Encoding.ASCII.GetBytes(serverDns);

            bytesWriten += StreamHelper.WriteUInt32(stream, this.Flags);
            bytesWriten += StreamHelper.WriteUInt32(stream, this.Depth);
            bytesWriten += StreamHelper.WriteLongTermId(stream, this.FolderLongTermId);
            bytesWriten += StreamHelper.WriteUInt32(stream, this.ServerDNCount);
            bytesWriten += StreamHelper.WriteUInt32(stream, this.CheapServerDNCount);
            bytesWriten += StreamHelper.WriteBuffer(stream, serverDnBytes);
            return(bytesWriten);
        }
Пример #2
0
        /// <summary>
        /// Serialize this instance to a stream
        /// </summary>
        /// <param name="stream">A data stream contains serialized object.</param>
        /// <returns>The number of bytes written to the stream.</returns>
        public override int Serialize(Stream stream)
        {
            int previousPosition = (int)stream.Position;
            int bytesWritten     = 0;

            bytesWritten += StreamHelper.WriteUInt16(stream, this.version);
            bytesWritten += StreamHelper.WriteUInt16(stream, this.padding1);
            bytesWritten += StreamHelper.WriteUInt32(stream, this.errorCode);
            byte[] buffer = StructureSerializer.Serialize(this.folderGID);
            bytesWritten += StreamHelper.WriteBuffer(stream, buffer);
            bytesWritten += StreamHelper.WriteUInt16(stream, this.padding2);
            buffer        = StructureSerializer.Serialize(this.messageGID);
            bytesWritten += StreamHelper.WriteBuffer(stream, buffer);
            bytesWritten += StreamHelper.WriteUInt16(stream, this.padding3);

            if (this.reserved1 == null || this.reserved1.Length != 24)
            {
                AdapterHelper.Site.Assert.Fail("The Reserved field should not be null and its length MUST be 24, but the actual length is {0}.", this.reserved1.Length);
            }

            for (int i = 0; i < this.reserved1.Length; i++)
            {
                AdapterHelper.Site.Assert.AreEqual(0, this.reserved1[i], "Reserved (24 bytes):  SHOULD be set to zeros and SHOULD be ignored by clients.");
            }

            bytesWritten += StreamHelper.WriteBuffer(stream, this.reserved1);
            bytesWritten += StreamHelper.WriteUInt32(stream, this.auxBytesCount);
            bytesWritten += StreamHelper.WriteUInt32(stream, this.auxBytesOffset);
            if (this.reserved2 != null)
            {
                bytesWritten += StreamHelper.WriteBuffer(stream, this.reserved2);
            }

            AdapterHelper.Site.Assert.AreEqual((int)this.auxBytesOffset, previousPosition + bytesWritten, "The offset and writen length are not equal, the offset is {0} and writen length is {1}.", this.auxBytesOffset, previousPosition + bytesWritten);

            AdapterHelper.Site.Assert.AreEqual((int)this.auxBytesCount, this.auxBytes.Length, "The original and serialized auxBytes length are not equal, the original length is {0} and serialized length is {1}.", this.auxBytesCount, this.auxBytes.Length);

            bytesWritten += StreamHelper.WriteBuffer(stream, this.auxBytes);
            return(bytesWritten);
        }
        /// <summary>
        /// Serialize fields to a stream.
        /// </summary>
        /// <param name="stream">The stream where serialized instance will be wrote.</param>
        /// <returns>Bytes wrote to the stream.</returns>
        public override int Serialize(Stream stream)
        {
            int bytesWritten = 0;

            bytesWritten += StreamHelper.WriteGuid(stream, this.guid);
            bytesWritten += StreamHelper.WriteUInt32(stream, this.kind);
            if (this.kind == 0x00000000)
            {
                AdapterHelper.Site.Assert.IsNotNull(this.lid, "The value of GroupPropertyName.lid should not be null.");
                bytesWritten += StreamHelper.WriteUInt32(stream, (uint)this.lid);
            }
            else if (this.kind == 0x00000001)
            {
                AdapterHelper.Site.Assert.IsNotNull(this.nameSize, "The value of GroupPropertyName.nameSize is null.");

                bytesWritten += StreamHelper.WriteUInt32(stream, (uint)this.nameSize);
                byte[] buffer = Encoding.Unicode.GetBytes(this.name, 0, this.name.Length);
                bytesWritten += StreamHelper.WriteBuffer(stream, buffer);
            }

            return(bytesWritten);
        }
Пример #4
0
        /// <summary>
        /// Serialize current instance to a stream.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <returns>The number of bytes written to the stream.</returns>
        public override int Serialize(Stream stream)
        {
            int size = 0;

            StreamHelper.WriteUInt32(stream, this.propertyTagCount);
            size += 4;
            AdapterHelper.Site.Assert.AreEqual((int)this.propertyTagCount, this.propertyTags.Length, "This field MUST contain PropertyTagCount tags. The expected count is {0}, the actual count is {1}.", this.propertyTagCount, this.propertyTags.Length);

            for (int i = 0; i < this.propertyTagCount; i++)
            {
                PropertyTag tag = this.propertyTags[i].Item1;
                StreamHelper.WriteUInt16(stream, tag.PropertyType);
                StreamHelper.WriteUInt16(stream, tag.PropertyId);
                size += 4;
                if (this.IsNamedProperty(tag))
                {
                    GroupPropertyName name = this.propertyTags[i].Item2;
                    AdapterHelper.Site.Assert.IsNotNull(name, "The property name should not be null.");
                    size += name.Serialize(stream);
                }
            }

            return(size);
        }