feat: add convenience methods to filter service and improve filter chain processing
Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
@@ -31,4 +31,29 @@ impl FilterService {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
}
|
||||
|
||||
// Add a method to process data through the filter chain and handle finish automatically
|
||||
pub fn process_all_data(&self, chain: &mut Option<FilterChain>, data: &[u8]) -> Result<Vec<u8>> {
|
||||
let mut processed = if let Some(chain) = chain {
|
||||
chain.process(data)?
|
||||
} else {
|
||||
data.to_vec()
|
||||
};
|
||||
|
||||
// If we have a chain, also get any remaining data from finish()
|
||||
if chain.is_some() {
|
||||
let finished = self.finish_processing(chain)?;
|
||||
if !finished.is_empty() {
|
||||
processed.extend(finished);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(processed)
|
||||
}
|
||||
|
||||
// Helper method to create and process data with a filter string in one call
|
||||
pub fn process_with_filter(&self, data: &[u8], filter_str: Option<&str>) -> Result<Vec<u8>> {
|
||||
let mut chain = self.create_filter_chain(filter_str)?;
|
||||
self.process_all_data(&mut chain, data)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user