sdf_metadata/metadata/io/
consumer_config.rs1use crate::wit::io::ConsumerConfig;
2
3impl ConsumerConfig {
4 pub fn merge(&mut self, other: &ConsumerConfig) {
5 if self.default_starting_offset.is_none() {
6 self.default_starting_offset = other.default_starting_offset;
7 }
8 if self.max_bytes.is_none() {
9 self.max_bytes = other.max_bytes;
10 }
11
12 if self.isolation.is_none() {
13 self.isolation = other.isolation;
14 }
15 }
16}
17
18#[allow(clippy::derivable_impls)]
19impl Default for ConsumerConfig {
20 fn default() -> Self {
21 Self {
22 default_starting_offset: None,
23 max_bytes: None,
24 isolation: None,
25 }
26 }
27}
28
29#[cfg(test)]
30mod test {
31 use crate::wit::io::Offset;
32
33 #[test]
34 fn test_consumer_config_merge() {
35 let mut config1 = super::ConsumerConfig {
36 default_starting_offset: Some(Offset::Beginning(0)),
37 ..Default::default()
38 };
39
40 let config2 = super::ConsumerConfig {
41 default_starting_offset: Some(Offset::End(0)),
42 max_bytes: Some(1024),
43 isolation: Some(crate::wit::io::Isolation::ReadCommitted),
44 };
45
46 config1.merge(&config2);
47
48 assert_eq!(config1.default_starting_offset, Some(Offset::Beginning(0)));
49 assert_eq!(config1.max_bytes, Some(1024));
50 assert_eq!(
51 config1.isolation,
52 Some(crate::wit::io::Isolation::ReadCommitted)
53 );
54 }
55}