Skip to content

Commit

Permalink
Adds base bench
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicceboy committed Dec 1, 2024
1 parent af9a369 commit 1badcfa
Show file tree
Hide file tree
Showing 11 changed files with 1,905 additions and 1,692 deletions.
125 changes: 125 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ path = "benches/strings.rs"
harness = false
test = true

[[bench]]
name = "ieee1609dot2cert"
path = "benches/ieee1609dot2_bsm_cert.rs"
harness = false
test = true

[dependencies]
bitvec.workspace = true
bytes = { version = "1.7.2", default-features = false }
Expand Down Expand Up @@ -99,6 +105,7 @@ iai-callgrind = "0.14.0"
once_cell = "1.20.2"
pretty_assertions.workspace = true
rasn-pkix = { path = "standards/pkix" }
rasn-ieee1609dot2 = { path = "standards/ieee1609dot2" }

# Assume that we need these dependencies only when benching manually on specific targets
[target.'cfg(any(target_arch = "x86_64", target_arch = "aarch64"))'.dev-dependencies]
Expand Down
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! Backtraces are enabled by default with `backtraces` feature.
//! See submodules for other error types.
#![allow(clippy::module_name_repetitions)]
mod components;
mod decode;
mod encode;
mod string;
Expand All @@ -25,3 +26,5 @@ pub use decode::{
pub use encode::EncodeErrorKind;
pub use encode::JerEncodeErrorKind;
pub use encode::{BerEncodeErrorKind, CodecEncodeError, CoerEncodeErrorKind, EncodeError};

pub use components::InnerSubtypeConstraintError;
18 changes: 18 additions & 0 deletions src/error/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,18 @@ impl DecodeError {
codec,
)
}
/// Creates a wrapper around a inner subtype constraint error from a given codec.
/// This is mainly used by standards.
#[must_use]
pub fn inner_subtype_constraint_not_satisfied(
reason: super::InnerSubtypeConstraintError,
codec: Codec,
) -> Self {
Self::from_kind(
DecodeErrorKind::InnerSubtypeConstraintNotSatisfied { reason },
codec,
)
}

/// Creates a wrapper around a discriminant value error from a given codec.
#[must_use]
Expand Down Expand Up @@ -434,6 +446,12 @@ pub enum DecodeErrorKind {
/// Expected value by the constraint
expected: Bounded<i128>,
},
/// Inner subtype constraint not satisfied.
#[snafu(display("Inner subtype constraint not satisfied: {reason}"))]
InnerSubtypeConstraintNotSatisfied {
/// The reason the constraint wasn't satisfied.
reason: super::InnerSubtypeConstraintError,
},

/// Codec specific error.
#[snafu(display("Wrapped codec-specific decode error"))]
Expand Down
2 changes: 1 addition & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use alloc::boxed::Box;
pub use {
self::{
any::Any,
constraints::{Constraint, Constraints, Extensible},
constraints::{Constraint, Constraints, Extensible, InnerSubtypeConstraint},
constructed::{Constructed, SequenceOf, SetOf},
instance::InstanceOf,
integer::{ConstrainedInteger, Integer, IntegerType},
Expand Down
6 changes: 6 additions & 0 deletions src/types/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
use super::IntegerType;
use num_bigint::BigInt;

/// A marker trait for types that have inner subtype constraints.
pub trait InnerSubtypeConstraint: Sized {
/// Validates the inner subtype constraints and returns the type on success.
fn validated(self) -> Result<Self, crate::error::InnerSubtypeConstraintError>;
}

/// A set of constraints for a given type on what kinds of values are allowed.
/// Used in certain codecs to optimise encoding and decoding values.
///
Expand Down
15 changes: 10 additions & 5 deletions standards/ieee1609dot2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ description = "ASN.1 definitions for IEEE Standard for Wireless Access in Vehicu
license.workspace = true
repository.workspace = true

# [[bench]]
# name = "cert"
# path = "benches/bsm_cert.rs"
# harness = false
# test = true

[dependencies]
bon = { version = "3.1.1", default-features = false }
rasn = { version = "0.22", path = "../.." }
rasn-etsi-ts103097-extensions = { version = "0.22", path = "../ts103097extensions" }


# [dependencies.ts103097]
# version = "0.22"
# path = "../ts103097"

[dev-dependencies]
pretty_assertions = "1.4.1"
# criterion = { version = "0.5.1", default-features = false, features = [
# "plotters",
# "cargo_bench_support",
# ] }
Loading

0 comments on commit 1badcfa

Please sign in to comment.