Imports System Imports System.Data Imports System.Data.SqlClient Imports System.Data.SqlTypes Imports Microsoft.SqlServer.Server Imports System.IO ‘ Declaration of the VarBinaryComp Structure. ‘ We implement the IBinarySerialize interface because of the fact that this ‘ structure uses “UserDefined” serialization _ _ Public Structure VarBinaryComp Implements INullable, Microsoft.SqlServer.Server.IBinarySerialize ... ‘UDTs must implement the ToString and Parse function to allow conversion ‘ to/from strings. With binary data, these functions provide little practical use. Public Overrides Function ToString() As String Try If m_Bytes Is Nothing Then Return String.Empty ‘Convert Compressed Byte Array to String Return System.Text.Encoding.Unicode.GetString(m_Bytes.Value) Catch ex As Exception Throw ex End Try End Function ‘Required property used to determine nullability Public ReadOnly Property IsNull() As Boolean Implements INullable.IsNull Get If m_Bytes Is Nothing Then Return True End If Return False End Get End Property ‘Required function used to return a new, null instance of the UDT. Public Shared ReadOnly Property Null() As VarBinaryComp Get Return New VarBinaryComp(False, Nothing, 0) End Get End Property ‘Example of a custom property (in this case, the uncompressed length of the binary data) Public ReadOnly Property UnCompressedLength() As SqlInt32 Get Return m_UnCompressedLength End Get End Property ‘This custom shared function instantiates a new instance of VarBinaryComp, ‘ using uncompressed data as input. Public Shared Function ParseVarBinaryU(ByVal sUncompressedBytes As SqlBytes) As VarBinaryComp Try ‘If we are passed in an empty byte array, return a Null instance If sUncompressedBytes Is Nothing Then Return VarBinaryComp.Null End If ‘Otherwise, call the overloaded constructor to return a new instance Return New VarBinaryComp(False, sUncompressedBytes, 0) Catch ex As Exception Throw ex End Try End Function ‘This custom shared function instantiates a new instance of VarBinaryComp, ‘ using data that is already compressed data as input. Public Shared Function ParseVarBinaryC(ByVal sCompressedBytes As SqlBytes, ByVal iUnCompressedLength As SqlInt32) As VarBinaryComp Try If sCompressedBytes.Value Is Nothing Then Return VarBinaryComp.Null End If Return New VarBinaryComp(True, sCompressedBytes, iUnCompressedLength) Catch ex As Exception Throw ex End Try End Function ‘UDTs must implement the ToString and Parse function to allow conversion ‘ to/from strings. With binary data, these functions typically are of little value. Public Shared Function Parse(ByVal s As SqlString) As VarBinaryComp Try If s.IsNull Then Return VarBinaryComp.Null End If