-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implemented monitor adapter interface
- Loading branch information
1 parent
44515f0
commit a43cc5e
Showing
5 changed files
with
81 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use std::{ | ||
fs, | ||
io::{self, BufRead}, | ||
path::Path, | ||
pin::Pin, | ||
}; | ||
|
||
use futures::stream; | ||
|
||
use super::{Event, MonitorAdapter}; | ||
|
||
pub struct FileMonitorAdapter { | ||
values: Vec<String>, | ||
} | ||
impl FileMonitorAdapter { | ||
pub fn new(file_path: &Path) -> anyhow::Result<Self> { | ||
let file = fs::File::open(file_path)?; | ||
let reader = io::BufReader::new(file); | ||
let values = reader.lines().collect::<io::Result<Vec<String>>>()?; | ||
|
||
Ok(Self { values }) | ||
} | ||
} | ||
impl MonitorAdapter for FileMonitorAdapter { | ||
fn stream(&mut self) -> Pin<Box<dyn futures::Stream<Item = anyhow::Result<Event>>>> { | ||
let stream = stream::iter(self.values.clone().into_iter().map(|v| { | ||
let bytes = hex::decode(&v)?; | ||
Ok(Event::RollForward(bytes)) | ||
})); | ||
|
||
Box::pin(stream) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.