Beispiel #1
0
def create_seek_info(start=None, stop=None, behavior="BLOCK_UNTIL_READY"):

    # build start
    if start is not None:
        seek_specified_start = ab_pb2.SeekSpecified()
        seek_specified_start.number = start
        seek_start = ab_pb2.SeekPosition()
        seek_start.specified.CopyFrom(seek_specified_start)
    else:
        seek_start = ab_pb2.SeekPosition()
        seek_start.newest.CopyFrom(ab_pb2.SeekNewest())

    # build stop
    if stop is not None:
        seek_specified_stop = ab_pb2.SeekSpecified()
        seek_specified_stop.number = stop
        seek_stop = ab_pb2.SeekPosition()
        seek_stop.specified.CopyFrom(seek_specified_stop)
    else:
        seek_stop = ab_pb2.SeekPosition()
        seek_stop.newest.CopyFrom(ab_pb2.SeekNewest())

    # seek info with all parts
    seek_info = ab_pb2.SeekInfo()
    seek_info.start.CopyFrom(seek_start)
    seek_info.stop.CopyFrom(seek_stop)

    seek_info.behavior = ab_pb2.SeekInfo.SeekBehavior.Value(behavior)

    return seek_info
Beispiel #2
0
    def _create_seek_info(self, start=None, stop=None):

        behavior = 'BLOCK_UNTIL_READY'

        # build start
        seek_start = ab_pb2.SeekPosition()
        if start is None or start == 'newest':
            seek_start.newest.CopyFrom(ab_pb2.SeekNewest())
        elif start == 'oldest':
            seek_start.oldest.CopyFrom(ab_pb2.SeekOldest())
        else:
            seek_specified_start = ab_pb2.SeekSpecified()
            seek_specified_start.number = start
            seek_start.specified.CopyFrom(seek_specified_start)

        # build stop
        seek_stop = ab_pb2.SeekPosition()
        if stop == 'newest':
            self._ending_block_newest = True
            seek_stop.newest.CopyFrom(ab_pb2.SeekNewest())
            behavior = 'FAIL_IF_NOT_READY'
        elif start == 'oldest':
            seek_stop.oldest.CopyFrom(ab_pb2.SeekOldest())
            behavior = 'FAIL_IF_NOT_READY'
        else:
            seek_specified_stop = ab_pb2.SeekSpecified()
            if stop is not None:
                seek_specified_stop.number = stop
                behavior = 'FAIL_IF_NOT_READY'
            else:
                seek_specified_stop.number = sys.maxsize
            seek_stop.specified.CopyFrom(seek_specified_stop)

        # seek info with all parts
        seek_info = ab_pb2.SeekInfo()
        seek_info.start.CopyFrom(seek_start)
        seek_info.stop.CopyFrom(seek_stop)

        # BLOCK_UNTIL_READY will mean hold the stream open and keep sending
        # as the blocks come in
        # FAIL_IF_NOT_READY will mean if the block is not there throw an error
        seek_info.behavior = ab_pb2.SeekInfo.SeekBehavior.Value(behavior)

        return seek_info
Beispiel #3
0
def create_seek_info(start, stop, behavior="BLOCK_UNTIL_READY"):

    # build start
    seek_specified_start = ab_pb2.SeekSpecified()
    seek_specified_start.number = start
    seek_start = ab_pb2.SeekPosition()
    seek_start.specified.CopyFrom(seek_specified_start)

    # build stop
    seek_specified_stop = ab_pb2.SeekSpecified()
    seek_specified_stop.number = stop
    seek_stop = ab_pb2.SeekPosition()
    seek_stop.specified.CopyFrom(seek_specified_stop)

    # seek info with all parts
    seek_info = ab_pb2.SeekInfo()
    seek_info.start.CopyFrom(seek_start)
    seek_info.stop.CopyFrom(seek_stop)
    seek_info.behavior = \
            ab_pb2.SeekInfo.SeekBehavior.Value(behavior)

    return seek_info