2.2.9.2 KeyValue Structure
The KeyValue structure specifies the value of a key column.
|
|
|
|
|
|
|
|
|
|
1 |
|
|
|
|
|
|
|
|
|
2 |
|
|
|
|
|
|
|
|
|
3 |
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
keyValue (variable) |
|||||||||||||||||||||||||||||||
... |
keyValue (variable): A binary value that represents the value of a key column. The type of the binary value MUST be one of the types in the following table and is determined by the data type of the corresponding key column. For each type, the following table describes the size in bytes of the value and the method used to deserialize the binary value.
-
CLR data type
Size in bytes
Deserialization method
String
variable
BinaryReader.ReadString
Char
2
BinaryReader.ReadChar
Int32
4
BinaryReader.ReadInt32
Int16
2
BinaryReader.ReadInt16
UInt16
2
BinaryReader.ReadUInt16
Byte
1
BinaryReader.ReadByte
SByte
1
BinaryReader.ReadSByte
Decimal
16
BinaryReader.ReadDecimal
Int64
8
BinaryReader.ReadInt64
UInt64
8
BinaryReader.ReadUInt64
UInt32
4
BinaryReader.ReadUInt32
Double
8
BinaryReader.ReadDouble
Single
4
BinaryReader.ReadSingle
DateTime
8
DateTimeOffset
8
TimeSpan
8
Boolean
1
BinaryReader.ReadBoolean
Guid
16
ByteArray
variable
-
Key column values are deserialized from a stream by applying a BinaryReader [MSDN-BRM] method as specified in the preceding table according to the type of the value. The five exceptions to this rule are key column values that have one of the following types: DateTime, DateTimeOffset, TimeSpan, Guid, and ByteArray.
-
Key column values that have the DateTime or DateTimeOffset type are deserialized by first applying the BinaryReader.ReadInt64 [MSDN-BRM] method and then applying the DateTime.FromBinary [MSDN-DTM] method.
-
Key column values that have the TimeSpan type are deserialized by first applying the BinaryReader.ReadInt64 [MSDN-BRM] method and then applying the TimeSpan.FromTicks [MSDN-TSFTM] method.
-
Key column values that have the Guid type are deserialized by first calling the BinaryReader.ReadBytes(16) [MSDN-BRM] method and then creating a new globally unique identifier (GUID) with the result of the method call.
-
Key column values that have the ByteArray type are deserialized by first deserializing the length of the byte array by using the BinaryReader.ReadInt32 [MSDN-BRM] method and then deserializing the bytes by using the BinaryReader.ReadBytes(length) [MSDN-BRM] method.
-
Binary serialization of key column values to a stream is performed by applying the BinaryWriter.Write [MSDN-BWM] method to the key column value whose type is specified in the preceding table. The five exceptions to this rule are values that have one of the following types: DateTime, DateTimeOffset, TimeSpan, Guid, and ByteArray.
-
DateTime is serialized by first applying the DateTime.ToBinary [MSDN-DTM] method followed by BinaryWriter.Write [MSDN-BWM].
-
DateTimeOffset is serialized by first applying the DateTimeOffset.UtcDateTime [MSDN-DTOUTCP] and DateTime.ToBinary [MSDN-DTM] methods followed by BinaryWriter.Write [MSDN-BWM].
-
TimeSpan is serialized by first applying the TimeSpan.Ticks [MSDN-TSTP] method followed by BinaryWriter.Write [MSDN-BWM].
-
Guid is serialized by first applying the Guid.ToByteArray [MSDN-GTBAM] method followed by BinaryWriter.Write [MSDN-BWM].
-
ByteArray is serialized by first serializing the Int32 length of the byte array by using BinaryWriter.Write [MSDN-BWM] and then serializing the byte array by using BinaryWriter.Write [MSDN-BWM].