WriteBuffer() public static method

Write bytes to a stream and advances the position within the stream by 16.
public static WriteBuffer ( Stream stream, byte buffer ) : int
stream Stream The stream.
buffer byte A byte array.
return int
Exemplo n.º 1
0
        /// <summary>
        /// Write  a LongTermId value to a stream
        /// and advances the position within the stream by 24.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <param name="id">A LongTermId value.</param>
        /// <returns>The number of bytes written to the stream.</returns>
        public static int WriteLongTermId(Stream stream, LongTermId id)
        {
            int size = 0;

            size += StreamHelper.WriteGuid(stream, new Guid(id.DatabaseGuid));
            size += StreamHelper.WriteBuffer(stream, id.GlobalCounter);
            size += StreamHelper.WriteBuffer(stream, new byte[2] {
                0x00, 0x00
            });
            return(size);
        }
        /// <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);
        }
Exemplo n.º 3
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);
        }