<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def encode_index_req(self, bucket, index, startkey, endkey=None, return_terms=None, max_results=None, continuation=None, timeout=None, term_regex=None, streaming=False):
 """ Encodes a secondary index request into the protobuf message. :param bucket: the bucket whose index to query :type bucket: string :param index: the index to query :type index: string :param startkey: the value or beginning of the range :type startkey: integer, string :param endkey: the end of the range :type endkey: integer, string :param return_terms: whether to return the index term with the key :type return_terms: bool :param max_results: the maximum number of results to return (page size) :type max_results: integer :param continuation: the opaque continuation returned from a previous paginated request :type continuation: string :param timeout: a timeout value in milliseconds, or 'infinity' :type timeout: int :param term_regex: a regular expression used to filter index terms :type term_regex: string :param streaming: encode as streaming request :type streaming: bool :rtype riak.pb.riak_kv_pb2.RpbIndexReq """

        req = riak.pb.riak_kv_pb2.RpbIndexReq(
            bucket=str_to_bytes(bucket.name),
            index=str_to_bytes(index))
        self._add_bucket_type(req, bucket.bucket_type)
        if endkey is not None:
            req.qtype = riak.pb.riak_kv_pb2.RpbIndexReq.range
            req.range_min = str_to_bytes(str(startkey))
            req.range_max = str_to_bytes(str(endkey))
        else:
            req.qtype = riak.pb.riak_kv_pb2.RpbIndexReq.eq
            req.key = str_to_bytes(str(startkey))
        if return_terms is not None:
            req.return_terms = return_terms
        if max_results:
            req.max_results = max_results
        if continuation:
            req.continuation = str_to_bytes(continuation)
        if timeout:
            if timeout == 'infinity':
                req.timeout = 0
            else:
                req.timeout = timeout
        if term_regex:
            req.term_regex = str_to_bytes(term_regex)
        req.stream = streaming
        mc = riak.pb.messages.MSG_CODE_INDEX_REQ
        rc = riak.pb.messages.MSG_CODE_INDEX_RESP
        return Msg(mc, req.SerializeToString(), rc)