1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use kf_protocol_api::PartitionOffset;

use crate::offset::KfListOffsetResponse;
use crate::offset::ListOffsetPartitionResponse;

impl KfListOffsetResponse {

    pub fn find_partition(self,topic: &str,partition: i32) -> Option<ListOffsetPartitionResponse> {

        for topic_res in self.topics {
            if topic_res.name == topic {
                for partition_res in topic_res.partitions {
                    if partition_res.partition_index == partition {
                        return Some(partition_res);
                    }
                }
            }
        }

        None

    }

}

impl PartitionOffset for ListOffsetPartitionResponse {

    fn last_stable_offset(&self) -> i64 {
        self.offset
    }


    // we don't have start offset yet for kafka
    fn start_offset(&self) -> i64 {
        self.offset
    }
}