-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlib.rs
More file actions
48 lines (40 loc) · 1.36 KB
/
Copy pathlib.rs
File metadata and controls
48 lines (40 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! Binary serialisation and deserialisation helpers for Cardano components.
//!
//! The API mirrors the spirit of the original Haskell `cardano-binary`
//! package, offering high-level helpers to serialise values to CBOR, decode
//! complete payloads, and work with nested CBOR-in-CBOR structures.
#![cfg_attr(test, allow(clippy::unwrap_used))]
#![cfg_attr(test, allow(clippy::approx_constant))]
mod deserialize;
mod error;
mod serialize;
#[allow(deprecated)]
pub use crate::deserialize::{
decode_full, decode_full_owned, decode_nested_cbor, decode_nested_cbor_bytes,
unsafe_deserialize, unsafe_deserialize_owned,
};
pub use crate::error::BinaryError;
pub use crate::serialize::{
encode_nested_cbor, encode_nested_cbor_bytes, serialize, serialize_into_vec,
serialize_into_writer, serialize_strict, serialize_with_capacity,
};
#[cfg(test)]
mod roundtrip_tests {
use super::*;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
struct Sample {
id: u64,
payload: String,
}
#[test]
fn roundtrip_helpers_work() {
let sample = Sample {
id: 7,
payload: "hello".into(),
};
let bytes = serialize(&sample).expect("serialize");
let decoded = decode_full::<Sample>(&bytes).expect("decode");
assert_eq!(sample, decoded);
}
}