Skip to main content

arc_malachitebft_peer/ser/
borsh.rs

1use {crate::PeerId, alloc::vec::Vec};
2
3impl borsh::BorshSerialize for PeerId {
4    fn serialize<W: borsh::io::Write>(&self, writer: &mut W) -> borsh::io::Result<()> {
5        self.multihash.to_bytes().serialize(writer)
6    }
7}
8
9impl borsh::BorshDeserialize for PeerId {
10    fn deserialize_reader<R: borsh::io::Read>(reader: &mut R) -> borsh::io::Result<Self> {
11        let bytes = Vec::<u8>::deserialize_reader(reader)?;
12        PeerId::from_bytes(&bytes)
13            .map_err(|e| borsh::io::Error::new(borsh::io::ErrorKind::InvalidData, e))
14    }
15}