1e9cf93e9eaa103c82720512158b93f3e77b1f88
[platform/upstream/dotnet/runtime.git] /
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4
5 using System.IO;
6
7 namespace Microsoft.SqlServer.TDS.SessionState
8 {
9     /// <summary>
10     /// Generic session state option
11     /// </summary>
12     public class TDSSessionStateGenericOption : TDSSessionStateOption
13     {
14         /// <summary>
15         /// State option value
16         /// </summary>
17         public byte[] Value { get; set; }
18
19         /// <summary>
20         /// Initialization constructor
21         /// </summary>
22         public TDSSessionStateGenericOption(byte stateID) :
23             base(stateID)
24         {
25         }
26
27         /// <summary>
28         /// Initialization constructor
29         /// </summary>
30         public TDSSessionStateGenericOption(byte stateID, byte[] value) :
31             this(stateID)
32         {
33             Value = value;
34         }
35
36         /// <summary>
37         /// Deflate state into the stream
38         /// </summary>
39         public override void Deflate(Stream destination)
40         {
41             // Write state ID
42             destination.WriteByte(StateID);
43
44             // Write value as is
45             DeflateValue(destination, Value);
46         }
47
48         /// <summary>
49         /// Inflate from stream
50         /// </summary>
51         public override bool Inflate(Stream source)
52         {
53             // Reset inflation size
54             InflationSize = 0;
55
56             // NOTE: state ID is skipped because it is read by the construction factory
57
58             // Inflate value
59             Value = InflateValue(source);
60
61             // Inflation is complete
62             return true;
63         }
64     }
65 }