コード例 #1
0
    def from_bytes(cls, data):
        if not check_bytes_length(data, 5):
            return None

        offset = 1
        offset, piece_index = Network.read_integer(data, offset)

        return cls(piece_index)
コード例 #2
0
    def for_receive(cls, data):
        if not check_bytes_length(data, 16):
            return None

        offset = 0
        offset, action = read_integer(data, offset)
        offset, transaction_id = read_integer(data, offset)
        offset, connection_id = read_long(data, offset)

        return cls(connection_id, transaction_id, action)
コード例 #3
0
    def from_bytes(cls, data):
        if not check_bytes_length(data, 68):
            return None

        offset = 0
        offset, length = Network.read_byte_as_int(data, offset)
        offset, protocol = Network.read_bytes(data, 19, offset)
        offset, reserved = Network.read_bytes(data, 8, offset)
        offset, info_hash = Network.read_bytes(data, 20, offset)
        offset, peer_id = Network.read_bytes(data, 20, offset)

        result = cls(info_hash)
        result.length = length
        result.protocol = protocol
        result.reserved = reserved
        result.peer_id = peer_id

        return result
コード例 #4
0
    def from_bytes(cls, data):
        if not check_bytes_length(data, 1):
            return None

        return cls()
コード例 #5
0
    def from_bytes(cls, data):
        if not check_bytes_length(data, 3):
            return None

        offset, port = Network.read_ushort(data, 1)
        return cls(port)