Skip to content

Commit

Permalink
Add new API for extracting the underling CBOR value from a CBORValida…
Browse files Browse the repository at this point in the history
…tor for reuse.
  • Loading branch information
pythonspeed committed Jan 24, 2024
1 parent 83ce7e3 commit 60ceb32
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/validator/cbor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,11 @@ impl<'a> CBORValidator<'a> {
}
}

/// Extract the underlying CBOR Value.
pub fn extract_cbor(self) -> Value {
self.cbor
}

fn validate_array_items<T: std::fmt::Debug + 'static>(
&mut self,
token: &ArrayItemToken,
Expand Down Expand Up @@ -3903,4 +3908,14 @@ mod tests {

Ok(())
}

#[test]
fn extract_cbor() {
use ciborium::value::Value;

let cbor = Value::Float(1.23);
let cddl = cddl_from_str("start = any", true).unwrap();
let cv = CBORValidator::new(&cddl, cbor, None);
assert_eq!(cv.extract_cbor(), Value::Float(1.23));
}
}

0 comments on commit 60ceb32

Please sign in to comment.