def classForMessage(id, payload)
      if @@classForMessage.nil?
        @@classForMessage = [Choke, Unchoke, Interested, Uninterested, Have, BitfieldMessage, Request, Piece, Cancel]
        @@classForMessage[20] = Extended
      end

      if @@classForExtendedMessage.nil?
        @@classForExtendedMessage = []
        @@classForExtendedMessage[Extension::MetadataExtensionId] = ExtendedMetaInfo
      end
      
      result = @@classForMessage[id]
      
      if result == Extended && payload
        # Extended messages have further subtypes.
        extendedMsgId = payload.unpack("C")[0]
        if extendedMsgId == 0
          result = ExtendedHandshake
        else
          # In this case the extended message number is the one we told our peers to use, not the one the peer told us.
          result = @@classForExtendedMessage[extendedMsgId]
          raise "Unsupported extended peer message id '#{extendedMsgId}'" if ! result 
        end

      end

      result
    end
def classForMessage(id, payload)
      if @@classForMessage.nil?
        @@classForMessage = [Choke, Unchoke, Interested, Uninterested, Have, BitfieldMessage, Request, Piece, Cancel]
        @@classForMessage[20] = Extended
      end

      if @@classForExtendedMessage.nil?
        @@classForExtendedMessage = []
        @@classForExtendedMessage[Extension::MetadataExtensionId] = ExtendedMetaInfo
      end
      
      result = @@classForMessage[id]
      
      if result == Extended && payload
        # Extended messages have further subtypes.
        extendedMsgId = payload.unpack("C")[0]
        if extendedMsgId == 0
          result = ExtendedHandshake
        else
          # In this case the extended message number is the one we told our peers to use, not the one the peer told us.
          result = @@classForExtendedMessage[extendedMsgId]
          raise "Unsupported extended peer message id '#{extendedMsgId}'" if ! result 
        end

      end

      result
    end
Determine the class associated with the message type passed.