Private Sub WriteObject(o As Object, out As OutputStream)
    Dim data() As Byte
    tempArray(0) = o
    If tempArray(0) = Null Then
        out.WriteBytes(Array As Byte(T_NULL), 0, 1)
    Else If tempArray(0) Is Short Then
        out.WriteBytes(Array As Byte(T_SHORT), 0, 1)
        data = bc.ShortsToBytes(Array As Short(o))
    Else If tempArray(0) Is Int Then
        out.WriteBytes(Array As Byte(T_INT), 0, 1)
        data = bc.IntsToBytes(Array As Int(o))
    Else If tempArray(0) Is Float Then
        out.WriteBytes(Array As Byte(T_FLOAT), 0, 1)
        data = bc.FloatsToBytes(Array As Float(o))
    Else If tempArray(0) Is Double Then
        out.WriteBytes(Array As Byte(T_DOUBLE), 0, 1)
        data = bc.DoublesToBytes(Array As Double(o))
    Else If tempArray(0) Is Long Then
        out.WriteBytes(Array As Byte(T_LONG), 0, 1)
        data = bc.LongsToBytes(Array As Long(o))
    Else If tempArray(0) Is Boolean Then
        out.WriteBytes(Array As Byte(T_BOOLEAN), 0, 1)
        Dim b As Boolean = 0
        Dim data(1) As Byte
        If b Then data(0) = 1 Else data(0) = 0
    Else If GetType(tempArray(0)) = "[B" Then
        data = o
        out.WriteBytes(Array As Byte(T_BLOB), 0, 1)
        WriteInt(data.Length, out)   
    Else 'If o Is String Then (treat all other values as string)
        out.WriteBytes(Array As Byte(T_STRING), 0, 1)
        data = bc.StringToBytes(o, "UTF8")
        WriteInt(data.Length, out)
    End If
    If data.Length > 0 Then out.WriteBytes(data, 0, data.Length)
End Sub