|
48 | 48 | //! |
49 | 49 | //! let data = SecretData([42; 32]); |
50 | 50 | //! |
51 | | -//! let serialized = bincode::serialize(&data).unwrap(); |
52 | | -//! // bincode, a binary serialization format is serialized into bytes. |
53 | | -//! assert_eq!( |
54 | | -//! serialized.as_slice(), |
55 | | -//! [ |
56 | | -//! // Array size. |
57 | | -//! 32, 0, 0, 0, 0, 0, 0, 0, |
58 | | -//! // Actual data. |
59 | | -//! 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, |
60 | | -//! 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, |
61 | | -//! ] |
62 | | -//! ); |
63 | | -//! # let deserialized: SecretData = bincode::deserialize(&serialized).unwrap(); |
64 | | -//! # assert_eq!(deserialized, data); |
| 51 | +//! // postcard: an embedded-friendly binary serialization format |
| 52 | +//! let serialized = postcard::to_stdvec(&data).unwrap(); |
| 53 | +//! let deserialized: SecretData = postcard::from_bytes(&serialized).unwrap(); |
| 54 | +//! assert_eq!(deserialized, data); |
65 | 55 | //! |
66 | 56 | //! let serialized = serde_json::to_string(&data).unwrap(); |
67 | 57 | //! // JSON, a human-readable serialization format, is serialized into lower-case HEX. |
|
102 | 92 | //! |
103 | 93 | //! let data = SecretData(vec![42; 32]); |
104 | 94 | //! |
105 | | -//! let serialized = bincode::serialize(&data).unwrap(); |
106 | | -//! // bincode, a binary serialization format is serialized into bytes. |
107 | | -//! assert_eq!( |
108 | | -//! serialized.as_slice(), |
109 | | -//! [ |
110 | | -//! // Slice size. |
111 | | -//! 32, 0, 0, 0, 0, 0, 0, 0, |
112 | | -//! // Actual data. |
113 | | -//! 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, |
114 | | -//! 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, |
115 | | -//! ] |
116 | | -//! ); |
117 | | -//! # let deserialized: SecretData = bincode::deserialize(&serialized).unwrap(); |
118 | | -//! # assert_eq!(deserialized, data); |
| 95 | +//! // postcard: an embedded-friendly binary serialization format |
| 96 | +//! let serialized = postcard::to_stdvec(&data).unwrap(); |
| 97 | +//! let deserialized: SecretData = postcard::from_bytes(&serialized).unwrap(); |
| 98 | +//! assert_eq!(deserialized, data); |
119 | 99 | //! |
120 | 100 | //! let serialized = serde_json::to_string(&data).unwrap(); |
121 | 101 | //! // JSON, a human-readable serialization format is serialized into lower-case HEX. |
|
0 commit comments