public override void Deflate(Stream destination)
{
// Write state ID
destination.WriteByte(StateID);
// First 4 bytes are flags
int userOptions = 0;
// Next 4 bytes are masks
int userOptionsMask = unchecked((int)0xffffffff); // We only care about settings all bits
// Next byte are option user options
byte optionalUserOptions = 0;
// OPT_ANSI_WARNINGS
if (AnsiWarnings)
{
userOptions |= OPT_ANSI_WARNINGS;
}
// OPT_ANSI_NULLS
if (AnsiNulls)
{
userOptions |= OPT_ANSI_NULLS;
}
// OPT_CURSOR_COMMIT_CLOSE
if (CursorCloseOnCommit)
{
userOptions |= OPT_CURSOR_COMMIT_CLOSE;
}
// OPT_QUOTEDIDENT
if (QuotedIdentifier)
{
userOptions |= OPT_QUOTEDIDENT;
}
// OPT_CATNULL
if (ConcatNullYieldsNull)
{
userOptions |= OPT_CATNULL;
}
// OPT_ANSINULLDFLTON
if (AnsiNullDefaultOn)
{
userOptions |= OPT_ANSINULLDFLTON;
}
else
{
// Turn off the bit in the mask
userOptionsMask &= ~OPT_ANSINULLDFLTON;
}
// OPT_ANSI_PADDING
if (AnsiPadding)
{
userOptions |= OPT_ANSI_PADDING;
}
// OPT_ARITHABORT
if (ArithAbort)
{
userOptions |= OPT_ARITHABORT;
}
// OPT_NUMEABORT
if (NumericRoundAbort)
{
userOptions |= OPT_NUMEABORT;
}
// OPT_XACTABORT
if (TransactionAbortOnError)
{
userOptions |= OPT_XACTABORT;
}
// OPT_NOCOUNT
if (NoCount)
{
userOptions |= OPT_NOCOUNT;
}
// OPT_ARITHIGN
if (ArithIgnore)
{
userOptions |= OPT_ARITHIGN;
}
// OPT2_IMPLICIT_XACT
if (ImplicitTransactions)
{
optionalUserOptions |= OPT2_IMPLICIT_XACT;
}
// Allocate an array for all of this
MemoryStream cache = new MemoryStream();
// Put user options in it
byte[] subValue = BitConverter.GetBytes(userOptions);
cache.Write(subValue, 0, subValue.Length);
// Store mask in the cache
subValue = BitConverter.GetBytes(userOptionsMask);
cache.Write(subValue, 0, subValue.Length);
// Write additional byte
cache.WriteByte(optionalUserOptions);
// Store the value
DeflateValue(destination, cache.ToArray());
}