Function postcard::to_slice_crc32
source · pub fn to_slice_crc32<'a, 'b, T>(
value: &'b T,
buf: &'a mut [u8],
digest: Digest<'a, u32>
) -> Result<&'a mut [u8]>where
T: Serialize + ?Sized,
Expand description
Conveniently serialize a T
to the given slice, with the resulting slice containing
data followed by a 32-bit CRC. The CRC bytes are included in the output buffer.
When successful, this function returns the slice containing the serialized and encoded message.
Example
use crc::{Crc, CRC_32_ISCSI};
let mut buf = [0; 9];
let data: &[u8] = &[0x01, 0x00, 0x20, 0x30];
let crc = Crc::<u32>::new(&CRC_32_ISCSI);
let used = postcard::to_slice_crc32(data, &mut buf, crc.digest()).unwrap();
assert_eq!(used, &[0x04, 0x01, 0x00, 0x20, 0x30, 0x8E, 0xC8, 0x1A, 0x37]);
See the ser_flavors::crc
module for the complete set of functions.