code: def write(self, w, val):
          
          if val.is_null():
              w.put_usmallint(tds_base.TVP_NULL_TOKEN)
          else:
              columns = self._table_type.columns
              w.put_usmallint(len(columns))
              for i, column in enumerate(columns):
                  w.put_uint(column.column_usertype)
  
                  w.put_usmallint(column.flags)
  
                  # TYPE_INFO structure: https://msdn.microsoft.com/en-us/library/dd358284.aspx
  
                  serializer = self._columns_serializers[i]
                  type_id = serializer.type
                  w.put_byte(type_id)
                  serializer.write_info(w)
  
                  w.write_b_varchar('')  # ColName, must be empty in TVP according to spec
  
          # here can optionally send TVP_ORDER_UNIQUE and TVP_COLUMN_ORDERING
          # https://msdn.microsoft.com/en-us/library/dd305261.aspx
  
          # terminating optional metadata
          w.put_byte(tds_base.TVP_END_TOKEN)
  
          # now sending rows using TVP_ROW
          # https://msdn.microsoft.com/en-us/library/dd305261.aspx
          if val.rows:
              for row in val.rows:
                  w.put_byte(tds_base.TVP_ROW_TOKEN)
                  for i, col in enumerate(self._table_type.columns):
                      if not col.flags & tds_base.TVP_COLUMN_DEFAULT_FLAG:
                          self._columns_serializers[i].write(w, row[i])
  
          # terminating rows
          w.put_byte(tds_base.TVP_END_TOKEN)
docs: Writes remaining part of TVP_TYPE_INFO structure, resuming from TVP_COLMETADATA
  
          specs:
          https://msdn.microsoft.com/en-us/library/dd302994.aspx
          https://msdn.microsoft.com/en-us/library/dd305261.aspx
          https://msdn.microsoft.com/en-us/library/dd303230.aspx
  
          @param w: TdsWriter
          @param val: TableValuedParam or None
          @return: