-
Notifications
You must be signed in to change notification settings - Fork 5
Introduce functions to read the values in the fst file. #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -239,6 +239,41 @@ impl Reader { | |||||||||||||||
| _ => Err(Error::InvalidOperation), | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| /// Gets the value of the variable with the given handle at the specified time. | ||||||||||||||||
| /// | ||||||||||||||||
| /// If the variable is not found, returns `None`. | ||||||||||||||||
| /// If the value is not found, returns `None`. | ||||||||||||||||
| pub fn get_value_from_handle_at_time(&mut self, time: u64, handle: Handle) -> Option<String> { | ||||||||||||||||
| let mut buf = vec![0; 1024]; // Allocate a buffer for the value | ||||||||||||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The length of this buffer should be the length of the signal corresponding to the handle, rather than hardcoded, otherwise there is a risk of buffer overflow. I checked the fstapi code, it seems that the signal lengths are stored in an array in the memory pointed to by the reader context, but there is no such API to read them, and unfortunately the memory layout of the context is opaque. It would be better to add an API called |
||||||||||||||||
| let result = unsafe { | ||||||||||||||||
| capi::fstReaderGetValueFromHandleAtTime(self.ctx, time, handle.into(), buf.as_mut_ptr()) | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| let value_str = unsafe { std::ffi::CStr::from_ptr(result as *const raw::c_char).to_str().ok()? }; | ||||||||||||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||
| return Some(value_str.to_owned()); | ||||||||||||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use |
||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| /// Finds the next time at which a variable changes after a given time. | ||||||||||||||||
| pub fn get_next_time_change(&mut self, start_time: u64, handle: Handle) -> Result<u64> { | ||||||||||||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name of this method could be |
||||||||||||||||
| let mut time_table = Vec::new(); | ||||||||||||||||
| let mut time_table_len = 0; | ||||||||||||||||
| let mut last_time = 0; | ||||||||||||||||
|
|
||||||||||||||||
| self.for_each_block(|time, current_handle, _val, _| { | ||||||||||||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
| if time >= start_time && current_handle == handle { | ||||||||||||||||
| time_table.push(time); | ||||||||||||||||
| time_table_len += 1; | ||||||||||||||||
| } | ||||||||||||||||
|
Comment on lines
+263
to
+266
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both Try to define a variable
Suggested change
|
||||||||||||||||
| last_time = time; | ||||||||||||||||
| })?; | ||||||||||||||||
|
|
||||||||||||||||
| let next_time = if time_table_len > 0 { | ||||||||||||||||
| time_table[0] | ||||||||||||||||
| } else { | ||||||||||||||||
| last_time | ||||||||||||||||
| }; | ||||||||||||||||
| Ok(next_time) | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| impl Drop for Reader { | ||||||||||||||||
|
|
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method could have been named something simpler, like
value_at_time.