WriteGuid() public static method

Write a GUID value to a stream and advances the position within the stream by 16
public static WriteGuid ( Stream stream, System.Guid guid ) : int
stream Stream The stream.
guid System.Guid A GUID value.
return int
Beispiel #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 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);
        }