refactor: improve buffer handling logic and comments
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -58,18 +58,23 @@ impl MetaPlugin for BinaryMetaPlugin {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add data to buffer
|
||||
// Calculate how much data we can still accept
|
||||
let remaining_capacity = self.max_buffer_size.saturating_sub(self.buffer.len());
|
||||
if remaining_capacity > 0 {
|
||||
let bytes_to_copy = std::cmp::min(data.len(), remaining_capacity);
|
||||
self.buffer.extend_from_slice(&data[..bytes_to_copy]);
|
||||
if remaining_capacity == 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
// If we've reached the buffer limit, save the metadata immediately
|
||||
// Determine how much data to copy
|
||||
let bytes_to_take = std::cmp::min(data.len(), remaining_capacity);
|
||||
|
||||
// Add data to our buffer
|
||||
self.buffer.extend_from_slice(&data[..bytes_to_take]);
|
||||
|
||||
// If we've reached our buffer limit, save the metadata immediately
|
||||
if self.buffer.len() >= self.max_buffer_size {
|
||||
let _ = self.save_metadata(conn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn meta_name(&mut self) -> String {
|
||||
self.meta_name.clone()
|
||||
|
||||
Reference in New Issue
Block a user