diff --git a/src/codec/macros.rs b/src/codec/macros.rs index 6e6aa8e6b..c280307f8 100644 --- a/src/codec/macros.rs +++ b/src/codec/macros.rs @@ -13,3 +13,25 @@ macro_rules! impl_stacks_message_codec_for_int { } }; } + +macro_rules! impl_byte_array_message_codec { + ($thing:ident, $len:expr) => { + impl ::codec::StacksMessageCodec for $thing { + fn consensus_serialize( + &self, + fd: &mut W, + ) -> Result<(), ::codec::Error> { + fd.write_all(self.as_bytes()) + .map_err(::codec::Error::WriteError) + } + fn consensus_deserialize( + fd: &mut R, + ) -> Result<$thing, ::codec::Error> { + let mut buf = [0u8; ($len as usize)]; + fd.read_exact(&mut buf).map_err(::codec::Error::ReadError)?; + let ret = $thing::from_bytes(&buf).expect("BUG: buffer is not the right size"); + Ok(ret) + } + } + }; +} diff --git a/src/net/mod.rs b/src/net/mod.rs index 8467c315c..d44ede099 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -1515,27 +1515,6 @@ pub const GETPOXINV_MAX_BITLEN: u64 = 8; // message. pub const BLOCKS_PUSHED_MAX: u32 = 32; -macro_rules! impl_byte_array_message_codec { - ($thing:ident, $len:expr) => { - impl ::codec::StacksMessageCodec for $thing { - fn consensus_serialize( - &self, - fd: &mut W, - ) -> Result<(), ::codec::Error> { - fd.write_all(self.as_bytes()) - .map_err(::codec::Error::WriteError) - } - fn consensus_deserialize( - fd: &mut R, - ) -> Result<$thing, ::codec::Error> { - let mut buf = [0u8; ($len as usize)]; - fd.read_exact(&mut buf).map_err(::codec::Error::ReadError)?; - let ret = $thing::from_bytes(&buf).expect("BUG: buffer is not the right size"); - Ok(ret) - } - } - }; -} impl_byte_array_message_codec!(ConsensusHash, 20); impl_byte_array_message_codec!(Hash160, 20); impl_byte_array_message_codec!(BurnchainHeaderHash, 32);