/// <summary>
        /// Deflate the token
        /// </summary>
        /// <param name="destination">Stream to deflate token to</param>
        public override void Deflate(Stream destination)
        {
            destination.WriteByte((byte)TDSTokenType.ReturnValue);

            TDSUtilities.WriteUShort(destination, ParamOrdinal);

            destination.WriteByte((byte)ParamName.Length);
            TDSUtilities.WriteString(destination, ParamName);

            destination.WriteByte((byte)Status);

            TDSUtilities.WriteUInt(destination, UserType);

            TDSUtilities.WriteUShort(destination, Flags.ToUShort());

            // Write type
            destination.WriteByte((byte)DataType);

            // Dispatch further writing based on the type
            switch (DataType)
            {
            case TDSDataType.Binary:
            case TDSDataType.VarBinary:
            case TDSDataType.Char:
            case TDSDataType.VarChar:
            case TDSDataType.BitN:
            case TDSDataType.Guid:
            case TDSDataType.IntN:
            case TDSDataType.MoneyN:
            case TDSDataType.FloatN:
            case TDSDataType.DateTimeN:
            {
                // Byte length
                destination.WriteByte((byte)DataTypeSpecific);
                break;
            }

            case TDSDataType.DateN:
            {
                // No details
                break;
            }

            case TDSDataType.TimeN:
            case TDSDataType.DateTime2N:
            case TDSDataType.DateTimeOffsetN:
            {
                // Scale
                destination.WriteByte((byte)DataTypeSpecific);
                break;
            }

            case TDSDataType.DecimalN:
            case TDSDataType.NumericN:
            {
                // Cast to type-specific information
                TDSDecimalColumnSpecific typeSpecific = DataTypeSpecific as TDSDecimalColumnSpecific;

                // Write values
                destination.WriteByte(typeSpecific.Length);
                destination.WriteByte(typeSpecific.Precision);
                destination.WriteByte(typeSpecific.Scale);
                break;
            }

            case TDSDataType.BigBinary:
            case TDSDataType.BigVarBinary:
            {
                // Short length
                TDSUtilities.WriteUShort(destination, (ushort)DataTypeSpecific);
                break;
            }

            case TDSDataType.BigChar:
            case TDSDataType.BigVarChar:
            case TDSDataType.NChar:
            case TDSDataType.NVarChar:
            {
                // Cast to type specific information
                TDSShilohVarCharColumnSpecific typedSpecific = DataTypeSpecific as TDSShilohVarCharColumnSpecific;

                // Write length
                TDSUtilities.WriteUShort(destination, typedSpecific.Length);

                // Write collation
                TDSUtilities.WriteUInt(destination, typedSpecific.Collation.WCID);
                destination.WriteByte(typedSpecific.Collation.SortID);
                break;
            }

            case TDSDataType.Text:
            case TDSDataType.NText:
            {
                // YukonTextType.Len + YukonTextType.tdsCollationInfo + YukonTextType.cParts
                // cb = sizeof(LONG) + sizeof(TDSCOLLATION) + sizeof(BYTE);
                break;
            }

            case TDSDataType.Image:
            {
                // Integer length
                TDSUtilities.WriteUInt(destination, (uint)DataTypeSpecific);
                break;
            }

            case TDSDataType.SSVariant:
            {
                // Data length
                TDSUtilities.WriteUInt(destination, (uint)DataTypeSpecific);
                break;
            }

            case TDSDataType.Udt:
            {
                // hr = GetUDTColFmt(pvOwner, dwTimeout);
                break;
            }

            case TDSDataType.Xml:
            {
                // cb = sizeof(lpColFmt->YukonXmlType.bSchemaPresent);
                break;
            }
            }

            Microsoft.SqlServer.TDS.Row.TDSRowTokenBase.DeflateTypeVarByte(destination, DataType, Value, DataTypeSpecific);
        }
        public override bool Inflate(Stream source)
        {
            var len = source.ReadByte();

            if (len == -1)
            {
                return(false);
            }
            ParamMetaData = TDSUtilities.ReadString(source, (ushort)(len * 2));

            StatusFlags = new TDSRPCRequestStatusFlags((byte)source.ReadByte());

            DataType = (TDSDataType)source.ReadByte();

            // Dispatch further reading based on the type
            switch (DataType)
            {
            case TDSDataType.Binary:
            case TDSDataType.VarBinary:
            case TDSDataType.Char:
            case TDSDataType.VarChar:
            // The above types are deprecated after TDS 7205.

            case TDSDataType.BitN:
            case TDSDataType.Guid:
            case TDSDataType.IntN:
            case TDSDataType.MoneyN:
            case TDSDataType.FloatN:
            case TDSDataType.DateTimeN:
            {
                // Byte length
                DataTypeSpecific = source.ReadByte();
                break;
            }

            case TDSDataType.DateN:
            {
                // No details
                DataTypeSpecific = null;
                break;
            }

            case TDSDataType.TimeN:
            case TDSDataType.DateTime2N:
            case TDSDataType.DateTimeOffsetN:
            {
                // Scale
                DataTypeSpecific = source.ReadByte();
                break;
            }

            case TDSDataType.DecimalN:
            case TDSDataType.NumericN:
            {
                // Read values
                byte length    = (byte)source.ReadByte();
                byte precision = (byte)source.ReadByte();
                byte scale     = (byte)source.ReadByte();

                // Decimal data type specific
                DataTypeSpecific = new TDSDecimalColumnSpecific(length, precision, scale);
                break;
            }

            case TDSDataType.BigBinary:
            case TDSDataType.BigVarBinary:
            {
                // Short length
                DataTypeSpecific = TDSUtilities.ReadUShort(source);
                break;
            }

            case TDSDataType.BigChar:
            case TDSDataType.BigVarChar:
            case TDSDataType.NChar:
            case TDSDataType.NVarChar:
            {
                // SHILOH CHAR types have collation associated with it.
                TDSShilohVarCharColumnSpecific typedSpecific = new TDSShilohVarCharColumnSpecific();

                // Read length
                typedSpecific.Length = TDSUtilities.ReadUShort(source);

                // Create collation
                typedSpecific.Collation = new TDSColumnDataCollation();

                // Read collation
                typedSpecific.Collation.WCID   = TDSUtilities.ReadUInt(source);
                typedSpecific.Collation.SortID = (byte)source.ReadByte();

                DataTypeSpecific = typedSpecific;
                break;
            }

            case TDSDataType.Text:
            case TDSDataType.NText:
            {
                // YukonTextType.Len + YukonTextType.tdsCollationInfo + YukonTextType.cParts
                // cb = sizeof(LONG) + sizeof(TDSCOLLATION) + sizeof(BYTE);
                break;
            }

            case TDSDataType.Image:
            {
                // Data length
                DataTypeSpecific = TDSUtilities.ReadUInt(source);
                break;
            }

            case TDSDataType.SSVariant:
            {
                // Data length
                DataTypeSpecific = TDSUtilities.ReadUInt(source);
                break;
            }

            case TDSDataType.Udt:
            {
                // hr = GetUDTColFmt(pvOwner, dwTimeout);
                break;
            }

            case TDSDataType.Xml:
            {
                // cb = sizeof(lpColFmt->YukonXmlType.bSchemaPresent);
                break;
            }
            }

            Value = TDSRowTokenBase.InflateColumnData(source, DataType, DataTypeSpecific);

            return(true);
        }