/// <summary> /// Deflate the token /// </summary> /// <param name="destination">Stream to deflate token to</param> public override void Deflate(Stream destination) { // Write token identifier destination.WriteByte((byte)TDSTokenType.SessionState); // Allocate a temporary memory stream MemoryStream memoryStream = new MemoryStream(); // Iterate through all option foreach (TDSSessionStateOption option in Options) { // Deflate into the memory stream to calcualte the overall length option.Deflate(memoryStream); } // Write the length TDSUtilities.WriteUInt(destination, (uint)(memoryStream.Length + sizeof(uint) /* Sequence Number */ + sizeof(byte) /* Status */ + memoryStream.Length)); // Write sequence number TDSUtilities.WriteUInt(destination, (uint)SequenceNumber); // Write status destination.WriteByte((byte)(IsRecoverable ? 1 : 0)); // Write the options memoryStream.WriteTo(destination); }
/// <summary> /// Deflate the token /// </summary> /// <param name="destination">Stream to deflate token to</param> public override void Deflate(Stream destination) { // Allocate temporary cache MemoryStream cache = new MemoryStream(); // Write header type TDSUtilities.WriteUShort(cache, (ushort)TDSHeaderType.Trace); byte[] guidBytes = new byte[16]; // Check if activity ID is available if (ActivityID != null) { guidBytes = ActivityID.ToByteArray(); } // Write trace identifier cache.Write(guidBytes, 0, guidBytes.Length); // Write activity identifier TDSUtilities.WriteUInt(cache, SequenceNumber); // Write the header length including self into the destination TDSUtilities.WriteUInt(destination, (uint)(cache.Length + 4)); // Write cached header data cache.WriteTo(destination); }
/// <summary> /// Delate the token. /// </summary> /// <param name="destination">Stream the token to deflate to.</param> public override void Deflate(Stream destination) { // Write FeatureID destination.WriteByte((byte)FeatureID); // Write FeatureAckDataLen TDSUtilities.WriteUInt(destination, FeatureAckDataLen); // Write data. destination.Write(FeatureAckData, 0, (int)FeatureAckDataLen); }
/// <summary> /// Write raw data /// </summary> protected void DeflateValue(Stream destination, byte[] value) { // Check length if (value != null && value.Length >= 0xFF) { // Write the prefix to indicate a DWORD length destination.WriteByte(0xFF); // Length is DWORD TDSUtilities.WriteUInt(destination, (uint)value.Length); } else { // Length is byte destination.WriteByte((byte)value.Length); } // Serialize the data itself if (value != null) { destination.Write(value, 0, value.Length); } }