def generateCancel(index, begin, length): return _createMessageLength(13)+shortIntToBinary(8)+\ longIntToBinary(index)+\ longIntToBinary(begin)+\ longIntToBinary(length)
def generatePiece(index, begin, block): return _createMessageLength(9+len(block))+shortIntToBinary(7)+\ longIntToBinary(index)+\ longIntToBinary(begin)+\ block
def generateHave(pieceIndex): return _createMessageLength(5)+shortIntToBinary(4)+longIntToBinary(pieceIndex)
def generateRequest(index, begin, length): return _createMessageLength(13)+shortIntToBinary(6)+\ longIntToBinary(index)+\ longIntToBinary(begin)+\ longIntToBinary(length)
def _createMessageLength(length): return longIntToBinary(length)