Skip to content

Commit

Permalink
fix stream_parser: allow for message formats without timestamp
Browse files Browse the repository at this point in the history
E.g. nested formats are not required to contain a timestamp field.
Instead the check is moved to when the timestamp is trying to be accessed
(which indicates an invalid ULog file).
  • Loading branch information
bkueng committed Mar 26, 2024
1 parent b2887ab commit 765681c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
7 changes: 5 additions & 2 deletions src/stream_parser/file_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,11 @@ impl<'c> LogParser<'c> {
),
));
}
let current_timestamp =
flattened_format.timestamp_field.parse_timestamp(msg.data());
let timestamp_field = flattened_format.timestamp_field.as_ref().ok_or_else(|| UlogParseError::new(
ParseErrorType::Other,
&format!("Message does not have a timestamp field {}", flattened_format.message_name),
))?;
let current_timestamp = timestamp_field.parse_timestamp(msg.data());
if *last_timestamp < current_timestamp {
*last_timestamp = current_timestamp;
if let Some(cb) = &mut self.data_message_callback {
Expand Down
25 changes: 10 additions & 15 deletions src/stream_parser/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub struct FlattenedFormat {
pub message_name: String,
pub fields: Vec<FlattenedField>,
name_to_field: HashMap<String, FlattenedField>,
pub timestamp_field: TimestampField,
pub timestamp_field: Option<TimestampField>,
size: u16,
}

Expand All @@ -187,7 +187,7 @@ impl FlattenedFormat {
.iter()
.map(|f| (f.flattened_field_name.to_string(), (*f).clone()))
.collect();
match name_to_field
let timestamp_field = name_to_field
.get("timestamp")
.and_then(|field| match field.field_type {
FlattenedFieldType::UInt8 => Some(TimestampField {
Expand All @@ -207,19 +207,14 @@ impl FlattenedFormat {
offset: field.offset,
}),
_ => None,
}) {
Some(timestamp_field) => Ok(Self {
message_name,
fields,
name_to_field,
timestamp_field,
size,
}),
None => Err(UlogParseError::new(
ParseErrorType::Other,
&format!("Message does not have a timestamp field {}", message_name),
)),
}
});
Ok(Self {
message_name,
fields,
name_to_field,
timestamp_field,
size,
})
}

pub fn get_field_offset(
Expand Down

0 comments on commit 765681c

Please sign in to comment.