Skip to content
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

Unit variant errors in the hot loop #36

Merged
merged 7 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frost/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "frost"
version = "0.4.0"
version = "0.4.1"
edition = "2021"
rust-version = "1.65"
build = "build.rs"
Expand Down
11 changes: 6 additions & 5 deletions frost/benches/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ const COMPRESSED_LZ4: &[u8] = include_bytes!("../tests/fixtures/compressed_lz4.b
#[cfg(test)]
mod tests {
use super::*;
use frost::{query::Query, BagMetadata};
use frost::{query::Query, DecompressedBag};
use test::Bencher;

#[bench]
fn bench_from_bytes(b: &mut Bencher) {
b.iter(|| {
for _i in 0..1000 {
let mut _bag = hint::black_box(BagMetadata::from_bytes(COMPRESSED_LZ4).unwrap());
let mut _bag =
hint::black_box(DecompressedBag::from_bytes(COMPRESSED_LZ4).unwrap());
}
});
}
Expand All @@ -30,14 +31,14 @@ mod tests {
fn bench_from_file(b: &mut Bencher) {
b.iter(|| {
for _i in 0..1000 {
let mut _bag = hint::black_box(BagMetadata::from_file(BAG_PATH).unwrap());
let mut _bag = hint::black_box(DecompressedBag::from_file(BAG_PATH).unwrap());
}
});
}

#[bench]
fn bench_iterate_from_bytes(b: &mut Bencher) {
let bag = BagMetadata::from_bytes(COMPRESSED_LZ4).unwrap();
let bag = DecompressedBag::from_bytes(COMPRESSED_LZ4).unwrap();
let query = Query::all();

b.iter(|| {
Expand All @@ -51,7 +52,7 @@ mod tests {

#[bench]
fn bench_iterate_from_file(b: &mut Bencher) {
let bag = BagMetadata::from_file(BAG_PATH).unwrap();
let bag = DecompressedBag::from_file(BAG_PATH).unwrap();
let query = Query::all();

b.iter(|| {
Expand Down
38 changes: 33 additions & 5 deletions frost/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::borrow::Cow;
use std::error;
use std::fmt;
use std::io;
Expand All @@ -19,11 +18,10 @@ impl Error {
#[derive(Debug)]
pub enum ErrorKind {
NotARosbag,
UnindexedBag,
InvalidBag(Cow<'static, str>),
Deserialization(serde_rosmsg::Error),
Decompression(lz4_flex::block::DecompressError),
Io(io::Error),
Parse(ParseError),
}

impl fmt::Display for Error {
Expand All @@ -33,10 +31,9 @@ impl fmt::Display for Error {
write!(f, "invalid rosbag v2 header")
}
ErrorKind::Io(ref e) => e.fmt(f),
ErrorKind::UnindexedBag => write!(f, "unindexed bag"),
ErrorKind::InvalidBag(ref cow) => write!(f, "invalid bag: {cow}"),
ErrorKind::Deserialization(ref e) => e.fmt(f),
ErrorKind::Decompression(ref e) => e.fmt(f),
ErrorKind::Parse(ref e) => e.fmt(f),
}
}
}
Expand Down Expand Up @@ -66,3 +63,34 @@ impl From<lz4_flex::block::DecompressError> for Error {
}
}
}

impl From<ParseError> for Error {
fn from(e: ParseError) -> Error {
Error {
kind: ErrorKind::Parse(e),
}
}
}

#[derive(Debug)]
pub enum ParseError {
MissingRecord,
MissingFieldSeparator,
MissingHeaderOp,
InvalidOpCode,
BufferTooSmall,
UnexpectedEOF,
UnexpectedField,
UnexpectedOpCode,
MissingField,
InvalidBag,
UnindexedBag,
}

impl std::fmt::Display for ParseError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Error: {:?}", self)
}
}

impl std::error::Error for ParseError {}
Loading
Loading